Versionsvergleich
Aus ProgrammingWiki
Vergleich: 2011-01-19T12:54:11+00:00 → 2011-01-19T12:55:07+00:00
| + | <language>Java</language> |
| + | <run id="4d36df2ae7e67"> |
| + | 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 ...?"); |
| + | } |
| + | |
| + | </run> |