コード例 #1
0
  public void actionPerformed(ActionEvent e) {
    if (e.getSource() == selectOutfit) {

      setContentPane(frontEndPane);
      startFrontEndPane = null; // not used after button is pressed

      buttonHolder.add(replaceOutfit);
      topPanel.add(db.getItem("Trousers"));
      topPanel.add(db.getItem("T-Shirts"));
      topPanel.add(db.getItem("Jackets"));
      topPanel.add(db.getItem("Shoes"));
      topPanel.add(db.getItem("Sweaters"));
      showTotalPrice(true); // displays the price of selected items on right
      showTotalPrice(false); // displays total price of all items on left
    }

    // Suggest all 5 clothes categories again
    // if replace button is pressed
    if (e.getSource() == replaceOutfit) {
      // if clothesItem topPanel is NOT checked
      if (!((ClothesItem) topPanel.getComponent(0))
          .isChecked()) { // remove 0 element, 1 element, and so on..
        topPanel.remove(0);
        // topPanel gets the next trousers from the database
        topPanel.add(db.getItem("Trousers"), 0);
      }

      if (!((ClothesItem) topPanel.getComponent(1)).isChecked()) {
        topPanel.remove(1);
        topPanel.add(db.getItem("T-Shirts"), 1);
      }

      if (!((ClothesItem) topPanel.getComponent(2)).isChecked()) {
        topPanel.remove(2);
        topPanel.add(db.getItem("Jackets"), 2);
      }

      if (!((ClothesItem) topPanel.getComponent(3)).isChecked()) {
        topPanel.remove(3);
        topPanel.add(db.getItem("Shoes"), 3);
      }

      if (!((ClothesItem) topPanel.getComponent(4)).isChecked()) {
        topPanel.remove(4);
        topPanel.add(db.getItem("Sweaters"), 4);
      }
      showTotalPrice(true);
      showTotalPrice(false);
    }

    if (e.getSource() == help) {
      totalPrice.setText(
          "Pressed Help, press \"Replace\" to switch clothes already shown and unchecked");
    }

    if (e.getSource() == exit) {
      totalPrice.setText("Exiting...");
      this.dispose();
    }

    if (e.getSource() == total) {
      showTotalPrice(false);
    }
  }