The JDK 1.0 Event Model

In JDK 1.0.2, the default handleEvent method calls other methods depending on the type of event that occurred:

The strange part about AWT is that AWT components ignore events. A button for instance ignores the action event and passes it to its container. That container has to figure out which component was the target of the event. Below is an example of a small applet with two buttons, and the event handling code:

public class Button1Applet extends Applet {
    public void init() {
	add(new Button("Red"));
	add(new Button("Blue"));
    }
    public boolean action(Event evt, Object whatAction) {
	if (!(evt.target instanceof Button))
	    return false;
	String buttonLabel = (String)whatAction;
	if (buttonLabel == "Red")
	    setBackground(Color.red);
	else if (buttonLabel == "Blue")
	    setBackground(Color.blue);
	repaint();
	return true;
    }
}