/** Action listener method that reacts to the checkbox being clicked or button pushed */
  public void actionPerformed(ActionEvent e) {

    if (e.getSource() == stateCB) {
      if (currentPerson instanceof CustomerAgent) {
        CustomerAgent c = (CustomerAgent) currentPerson;
        c.setHungry(hunger);
        stateCB.setEnabled(false);
      }
    } else if (e.getSource() == changeOrder) {
      if (currentPerson instanceof CustomerAgent) {
        CustomerAgent c = (CustomerAgent) currentPerson;
        c.waiter.msgIWantToChangeOrder(c);
        // changeOrder.setEnabled(false);
      }
    } else if (e.getSource() == requestBreak) {
      if (currentPerson instanceof WaiterAgent) {
        WaiterAgent w = (WaiterAgent) currentPerson;
        w.requestBreak();
      }
    } else if (e.getSource() == addTable) {
      try {
        System.out.println("[Gautam] Add Table!");
        // String XPos = JOptionPane.showInputDialog("Please enter X Position: ");
        // String YPos = JOptionPane.showInputDialog("Please enter Y Position: ");
        // String size = JOptionPane.showInputDialog("Please enter Size: ");
        // restPanel.addTable(10, 5, 1);
        // restPanel.addTable(Integer.valueOf(YPos).intValue(), Integer.valueOf(XPos).intValue(),
        // Integer.valueOf(size).intValue());
        restPanel.addTable();
      } catch (Exception ex) {
        System.out.println("Unexpected exception caught in during setup:" + ex);
      }
    }
  }
