...
public class GUITiere {
JButton affe;
JButton loewe;
JButton baer;
JButton hase;
JLabel label;
public static void main (String[]args){
GUITiere gui = new GUITiere();
gui.los();
}
public void los(){JFrame frame = new JFrame("GUI Tiere");
affe = new JButton("Affe");
...
JPanel panel1 = new JPanel();
label = new JLabel("Bitte klicken Sie auf ein Tier");
panel1.setLayout(new BoxLayout(panel1,BoxLayout.Y_AXIS));
panel1.add(affe);
...
panel1.add(label);
affe.addActionListener(new affeListener());
...
frame.setContentPane(panel1);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
class affeListener implements ActionListener{
public void actionPerformed(ActionEvent event) {label.setText("Ich bin ein Affe");}
}
...
}}