Java GUIs

Aus ProgrammingWiki
Archivierte Version vom 2011-01-10T18:50:59+00:00. Aktuelle Version

<run></run>

 JButton myButton = new JButton("Button");
 JCheckBox myCheckBox = new JCheckBox("Check");
 JTextArea myText = new JTextArea("My text");
 JPanel bottomPanel = new JPanel();
 JPanel holdAll = new JPanel();
 frame = new JFrame( "My Frame" );
 frame.setLocation(200, 200);
 frame.setSize(300, 300);
 bottomPanel.setLayout(new FlowLayout());
 bottomPanel.add(myCheckBox);
 bottomPanel.add(myButton);
   
 holdAll.setLayout(new BorderLayout());
 holdAll.add(bottomPanel, BorderLayout.SOUTH);
 holdAll.add(myText, BorderLayout.CENTER);
   
 frame.getContentPane().add(holdAll, BorderLayout.CENTER);
 frame.setVisible(true);
   
 myButton.addActionListener(this);
 myCheckBox.addActionListener(this);
   
 void actionPerformed(ActionEvent e)
 {
   if (e.getSource() == myButton)
     myText.setText("A button click");
   else if (e.getSource() == myCheckBox)
     myText.setText("The checkbox state changed to " + 
                    myCheckBox.isSelected());
   else
     myText.setText("E ...?");
 }