Java GUIs
Aus ProgrammingWiki
Archivierte Version vom 2008-12-18T14:15:08+00:00. Aktuelle Version
<eval></eval>
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.setVisible(true); 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); myButton.addActionListener(this); myCheckBox.addActionListener(this); frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
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 ...?");
}