O'Reilly logo

Graphic Java™ 1.2, Volume I: AWT, Third Edition by David M. Geary

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Identifying Components by Label — Just Say No

It is standard AWT practice to check against the labels of certain components (in particular, buttons) to determine the component with which an event is associated. For instance, the following applet displays three buttons and uses the labels of the buttons to determine which one triggered an action event:

 import java.applet.Applet; import java.awt.*; public class ButtonActionApplet extends Applet { public void init() { Button buttonOne = new Button("Button One"); Button buttonTwo = new Button("Button Two"); Button buttonThree = new Button("Button Three"); add(buttonOne); add(buttonTwo); add(buttonThree); } public boolean action(Event event, Object what) { if(what.equals("Button One")) System.out.println("Button ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required