Java Reference
In-Depth Information
The Reservations Class
Figure 5-18 displays the beginning code to start the Reservations program by
declaring the Reservations class. After the block comment, import statements are
used to import three packages. The JOptionPane class of the Swing package will
be used to display message dialog boxes when all of the party rooms are
occupied. The java.awt and java.awt.event packages will be used for methods
related to GUI components and their listeners.
1 /*
2
Chapter 5: Reserve a Party Room
3
Programmer: J. Starks
4
Date:
October 28, 2007
5
Filename:
Reservations.java
6
Purpose:
This program creates a windowed application to reserve a party room.
7
It calls an external class named Rooms.
8 */
9
10 import javax.swing.JOptionPane;
11 import java.awt.*;
12 import java.awt.event.*;
13
14 public class Reservations extends Frame implements ActionListener
15 {
FIGURE 5-18
As shown in Figure 5-18, line 14 extends the Frame class. The Frame class
is the application equivalent of the Applet class, in that it is a logical and visual
object in which components are placed. By extending from the Frame class,
the Reservations class will be a subclass of the Frame class; this means the
Reservations class will behave in a similar manner and will inherit all of the
fields and methods declared or inherited in the Frame class. Programs that use
a window, or GUI-based interface, typically extend the Frame class and are
called windowed applications, or frame-based applications . The Reservations
class will implement the ActionListener because it will receive input, in the form
of a user clicking a button on the program interface.
The following steps enter the beginning code for the Reservations class.
To Enter Beginning Code for the Reservations Class
1. Start TextPad. If TextPad already is running, click the New Document
button on the Standard toolbar.
2. Insert the Data Disk in drive A. Click File on the menu bar and then click
Save As on the File menu. When the Save As dialog box is displayed,
type Reservations in the File name text box and then click Java
(*.java) in the Save as type list. Click the Save in box arrow and then
click 3 1 2 Floppy (A:) in the Save in list. Double-click the Chapter05 folder
or a location specified by your instructor. Click the Save button.
(continued)
Search WWH ::




Custom Search