//Click.java //Demonstrate the simplest event handling //By Andy Harris, 4 / 00 import java.awt.*; import java.applet.*; import java.awt.event.*; public class Click extends Applet implements ActionListener{ //Create some objects Label lblOutput = new Label("Don't click the button"); Button btnClickMe = new Button("Don't click me!"); public void init(){ //set up a Grid Layout with one column, as many rows as needed setLayout(new GridLayout(0,1)); //set up an 'applet-wide' default font this.setFont(new Font("SansSerif", Font.BOLD, 20)); //add the objects add(lblOutput); add(btnClickMe); //beautify the label lblOutput.setAlignment(Label.CENTER); lblOutput.setBackground(Color.yellow); //register the actionListener btnClickMe.addActionListener(this); } // end init public void actionPerformed(ActionEvent e){ //Complain lblOutput.setText("Ouch!!!"); } // end actionPerformed } // end class def