Exemple #2
0
  /** Constructor for RestaurantGui class. Sets up all the gui components. */
  public RestaurantGui() {
    int WINDOWX = 600;
    int WINDOWY = 500;

    ButtonPanel = new JPanel();
    MrKrabs = new ImageIcon(getClass().getResource("/resources/MrKrabs.png"));
    Ramsay = new ImageIcon(getClass().getResource("/resources/Ramsay.png"));

    RestaurantPortion.setLayout(new BorderLayout());
    InformationPanel = new JPanel();
    InformationPanel.setLayout(new BorderLayout());
    buttonPanel = new JPanel();
    buttonPanel.setLayout(new BorderLayout());

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setBounds(25, 25, WINDOWX + 650, WINDOWY + 170);
    setVisible(true);

    setLayout(new BorderLayout());
    Dimension restDim = new Dimension(WINDOWX, (int) (WINDOWY * .86));
    restPanel.setPreferredSize(restDim);
    restPanel.setMinimumSize(restDim);
    restPanel.setMaximumSize(restDim);

    // pauseButton = new JButton("PAUSE");
    // pauseButton.addActionListener(this);
    refreshButton = new JButton("REFRESH");
    refreshButton.addActionListener(this);

    // CUSTOMER PANEL INFORMATION
    Dimension infoDimCustomer = new Dimension(WINDOWX, (int) (WINDOWY * .12));
    customerInformationPanel = new JPanel();
    customerInformationPanel.setPreferredSize(infoDimCustomer);
    customerInformationPanel.setMinimumSize(infoDimCustomer);
    customerInformationPanel.setMaximumSize(infoDimCustomer);
    customerInformationPanel.setBorder(BorderFactory.createTitledBorder("Customers"));

    customerStateCheckBox = new JCheckBox();
    customerStateCheckBox.setVisible(false);
    customerStateCheckBox.addActionListener(this);

    customerInformationPanel.setLayout(new GridLayout(1, 2, 30, 0));

    infoCustomerLabel = new JLabel();
    infoCustomerLabel.setText("<html><pre><i>There are no restaurant customers.</i></pre></html>");
    customerInformationPanel.add(infoCustomerLabel);
    customerInformationPanel.add(customerStateCheckBox);

    // WAITER PANEL INFORMATION/*
    /*
    Dimension infoDimWaiter = new Dimension(WINDOWX, (int) (WINDOWY * .12));
    waiterInformationPanel = new JPanel();
    waiterInformationPanel.setPreferredSize(infoDimWaiter);
    waiterInformationPanel.setMinimumSize(infoDimWaiter);
    waiterInformationPanel.setMaximumSize(infoDimWaiter);
    waiterInformationPanel.setBorder(BorderFactory.createTitledBorder("Waiters"));

    waiterON.addActionListener(this);
    waiterOFF.addActionListener(this);
    */
    // waiterInformationPanel.setLayout(new GridLayout(1, 2, 30, 0));

    infoWaiterLabel = new JLabel();
    infoWaiterLabel.setText("<html><pre><i>Click Add to make waiters</i></pre></html>");
    // waiterInformationPanel.add(infoWaiterLabel);
    waiterON.setVisible(false);
    waiterOFF.setVisible(false);
    // waiterInformationPanel.add(waiterON);
    // waiterInformationPanel.add(waiterOFF);
    RestaurantPortion.add(restPanel, BorderLayout.NORTH);
    InformationPanel.add(customerInformationPanel, BorderLayout.CENTER);
    MrKrabsButton = new JButton(MrKrabs);
    RamsayButton = new JButton(Ramsay);
    MrKrabsButton.addActionListener(this);
    RamsayButton.addActionListener(this);
    ButtonPanel.setLayout(new BorderLayout());
    ButtonPanel.add(MrKrabsButton, BorderLayout.WEST);
    ButtonPanel.add(RamsayButton, BorderLayout.EAST);
    InformationPanel.add(ButtonPanel, BorderLayout.SOUTH);
    // InformationPanel.add(waiterInformationPanel, BorderLayout.CENTER);
    RestaurantPortion.add(InformationPanel, BorderLayout.CENTER);
    // buttonPanel.add(pauseButton, BorderLayout.CENTER);
    buttonPanel.add(refreshButton, BorderLayout.CENTER);
    RestaurantPortion.add(buttonPanel, BorderLayout.SOUTH);

    add(animationPanel, BorderLayout.CENTER);
    add(RestaurantPortion, BorderLayout.EAST);
  }
  /** Constructor for RestaurantGui class. Sets up all the gui components. */
  public RestaurantGui() {

    super("Restaurant Application");

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setBounds(50, 50, WINDOWX, WINDOWY);

    getContentPane().setLayout(new BoxLayout((Container) getContentPane(), BoxLayout.Y_AXIS));

    Dimension rest = new Dimension(WINDOWX, (int) (WINDOWY * .4));
    Dimension info = new Dimension(WINDOWX, (int) (WINDOWY * .1));
    restPanel.setPreferredSize(rest);
    restPanel.setMinimumSize(rest);
    restPanel.setMaximumSize(rest);
    infoPanel.setPreferredSize(info);
    infoPanel.setMinimumSize(info);
    infoPanel.setMaximumSize(info);
    infoPanel.setBorder(BorderFactory.createTitledBorder("Information"));

    inventorySetup.setLayout(new BorderLayout());
    inventorySetup.add(inventoryLabel, BorderLayout.NORTH);
    chicken.setMajorTickSpacing(1);
    chicken.setPaintLabels(true);
    chicken.setPaintTicks(true);
    steak.setMajorTickSpacing(1);
    steak.setPaintLabels(true);
    steak.setPaintTicks(true);
    pizza.setMajorTickSpacing(1);
    pizza.setPaintLabels(true);
    pizza.setPaintTicks(true);
    salad.setMajorTickSpacing(1);
    salad.setPaintLabels(true);
    salad.setPaintTicks(true);
    chicken.addChangeListener(this);
    steak.addChangeListener(this);
    pizza.addChangeListener(this);
    salad.addChangeListener(this);
    custHungerLevel.addChangeListener(this);
    currentChicken.setEditable(false);
    currentSteak.setEditable(false);
    currentSalad.setEditable(false);
    currentPizza.setEditable(false);

    moneyLabel.setText("New Customer Money");
    customerMoney.setEditable(true);
    custMoneyInput.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            custMoney = Integer.parseInt(customerMoney.getText());
          }
        });
    custMoneyInput.setText("submit");

    moneyPanel.setLayout(new GridLayout(1, 3));
    moneyPanel.add(moneyLabel);
    moneyPanel.add(customerMoney);
    moneyPanel.add(custMoneyInput);
    /*currentChicken.setText(Integer.toString(restPanel.cook.inventory.get("Chicken").currentNumber));
    currentSteak.setText(Integer.toString(restPanel.cook.inventory.get("Steak").currentNumber));
    currentPizza.setText(Integer.toString(restPanel.cook.inventory.get("Pizza").currentNumber));
    currentSalad.setText(Integer.toString(restPanel.cook.inventory.get("Salad").currentNumber));*/

    inventoryInput.setLayout(new GridLayout(5, 3));
    inventoryInput.add(chickenLabel);
    inventoryInput.add(currentChicken);
    inventoryInput.add(chicken);
    inventoryInput.add(saladLabel);
    inventoryInput.add(currentSalad);
    inventoryInput.add(salad);
    inventoryInput.add(pizzaLabel);
    inventoryInput.add(currentPizza);
    inventoryInput.add(pizza);
    inventoryInput.add(steakLabel);
    inventoryInput.add(currentSteak);
    inventoryInput.add(steak);
    inventoryInput.add(hungerLabel);
    inventoryInput.add(custHungerLevel);

    inventorySetup.add(inventoryInput, BorderLayout.CENTER);

    requestBreak.addActionListener(this);
    requestBreak.setVisible(false);

    stateCB.setVisible(false);
    stateCB.addActionListener(this);
    changeOrder.setVisible(false);
    changeOrder.addActionListener(this);

    infoPanel.setLayout(new GridLayout(1, 2, 30, 0));
    infoPanel.add(infoLabel);
    infoPanel.add(stateCB);
    infoPanel.add(requestBreak);
    infoPanel.add(changeOrder);

    getContentPane().add(restPanel);
    getContentPane().add(addTable);
    getContentPane().add(infoPanel);
    getContentPane().add(moneyPanel);
    getContentPane().add(inventorySetup);

    addTable.addActionListener(this);

    t.setDelay(40);
    t.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            updateInventory();
          }
        });
  }