示例#1
0
 private void startGame() {
   timer.setDelay(INITIAL_DELAY);
   timer.setPaused(false);
   start_newgame_butt.setLabel("Start New Game");
   pause_resume_butt.setEnabled(true);
   pause_resume_butt.setLabel("Pause");
   pause_resume_butt.validate();
   sounds.playSoundtrack();
 }
    /** Creates a timer if one doesn't already exist, then starts the timer thread. */
    private void start(int interval) {
      previousDelay = interval;
      lastCall = 0;

      if (timer == null) {
        timer = new Timer(interval, this);
      } else {
        timer.setDelay(interval);
      }

      if (ADJUSTTIMER) {
        timer.setRepeats(false);
        timer.setCoalesce(false);
      }

      timer.start();
    }
 /** Stops the animation. */
 public void stopAnimation() {
   timer.setDelay(STATIC_CLOCK_INTERVALS);
 }
 /** Starts the animation. */
 public void startAnimation() {
   timer.setDelay(ANIMATION_CLOCK_INTERVALS);
 }
  /** 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();
          }
        });
  }