The Chapter 9 lablet, based on class
OrderPlease
, is interesting for a couple of reasons.
First of all, despite its length, it doesn't really do much. It presents
to its user an increasingly common electronic order form to be filled out,
and when directed to do so, "submits" the order by simply printing the order
information on the screen as it might appear on a shipping label. What
little processing is done (the adding of an item to an order, the resetting
of the order form, and the submitting of the order) is quite simple.
It takes a good deal of code, though, to describe all of the components
and containers that make up the applet's interface.
The most
interesting feature of the lablet--and the reason that we are using
it in this chapter--is that it makes good use of Java's
Exception
subclasses to ensure that any errors or omissions made by the user in
entering information are caught before an order is processed. Using
exceptions can improve radically the "usability" of an applet, particularly
in cases like this where the user is required to enter a lot of information
that is critical to the operation of the program. The exercises that
follow will focus on how the lablet uses exceptions to produce a
"safer" program.
![]() |
In this lab, you will: | ||
![]() |
Run and test this chapter's lablet,
|
||
![]() |
Edit the lablet to cause some typical syntax errors related to exceptions. |
||
![]() |
Add some new exception handling features to the applet. |
OrderPlease
is
devoted to describing the many components and containers in the applet's
interface. One common pair of components is a label and a text field, where
the label describes the information to be entered in the text field.
LabelledTextField
, which extends
class Panel
and holds both a label and a text field.
The class should define methods for constructing labelled text fields
(blank ones, and ones with predefined labels), for setting the text
in the text field, and for getting the text (as a String) from it.
OrderPlease
to use class
LabelledTextField
wherever it is appropriate.
LabelledTextField
to create a class
LabelledIntTextField
. A LabelledIntTextField
is a LabelledTextField
that is designed to hold only integer
values. Add exception handling to class LabelledIntTextField
to detect and prevent any attempt to set an object's text to a non-integer value.