Java Reference
In-Depth Information
In-Store Sales
option button
is selected
Applet Viewer
window
Close
button
Telephone Sales
option button is
no longer
selected
FIGURE 4-49
OTHER WAYS
6. Click the Close button in the Applet Viewer window. If necessary, click
the Close button in the command prompt window title bar.
The applet terminates and the command prompt window closes.
1. To compile, press
CTRL + 1
2. To compile at
command prompt,
type javac
CommissionApplet.
java
3. To run, press CTRL + 3 ,
choose file, click Yes
button
4. To run at command
prompt, type
appletviewer
CommissionApplet.
html
Setting the hidden Checkbox to true, as part of the CheckboxGroup, means
that when the applet starts, none of the option buttons displayed on the user
interface are selected. The hidden Checkbox allows you to control the selection
when the applet starts rather than letting a default selection dictate the course
of the program.
Handling Exceptions in the Applet Using try
and catch Statements
When one of the Checkboxes in the CheckboxGroup is selected by a user
during run time, the ItemListener changes the state of the component. That
means when a user clicks an option button, the itemStateChanged() method is
triggered.
In the applet, the code in the itemStateChanged() method includes a try
and catch statement to call the methods used to test for valid data and to handle
exceptions. The try and catch statements are shown in Figure 4-50 on the next
page.
Search WWH ::




Custom Search