Java Reference
In-Depth Information
public class ButtonApplet extends Applet
implements ActionListener {
Label label;
public ButtonApplet() {
}
public void init() {
label = new Label("Hello World");
Button button = new Button("Click Here");
add(label);
add(button);
button.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
label.setText("Click!");
}
}
While simplistic, this code shows the basic idea: objects interested in receiving
events must declare themselves as implementing the appropriate listening interface,
and then signal to the generator of the event that they're listening for events by invoking
the appropriate method. This example does this by implementing the ActionListener
contract that provides the actionPerformed method. Additionally, the applet notifies the
button, which generates ActionEvents , that it wants to receive any ActionEvents that the
button generates.
Developing User Interfaces with the AGUI
The AGUI package, defined in JSR 209, provides a subset of the Java Swing classes for Java
ME devices. Using the AGUI, you can develop essentially a single application that runs
atop both a AGUI-enabled Java ME device and a conventional computer. The AGUI pack-
age depends on CDC 1.1, FP 1.1, and PBP 1.1, and it provides the following packages:
• A subset of the java.awt package to provide the class hierarchy for implementing
the AGUI's lightweight components
• The java.awt.font package to support rendering PostScript Type 1, Type 1 multiple
master, OpenType, and TrueType fonts
• The java.awt.geom package for operations on objects related to two-dimensional
geometry
 
Search WWH ::




Custom Search