public class Mein extends JFrame {
JRadioButton opt3 ;
JRadioButton opt4;
JRadioButton opt5;
JLabel text1;
JLabel text2;
class richtig implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
int i;
text1.setText("2.Frage:");
text2.setText("Wer war ...");
opt3.setText("hallo");
opt4.setText("nochmal");
}
}
class falsch implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
int i;
text1.setText("Das war leider falsch");
text2.setText("");
opt3.removeAll();
opt4.removeAll();
}
}
public static void main(String[] args) {
Mein auswahl =
new Mein("Mehr Auswahl mit Swing!");
auswahl.pack();
auswahl.setSize(640,400);
auswahl.show();
}
Mein(String titel)
{
super(titel);
JPanel pane = new JPanel();
pane.setLayout(new GridLayout(3, 4, 3, 3));
setContentPane(pane);
JPanel zelle1 = new JPanel();
JPanel zelle2 = new JPanel();
JPanel zelle3 = new JPanel();
JPanel zelle4 = new JPanel();
JPanel zelle5 = new JPanel();
JPanel zelle6 = new JPanel();
JPanel zelle7 = new JPanel();
JPanel zelle8 = new JPanel();
JPanel zelle9 = new JPanel();
JPanel zelle10 = new JPanel();
JPanel zelle11 = new JPanel();
JPanel zelle12 = new JPanel();
text1 = new JLabel("Frage 1:", SwingConstants.LEFT);
text1.setFont(new Font("Monospaced", Font.BOLD,12));
zelle1.add(text1);
text2 = new JLabel("Wer war Heino?", SwingConstants.LEFT);
text2.setFont(new Font("Monospaced", Font.BOLD,12));
zelle5.add(text2);
ButtonGroup gruppe = new ButtonGroup();
opt3 = new JRadioButton ("Sänger",false);
opt4 = new JRadioButton ("Spinner",false);
gruppe.add(opt3);
gruppe.add(opt4);
zelle6.add(opt3);
zelle7.add(opt4);
pane.add(zelle1);
pane.add(zelle2);
pane.add(zelle3);
pane.add(zelle4);
pane.add(zelle5);
pane.add(zelle6);
pane.add(zelle7);
pane.add(zelle8);
pane.add(zelle9);
pane.add(zelle10);
pane.add(zelle11);
pane.add(zelle12);
opt3.addActionListener( new richtig()
);
opt4.addActionListener( new falsch()
);
class CFensterLauscher extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
};
addWindowListener(new CFensterLauscher());
}
}