CodeZip/ButtonDemo.javaCodeZip/ButtonDemo.java// Demonstrate a push button and handle action events. import java.awt.*; import java.awt.event.*; import javax.swing.*; publicclassButtonDemoimplementsActionListener{ JLabel jlab; JTextField jtf; ButtonDemo(){ // Create a new JFrame container. JFrame jfrm =newJFrame("A Button Example"); // Specify FlowLayout for the layout manager. jfrm.setLayout(newFlowLayout()); // Give the frame an initial size. jfrm.setSize(220,90); // Terminate the program when the user closes the application. jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Make two buttons. JButton jbtnUp =newJButton("Up"); JButton jbtnDown =newJButton("Down"); // Create a text field. jtf =newJTextField(10); // Add action listeners. jbtnUp.addActionListener(this); jbtnDown.addActionListener(this); // Add the buttons to the content pane. jfrm.add(jbtnUp); jfrm.add(jbtnDown); jfrm.add(jtf); // Create a label. jlab =newJLabel("Press a button."); // Add the label to the frame. jfrm.add(jlab); // Display the frame. jfrm.setVisible(true); } // Handle button events. publicvoid actionPerformed(ActionEvent ae){ if(ae.getActionCommand().equals("Up")){ jlab.setText("You pressed Up."); FileClock clock1=newFileClock(jtf); Thread thread1=newThread(clock1); thread1.start(); } else jlab.setText("You pressed down. "); } publicstaticvoid main(String args[]){ // Create the frame on the event dispatching thread. SwingUtilities.invokeLater(newRunnable(){ publicvoid run(){ newButtonDemo(); } }); } } CodeZip/CBDemo.javaCodeZip/CBDemo.java// Demonstrate check boxes. import java.awt.*; import java.awt.event.*; import javax.swing.*; publicclassCBDemoimplementsItemListener{ JLabel jlabSelected; JLabel jlabChanged; JCheckBox jcbAlpha; JCheckBox jcbBeta; JCheckBox jcbGamma; CBDemo(){ // Create a new JFrame container. JFrame jfrm =newJFrame("Demonstrate Check Boxes"); // Specify FlowLayout for the layout manager. jfrm.setLayout(newFlowLayout()); // Give the frame an initial size. jfrm.setSize(280,120); // Terminate the program when the user closes the application. jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Create empty labels. jlabSelected =newJLabel(""); jlabChanged =newJLabel(""); // Make check boxes. jcbAlpha =newJCheckBox("Alpha"); jcbBeta =newJCheckBox("Beta"); jcbGamma =newJCheckBox("Gamma"); // Events generated by the check boxes // are handled in common by the itemStateChanged() // method implemented by CBDemo. jcbAlpha.addItemListener(this); jcbBeta.addItemListener(this); jcbGamma.addItemListener(this); // Add checkboxes and labels to the content pane. jfrm.add(jcbAlpha); jfrm.add(jcbBeta); jfrm.add(jcbGamma); jfrm.add(jlabChanged); jfrm.add(jlabSelected); // Display the frame. jfrm.setVisible(true); } // This is the handler for the check boxes..