private void saveCurrent() {
    PrintWriter writer = null;

    try {
      writer = new PrintWriter("config.txt", "UTF-8");
      writer.println("PhoneNumbers:");

      for (String s : Main.getEmails()) {
        writer.println(s);
      }

      writer.println("Items:");

      for (Item s : Main.getItems()) {
        writer.println(s.getName() + "," + s.getWebsite());
      }

      results.setText("Current settings have been saved sucessfully.");
    } catch (FileNotFoundException e1) {
      e1.printStackTrace();
    } catch (UnsupportedEncodingException e1) {
      e1.printStackTrace();
    }

    writer.close();
  }
Exemple #2
0
  public void checkInput() {
    // SwingUtilities.invokeLater(new Runnable() {
    // public void run() {
    String text = inputText.getText();
    if (!text.equals("")) {
      appendToPane(text + "\n\n", Color.blue);
      inputText.setText("");
      if (text.startsWith("use ")) {
        ArrayList<Item> inventory = player.getInventory();
        String key = text.substring(4);
        boolean found = false;
        for (Item i : inventory) {
          if (i.getName().equalsIgnoreCase(key)) {
            found = true;
            i.use();
            break;
          }
        }
        if (!found) {
          appendToPane("Item does not exist in your iventory.\n\n", Color.black);
        } else {

        }
      }
      if (text.startsWith("inventory")) {
        ArrayList<Item> inventory = player.getInventory();
        if (inventory.size() > 0) {
          for (Item i : inventory) {
            appendToPane(i.getName() + "\n", Color.darkGray);
          }
        } else appendToPane("Your iventory is empty.\n\n", Color.black);
        appendToPane("#", Color.blue);
      } else {
        userInput = text;
      }
    }
    // }
    // });
  }
  private void displayInformation() {
    results.setText("-Cell Phones-\n");
    if (Main.getEmails().isEmpty()) {
      results.append("\nNo Numbers");
    } else {
      ArrayList<String> emails = Main.getEmails();
      int index = 0;

      for (String s : emails) {
        index++;
        results.append("\n(" + index + ")   " + s);
      }
    }

    results.append("\n\n-Current Items-");
    if (Main.getItems().isEmpty()) {
      results.append("\n\nNo Items");
    } else {
      ArrayList<Item> items = Main.getItems();
      int index = 0;

      for (Item i : items) {
        String s = i.getWebsite().substring(46, i.getWebsite().length());

        index++;

        for (int j = 0; j < s.length(); j++) {
          if (s.substring(j, j + 1).equals("&")) {
            s = s.substring(0, j);
          }
        }

        results.append("\n\n(" + index + ")\nName: \t" + i.getName() + "\nItem: \t" + s);
      }
      results.append("\n\n");
    }
  }