Java Reference
In-Depth Information
time-consuming procedure must be performed, then a separate thread should be created for
that purpose.
Using the ActionEvent object passed to actionPerformed( ) , you can obtain several
useful pieces of information relating to the button-press event. The one used by this chapter
is the action command string associated with the button. By default, this is the string dis-
played inside the button. The action command is obtained by calling getActionCommand(
) on the event object. It is declared like this:
String getActionCommand( )
The action command identifies the button. Thus, when using two or more buttons within
the same application, the action command gives you an easy way to determine which but-
ton was pressed.
The following program demonstrates how to create a push button and respond to button-
press events. Figure 16-2 shows how the example appears on the screen.
Figure 16-2 Output from the ButtonDemo program
 
Search WWH ::




Custom Search