Ejemplo n.º 1
0
 private void bookRoom(String name, String phone, boolean smoking, int partySize) {
   boolean booked = false;
   // Iterate over the rooms
   for (Room r : rooms) {
     // To find one that is available and meets the client's smoking preference
     if (r.isAvailable() && (r.isSmokingRoom() == smoking)) {
       // Then book the room
       r.bookRoom(name, phone, partySize);
       booked = true;
       break;
     }
   }
   if (!booked) {
     // Show a message alerting the user with the Reservations frame as the alert's parent or
     // origin frame
     JOptionPane.showMessageDialog(
         this, "Could not find an available room that meet the client's preferences.");
   }
 }
Ejemplo n.º 2
0
 public void run() {
   while (true) {
     if (!isFirst) {
       room.physic();
     }
     repaint();
     try {
       Thread.sleep(1);
     } catch (Exception e) {
     }
   }
 }
Ejemplo n.º 3
0
 public void paintComponent(Graphics g) { // display
   if (isFirst) {
     myWidth = getWidth();
     myHeight = getHeight();
     define();
     isFirst = false;
   }
   g.clearRect(0, 0, getWidth(), getHeight());
   room.draw(g); // draw map
   store.draw(g); // draw sidebar
   // b.draw(g);
   theMinion.draw(g);
   if (to != null) { // tower selected movement
     to.draw(g, xval, yval, to);
   }
   for (Tower i : tplace) {
     i.draw(g, i);
   }
 }
Ejemplo n.º 4
0
  // Visual element creation
  public void init() {
    // Because the damn thing doesn't play well with a FlowLayout
    setLayout(new BorderLayout());

    // Initialize the upper grid panel
    gridPanel = new JPanel(new GridLayout(2, 4, 5, 5));

    // Allow space between the text areas
    gridPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

    for (Room room : rooms) {
      // Make sure everything is sufficiently large and add them to the grid
      room.setPreferredSize(new Dimension(50, 50));
      gridPanel.add(room, room.roomIndex);
    }

    // Initialize the information input panel
    infoPanel = new JPanel(new FlowLayout());

    // Create the helper labels
    nameLabel = new JLabel("Name:");
    phoneLabel = new JLabel("Phone #:");
    partyLabel = new JLabel("Number in party:");
    smokingLabel = new JLabel("Smoking preference:");

    // Create the text input fields
    nameField = new JTextField(20);
    phoneField = new JTextField(12);

    // Create a *party* box
    Vector<String> items = new Vector<String>();
    for (int i = 8; i <= 20; i++) {
      items.add(String.valueOf(i));
    }

    partyBox = new JComboBox(items);

    // Create the radio buttons
    hiddenRadio = new JRadioButton("");
    hiddenRadio.setVisible(false);
    hiddenRadio.setSelected(true);

    smokingRadio = new JRadioButton("Smoking");

    nonSmokingRadio = new JRadioButton("Non-Smoking");

    // Create the radio group and add the radio buttons
    radioGroup = new ButtonGroup();
    radioGroup.add(hiddenRadio);
    radioGroup.add(smokingRadio);
    radioGroup.add(nonSmokingRadio);

    // Add the objects to the info panel
    infoPanel.add(nameLabel);
    infoPanel.add(nameField);
    infoPanel.add(phoneLabel);
    infoPanel.add(phoneField);
    infoPanel.add(partyLabel);
    infoPanel.add(partyBox);
    infoPanel.add(smokingLabel);
    infoPanel.add(smokingRadio);
    infoPanel.add(nonSmokingRadio);

    // Create the submit panel
    submitPanel = new JPanel();

    submitButton = new JButton("Book room");
    submitButton.addActionListener(this);

    submitPanel.add(submitButton);

    add(gridPanel, BorderLayout.NORTH);
    add(infoPanel, BorderLayout.CENTER);
    add(submitPanel, BorderLayout.SOUTH);
  }