Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

how to add a person and his friends through txtfile package gui; import javax.swing.*; import java.util.ArrayList; public class PersonSelectorFrame { private JFrame frame; private JPanel

how to add a person and his friends through txtfile package gui; import javax.swing.*; import java.util.ArrayList; public class PersonSelectorFrame { private JFrame frame; private JPanel panel; private JButton insertThePersonButton; private JButton deleteThePersonButton; private JList list; private JButton profileButton; private JTextField textField1; private DefaultListModel listModel; private ArrayList personList; private Person authPerson; private User authPerson2; public PersonSelectorFrame(Person authPerson) { this.authPerson = authPerson; listModel = new DefaultListModel<>(); list.setModel(listModel); refreshList(); // list.addListSelectionListener(new ListSelectionListener() { // @Override // public void valueChanged(ListSelectionEvent e) { // choice = list.getSelectedIndex(); // System.out.println(choice); // } // }); insertThePersonButton.addActionListener(e -> { try { String name = JOptionPane.showInputDialog("Type the name"); int age = Integer.parseInt(JOptionPane.showInputDialog("Type the age")); String profession = JOptionPane.showInputDialog("Type the profession"); Person p = new Person(name, age, profession); personList.add(p); refreshList(); } catch (NumberFormatException ex) { { JOptionPane.showMessageDialog(panel, "Error: Put a number for age.", "Error Window", JOptionPane.ERROR_MESSAGE ); } } }); deleteThePersonButton.addActionListener(e -> { if (!personList.isEmpty()) { personList.remove(list.getSelectedIndex()); refreshList(); } else { JOptionPane.showMessageDialog(panel, "Error: The list is already empty", "Error Window", JOptionPane.ERROR_MESSAGE ); } }); profileButton.addActionListener(e -> { if (!personList.isEmpty()) { personList.add(list.getSelectedIndex()); User u = new User(name, ) new ProfileForm(); frame.dispose(); refreshList(); } else { JOptionPane.showMessageDialog(panel, "Error: User was not selected", "Error Window", JOptionPane.ERROR_MESSAGE ); } }); // Setup frame // JFrame setup setupFrame(); } // Refresh the List private void refreshList() { listModel.removeAllElements(); for (int i = 0; i < personList.size(); i++) { listModel.addElement(personList.get(i).getFirstName()); } } // setup frame private void setupFrame() { frame = new JFrame("Person Selector"); frame = new JFrame("Counter Application"); frame.setContentPane(panel); frame.setVisible(true); frame.setSize(500, 500); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } } 

public class Person { private String name; private String userName; private String password; private String location; private BST friends = new BST<>(); private List interests; private static int userID = 1; /** * CONSTRUCTOR **/ public Person() { this.name = ""; this.userName = ""; this.password = ""; this.location = ""; } public Person(String name) { userName = ""; this.name = name; password = ""; location = ""; } public Person(String userName, String password) { this.name = ""; this.userName = userName; this.password = password; location = ""; } public Person(String name, String userName, String password, String location, ArrayList al, List l) { NameComparator c = new NameComparator(); this.name = name; this.userName = userName; this.password = password; this.location = location; for (int i = 0; i < al.size(); i++) { friends.insert(al.get(i), c); } this.interests = l; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Application Development And Administration

Authors: Michael V. Mannino

3rd Edition

0071107010, 978-0071107013

More Books

Students also viewed these Databases questions

Question

Determine miller indices of plane A Z a/2 X a/2 a/2 Y

Answered: 1 week ago

Question

Explain the function and purpose of the Job Level Table.

Answered: 1 week ago