Versionsvergleich
Aus ProgrammingWiki
Vergleich: 2008-12-18T14:06:55+00:00 → 2011-01-10T19:11:43+00:00
<language>Java</language> | |
| − | <eval> |
| − | TextField txtResults = new TextField(); |
| − | Checkbox checkBox1 = new Checkbox(); |
| − | Checkbox checkBox2 = new Checkbox(); |
| − | List listOptions = new List(); |
| − | Label lblEventChecker = new Label(); |
| − | Button btnOK = new Button(); |
| − | Button btnCancel = new Button(); |
| − | Label label1 = new Label(); |
| − | Label label2 = new Label(); |
| + | <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(); |
| − | |
| − | lblEventChecker.setBounds(new Rectangle(21, 13, 118, 25)); |
| − | lblEventChecker.setText("Event Checker:"); |
| − | btnOK.setBounds(new Rectangle(81, 219, 100, 40)); |
| − | btnOK.setLabel("OK"); |
| − | btnOK.addActionListener(new java.awt.event.ActionListener() { |
| − | public void actionPerformed(ActionEvent e) { |
| − | btnOK_actionPerformed(e); |
| − | } |
| − | }); |
| − | btnCancel.setBounds(new Rectangle(224, 217, 100, 41)); |
| − | btnCancel.setLabel("Cancel"); |
| − | label1.setBounds(new Rectangle(21, 56, 117, 23)); |
| − | label1.setText("Select a checkbox:"); |
| − | label2.setBounds(new Rectangle(153, 56, 219, 19)); |
| − | label2.setText("Double-click a list item:"); |
| − | btnCancel.addActionListener(new java.awt.event.ActionListener() { |
| − | public void actionPerformed(ActionEvent e) { |
| − | btnCancel_actionPerformed(e); |
| − | } |
| − | }); |
| − | this.setLayout(null); |
| − | this.setBackground(Color.lightGray); |
| − | this.setSize(new Dimension(400, 275)); |
| − | txtResults.setBounds(new Rectangle(154, 12, 219, 23)); |
| − | checkBox1.setBounds(new Rectangle(21, 84, 124, 23)); |
| − | checkBox1.setLabel("Option Number 1"); |
| − | checkBox1.addItemListener(new java.awt.event.ItemListener() { |
| − | public void itemStateChanged(ItemEvent e) { |
| − | checkBox1_itemStateChanged(e); |
| − | } |
| − | }); |
| − | checkBox2.setBounds(new Rectangle(21, 115, 124, 23)); |
| − | checkBox2.setLabel("Option Number 2"); |
| − | checkBox2.addItemListener(new java.awt.event.ItemListener() { |
| − | public void itemStateChanged(ItemEvent e) { |
| − | checkBox2_itemStateChanged(e); |
| − | } |
| − | }); |
| − | listOptions.setBounds(new Rectangle(154, 85, 216, 116)); |
| − | listOptions.addActionListener(new java.awt.event.ActionListener() { |
| − | public void actionPerformed(ActionEvent e) { |
| − | listOptions_actionPerformed(e); |
| − | } |
| − | }); |
| − | listOptions.addItem("Item Number One"); |
| − | listOptions.addItem("Item Number Two"); |
| − | listOptions.addItem("Item Number Three"); |
| − | listOptions.addItem("Item Number Four"); |
| − | listOptions.addItem("Item Number Five"); |
| − | listOptions.addItem("Item Number Six"); |
| − | |
frame = new JFrame( "My Frame" ); | |
| − | frame.getContentPane().add(checkBox1, null); |
| − | frame.getContentPane().add(checkBox2, null); |
| − | frame.getContentPane().add(txtResults, null); |
| − | frame.getContentPane().add(listOptions, null); |
| − | frame.getContentPane().add(lblEventChecker, null); |
| − | frame.getContentPane().add(btnOK, null); |
| − | frame.getContentPane().add(btnCancel, null); |
| − | frame.getContentPane().add(label1, null); |
| − | frame.getContentPane().add(label2, null); |
| − | frame.setVisible(true); |
frame.setLocation(200, 200); | |
| − | //frame.pack(); |
| + | frame.setSize(300, 300); |
| − | void checkBox2_itemStateChanged(ItemEvent e) { |
| − | txtResults.setText("checkBox2 selected!"); |
| + | 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 ...?"); |
} | |
| − | void checkBox1_itemStateChanged(ItemEvent e) { |
| − | txtResults.setText("checkBox1 selected!"); |
| − | } |
| − | |
| − | void btnOK_actionPerformed(ActionEvent e) { |
| − | txtResults.setText("btnOK selected!"); |
| − | } |
| − | |
| − | void btnCancel_actionPerformed(ActionEvent e) { |
| − | txtResults.setText("btnCancel selected!"); |
| − | } |
| − | |
| − | void listOptions_actionPerformed(ActionEvent e) { |
| − | txtResults.setText(listOptions.getItem(listOptions.getSelectedIndex())); |
| − | } |
| − | |
| − | </eval> |
| + | </run> |