Esempio n. 1
0
  @Override
  public void actionPerformed(ActionEvent e) {

    Object src = e.getSource();
    if (src.getClass().equals(button.getClass())) {
      System.out.println(catalogo.genText());
    }
    catalogo.setFilter(filter.getSelectedItem().toString());
    // System.out.println(filter.getSelectedItem().toString());

    //	event.setFilter(filter.getSelectedItem().toString());

  }
Esempio n. 2
0
  /**
   * converts from actionEvent (from inventory button) to InputEvent2D and notifies
   *
   * @param arg0 the ActionEvent
   */
  @Override
  public void actionPerformed(ActionEvent event) {
    if (event.getSource().getClass().equals(JButton.class)) {
      JButton pressed = (JButton) (event.getSource());
      if (pressed.equals(inventoryButton)) {
        notifyInputListeners(new InputEvent2D(new Command(CommandWord.inventory, null)));
        if (inventoryWin != null
            && inventoryWin
                .isDisplayable()) { // closes window if its already open when you click the button
          inventoryWin.dispose();
        } else {
          inventoryWindow();
        }
      } else if (pressed.equals(characterButton)) {
        notifyInputListeners(new InputEvent2D(new Command(CommandWord.character, null)));
        if (characterWindow != null && characterWindow.isDisplayable()) {
          characterWindow.dispose();
        } else {
          characterWindow();
        }
      } else if (pressed.equals(undoButton)) {
        notifyInputListeners(new InputEvent2D(new Command(CommandWord.undo, null)));
      } else if (pressed.equals(redoButton)) {
        notifyInputListeners(new InputEvent2D(new Command(CommandWord.redo, null)));
      } else if (pressed.equals(helpButton)) {
        notifyInputListeners(new InputEvent2D(new Command(CommandWord.help, null)));
      } else if (pressed.equals(quitButton)) {
        notifyInputListeners(new InputEvent2D(new Command(CommandWord.quit, null)));
      } else if (pressed.equals(saveButton)) {
        notifyInputListeners(new InputEvent2D(new Command(CommandWord.save, null)));
      } else if (pressed.getClass().equals(JButton.class)) { // inventory or character button
        JButton src = (JButton) event.getSource();
        if (src.getText().startsWith("drop")) {
          notifyInputListeners(
              new InputEvent2D(new Command(CommandWord.drop, "" + src.getText().substring(5))));

        } else {
          notifyInputListeners(new InputEvent2D(new Command(CommandWord.use, "" + src.getText())));
        }
        // updates windows
        if (inventoryWin != null && inventoryWin.isVisible()) {
          inventoryWindow();
        }
        if (characterWindow != null && characterWindow.isVisible()) {
          characterWindow();
        }
      }
    }
    if (event.getSource().getClass().equals(JTextField.class)) {
      JTextField source = (JTextField) (event.getSource());

      displayMessage(source.getText());

      String word1 = null;
      String word2 = null;

      Scanner tokenizer = new Scanner(source.getText());
      if (tokenizer.hasNext()) {
        word1 = tokenizer.next(); // get first word
        if (tokenizer.hasNext()) {
          word2 = tokenizer.next(); // get second word
          // note: we just ignore the rest of the input line.
        }
      }
      tokenizer.close();

      Command toNotify = new Command(CommandWord.getCommandFromString(word1), word2);
      notifyInputListeners(new InputEvent2D(toNotify));

      source.setText("");
    }
  }