class HotelReservationApp
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class HotelReservationApp extends Frame
implements ActionListener, WindowListener {
private TextField input, output;
private Panel opsPad;
private Checkbox reserveBox;
private Checkbox cancelBox;
private CheckboxGroup ops;
private Button start;
private Reservation resv;
public static void main (String[] args) {
HotelReservationApp sc = new HotelReservationApp(550, 100);
sc.show();
}
public HotelReservationApp(int width, int height) {
super("Hotel Reservation");
this.setSize (width, height);
this.input = new TextField(15);
this.output = new TextField(30);
this.opsPad = new Panel();
this.opsPad.setLayout(new GridLayout(2,1));
CheckboxGroup ops = new CheckboxGroup();
this.reserveBox = new Checkbox("Reserve", ops, true);
this.cancelBox = new Checkbox("Cancel", ops, false);
this.opsPad.add(reserveBox);
this.opsPad.add(cancelBox);
this.start = new Button("Start");
this.setLayout(new FlowLayout());
this.add(input);
this.add(opsPad);
this.add(start);
this.add(output);
this.resv = new Reservation();
start.addActionListener(this);
this.addWindowListener(this);
}
private void reserve(String customer) {
if (resv.reserve (customer)) {
output.setText("Reservation has been made for " + customer + ".");
} else {
output.setText ("The hotel is full.");
}
input.setText("");
}
private void cancel(String customer) {
if (resv.cancel (customer)) {
output.setText("Reservation has been canceled for " + customer + ".");
} else {
output.setText (customer + " has no reservation at this hotel.");
}
input.setText("");
}
public void actionPerformed(ActionEvent evt) {
if (evt.getSource().equals(start)) {
if (reserveBox.getState()) {
reserve(input.getText());
} else {
cancel(input.getText());
}
}
}
public void windowActivated(WindowEvent e) {}
public void windowClosed(WindowEvent e) {}
public void windowClosing(WindowEvent e) {
HotelReservationApp.this.dispose();
}
public void windowDeactivated(WindowEvent e) {}
public void windowDeiconified(WindowEvent e) {}
public void windowIconified(WindowEvent e) {}
public void windowOpened(WindowEvent e) {}
}