import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import javax.swing.*;
import javax.swing.filechooser.FileFilter;
public class Startdialog extends JFrame implements ActionListener
{
String nameSpieler1;
String nameSpieler2;
String nameSpieler3;
int spieleranzahl;
String farbeSpieler1;
String farbeSpieler2;
String farbeSpieler3;
/**
* Konstruktor der Klasse.
*
*/
public Startdialog() {
JFrame startfenster = new JFrame ("Startdialog");
Container contentPane = startfenster.getContentPane ();
contentPane.setBackground(Color.yellow);
JLabel label1 = new JLabel (" Spieler1", JLabel.CENTER);
JLabel label2 = new JLabel (" Spieler2", JLabel.CENTER);
JLabel label3 = new JLabel (" Spieler3", JLabel.CENTER);
JLabel label4 = new JLabel (" HALMA", JLabel.CENTER);
label4.setForeground (Color.magenta);
Font f = new Font ("SansSerif",Font.BOLD, 34);
label4.setFont(f);
JTextField feld1 = new JTextField (10);
JTextField feld2 = new JTextField (10);
JTextField feld3 = new JTextField (10);
String[] farben = {"rot","grün","blau"};
JComboBox box2 = new JComboBox(farben);
JComboBox box3 = new JComboBox(farben);
//Choice Listen erstelllen
Panel panelC_1 = new Panel ();
panelC_1.setLayout(new FlowLayout());
Choice choice = new Choice();
choice.add("rot");
choice.add("grün");
choice.add("blau");
panelC_1.add(choice);
Panel panelC_2 = new Panel ();
panelC_2.setLayout(new FlowLayout());
Choice choice2 = new Choice();
choice2.add("rot");
choice2.add("grün");
choice2.add("blau");
panelC_2.add(choice2);
Panel panelC_3 = new Panel ();
panelC_3.setLayout(new FlowLayout());
Choice choice3 = new Choice();
choice3.add("rot");
choice3.add("grün");
choice3.add("blau");
panelC_3.add(choice3);
JButton buttonA = new JButton ("Spielanleitung");
buttonA.setBackground(Color.green);
buttonA.addActionListener(this);
JButton buttonL = new JButton ("Spiel laden");
buttonL.setBackground(Color.orange);
buttonL.addActionListener(this);
JButton buttonN = new JButton ("Neues Spiel");
buttonN.setBackground(Color.red);
//hier ist zu Testzwecken die Hoerer Klasse verändert
buttonN.addActionListener(this);
JButton buttonU1 = new JButton ();
JButton buttonU2 = new JButton ();
//erstes Panel
Panel panelSt_1 = new Panel ();
panelSt_1.setLayout (new FlowLayout (FlowLayout.CENTER, 20,20));
panelSt_1.add (label4);
// Mittlerer Bereich
Panel panelSt_2 = new Panel ();
panelSt_2.setLayout (new FlowLayout(FlowLayout.LEFT,65,20));
panelSt_2.add(label1);
panelSt_2.add(feld1);
panelSt_2.add(panelC_1);
Panel panelSt_3 = new Panel ();
panelSt_3.setLayout (new FlowLayout(FlowLayout.LEFT,65,20));
panelSt_3.add(label2);
panelSt_3.add(feld2);
panelSt_3.add(panelC_2);
Panel panelSt_4 = new Panel ();
panelSt_4.setLayout (new FlowLayout(FlowLayout.LEFT,65,20));
panelSt_4.add(label3);
panelSt_4.add(feld3);
panelSt_4.add(panelC_3);
// Unteres Panel
Panel panelSt_5 = new Panel ();
panelSt_5.setLayout (new FlowLayout (FlowLayout.CENTER,30,20));
panelSt_5.add(buttonA);
panelSt_5.add(buttonL);
panelSt_5.add(buttonN);
//Komplettes Layout
contentPane.setLayout (new GridLayout (5,1));
contentPane.add(panelSt_1);
contentPane.add(panelSt_2);
contentPane.add(panelSt_3);
contentPane.add(panelSt_4);
contentPane.add(panelSt_5);
startfenster.setSize (500,490);
startfenster.setVisible(true);
}
public void actionPerformed(ActionEvent e){
if (e.getActionCommand() == "Spielanleitung") {
Anleitung anleitung = new Anleitung ();
}
if (e.getActionCommand() == "Spiel laden") {
JFileChooser chooser = new JFileChooser();
chooser.addChoosableFileFilter(new FileFilter()
{
public boolean accept(File f)
{if (f.isDirectory()) return true;
return f.getName().toLowerCase().endsWith(".gif");
}
public String getDescription () { return "GIFs"; }
});
chooser.setMultiSelectionEnabled(false);
if (chooser.showOpenDialog(chooser) ==
JFileChooser.APPROVE_OPTION)
System.out.println ("Datei "+chooser.getSelectedFile()+
" ausgewählt.");
}
if (e.getActionCommand() == "Neues Spiel") {
Spielfenster game = new Spielfenster();
game.spielfenster ();
// hierbei sollte sich das fenster dann auch unsichtbar machen
}
}
}