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(); }
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"); } }
@SuppressWarnings("deprecation") public void actionPerformed(ActionEvent e) { if (e.getSource() == add1) { addItem(); } if (e.getSource() == add2) { addPhone(); } if (e.getSource() == save1) { saveItem(); } if (e.getSource() == save2) { savePhone(); } if (e.getSource() == help) { help(); } if (e.getSource() == about) { about(); } if (e.getSource() == show) { displayInformation(); } if (e.getSource() == removeItem) { removeItem(); } if (e.getSource() == removePhone) { removePhone(); } if (e.getSource() == clearSaved) { clearSaved(); } if (e.getSource() == saveCurrent) { saveCurrent(); } if (e.getSource() == quitItem) { System.exit(1); } if (e.getSource() == start) { if (Main.getItems().isEmpty()) { results.setText("Please add items to search for."); } else { Main.setSleep((Integer) interval.getValue() * 60000); t2 = new CheckThread(); t2.start(); Main.setCont(true); start.setEnabled(false); stop.setEnabled(true); } } if (e.getSource() == stop) { t2.stop(); Main.setCont(false); start.setEnabled(true); stop.setEnabled(false); } if (e.getSource() == load) { if (Main.getItems().isEmpty()) { Main.loadSettings(); displayInformation(); } else { results.setText("All current items must be cleared before loading. (File>Clear)"); } } if (e.getSource() == clearCurrent) { searchName.setText(""); item.setText(""); results.setText(""); phone.setText(""); interval2.setText(""); carriers.setSelectedIndex(0); Main.clearItems(); Main.clearNumbers(); displayInformation(); } }