import java.applet.Applet; import java.awt.*; import java.awt.event.*; import javax.swing.*; /** * The ClickMe class implements an applet that simply puts up a button * thats ays click me and, when clicked, just prints out the canonical * "Hello World!" message. -- This is the SWING version * * @author Author * @version Version as of 2006-05-05 * For: CIS 355 with Professor Sethi * * Specification: * input(keyboard): * output(screen): ******************************************************************/ public class source_lab04_ClickMeSwing extends JApplet { private JTextField text1; private JButton button1; public void init() { // Declare and initialize our containers and handlers: AppletButtonHandler bHandler = new AppletButtonHandler(); setLayout(new GridLayout(3,1)); // Declare and instantiate our buttons and textfields next: text1 = new JTextField(20); button1 = new JButton("Click me, please!"); // At the same time, add our action listeners: button1.addActionListener(bHandler); // Finally, add them both to the main content pane: add(text1); add(button1); // Set the main container's content pane to visible setVisible(true); } class AppletButtonHandler implements ActionListener { public void actionPerformed(ActionEvent e) { String msg = new String ("Hello, World!"); if (e.getSource() == button1) { text1.setText(msg); } } } // End Inner Class } // End ClickMeSwing Class