public static void main(String[] args) { ContactList list = new ContactList("Contacts.txt"); Scanner input = new Scanner(System.in); boolean exit = false; System.out.println("Welcome to the Contact Manager!"); do { System.out.println("-------------------"); System.out.println( "Do you want to:\n1) See all contacts\n2)See a specific contact\n3)Enter a new contact\n4+)Quit"); int userInput = Integer.parseInt(input.nextLine()); switch (userInput) { case 1: System.out.println("-------------------"); System.out.println("All contacts:"); list.listContactNames(); break; case 2: System.out.println("-------------------"); System.out.println("Enter the name of the contact that you wish to see"); String userInput2 = input.nextLine(); System.out.println("-------------------"); list.getContact(userInput2); System.out.println(); break; case 3: System.out.println("-------------------"); System.out.println( "Enter the name, then the email, and the number in order to add the contact"); String name = input.nextLine(); String email = input.nextLine(); String number = input.nextLine(); list.addContact(name, email, number); System.out.println("-------------------"); System.out.println("\n" + name + "'s Contact has been added:\n" + list.getContact(name)); break; default: System.out.println("-------------------"); System.out.println("Goodbye."); exit = true; break; } } while (exit == false); }
public void actionPerformed(ActionEvent e) { if (to == e.getSource()) { toSendWindow(); // Display list for user selection // puts user selection into JTextField to } else if (addContacts == e.getSource()) { addContactWindow(); // Display prompt for information for new contact // Uses information to add to ContactList collection // } else if (removeContacts == e.getSource()) { removeContactWindow(); // Display prompt for removing contacts // Uses information to remove from ContactList collection } else if (editContacts == e.getSource()) { editContactWindow(); // UI for editing contacts } else if (save == e.getSource()) { cList.addContact( new Contact( newContactFields[0].getText(), newContactFields[1].getText(), newContactFields[2].getText())); JOptionPane.showMessageDialog( null, "The contact has been added.", "Success!", JOptionPane.INFORMATION_MESSAGE); addWindow.dispose(); } else if (deleteContact == e.getSource()) { ContactList cDeleted = contactList.getContacts(); for (int i = 0; i < cDeleted.getLength(); i++) { cList.removeContact(cDeleted.getContact(i)); /* PLACEHOLDER FOR REPAINT */ } removeWindow.dispose(); } else if (addSendContacts == e.getSource()) { toText.setText(toText.getText() + contactList.getEmails()); toWindow.dispose(); } }