Java Reference
In-Depth Information
if (cmd.equals ( " A " )) {
fPushACount++;
showStatus (event.getActionCommand () +
"pushed" + fPushACount + "times");
} else {
fPushBCount++;
showStatus (event.getActionCommand () +
"pushed" + fPushBCount + "times");
}
} // actionPerformed
} // class PlainButtonApplet
The ActionEvent class also includes the method
public int getModifiers ()
The integer returns with a bitwise OR of the values indicating what mod-
ifier keys were held down when the event occurred. For example, a value
of 0x09 would indicate the OR of ActionEvent.ALT - MASK (0x08) and
ActionEvent.SHIFT - MASK (0x01) for the Alt and Shift keys, respectively.
7.2.4 Simple GUI
In Chapter 6 we created a very basic display with two buttons, two text fields,
corresponding labels, plus a text area. However, that applet could not perform
any operation. Now that we know about button event handling, we can create a
genuine user interface with these components.
Figure 7.2 shows the display from the MultiPanelWithEvents applet
whose code is given below. It corresponds to the MultiPanelApplet example
from Chapter 6 and uses the same InputsPanel class. However, now the applet
implements the ActionListener interface and the ActionButtonsPanel
is modified to pass an ActionListener reference in the constructor. Each
button adds this reference to its list of listeners to send events.
Figure 7.2 With a layout like that in Figure 6.4(b), the MultiPanelWithEvents applet
can handle events generated by the buttons and execute the selected operation on
the data values in the text fields. It then displays the result in the text area.
Search WWH ::




Custom Search