Java Reference
In-Depth Information
FIGURE 12-25 Sample output of the Java Kiosk program
Input: A list of selected items from the menu shown on the left in Figure 12-25.
Output: A bill shown on the right in Figure 12-25.
As shown in Figure 12-25, there are five GUI components: a frame, a label, a list, a
text area, and a button. All components other than the frame are placed into the
content pane of the window. The user selects various list items and then presses the
Selection Completed button. Recall that when you click a button, it generates an
action event, which is processed by using the interface ActionListener . There-
fore, we will create and register an action listener object with the button.
PROBLEM
ANALYSIS
AND GUI AND
ALGORITHM
DESIGN
When the event is generated, the event handler computes the subtotal, tax, and total.
The program then displays the result in the text area. To create the label, list, text
area, and button, we use reference variables of the types JLabel , JList , JTextArea ,
and JButton , respectively. We also need a reference variable to access the content
pane of the window. As in the GUI programs in previous chapters, we create the class
containing the application program by extending the definition of the class
JFrame ; this also allows us to create the necessary window to create the GUI. Thus,
we use the following reference variables to create the GUI components and to access
the content pane of the window:
private JList yourChoices;
private JTextArea bill;
Search WWH ::




Custom Search