GUIReservationTester
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
/**
* This is GUI tester to test the hotel reservation class
*
* @author Terence (adopted from HotelReservation)
* @version 1.0.0
*/
public class GUIReservationTester extends Applet
implements ActionListener {
private TextField input, output;
private TextArea testOutput;
private Button reserveButton , cancelButton ;
private NewReservation reservation;
/**
* Initializes widgets and creates layouts.
*
*/
public void init() {
reservation = new NewReservation();
input = new TextField(15);
output = new TextField(30);
testOutput = new TextArea(10,50);
reserveButton = new Button("Reserve");
cancelButton = new Button("Cancel");
add(reserveButton );
add(cancelButton );
add(input);
add(output);
add(testOutput);
reserveButton.addActionListener(this);
cancelButton.addActionListener(this);
}
private void reserve(String customer) {
if (reservation.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 (reservation.cancel (customer)) {
output.setText("Reservation has been canceled for " + customer + ".");
} else {
output.setText (customer + " has no reservation at this hotel.");
}
input.setText("");
}
private void listOccupancy() {
String s = "";
int size = reservation.occupancy.length;
for (int i=0; i < size; i++) {
s = s + reservation.occupancy[i] + '\n';
}
testOutput.setText(s);
}
/**
* Process the button events.
*
* @param e the event generated.
*/
public void actionPerformed(ActionEvent evt) {
if (evt.getSource().equals(reserveButton )) {
reserve(input.getText());
} else {
cancel(input.getText());
}
listOccupancy();
}
}