-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddressBookGUI.java
More file actions
79 lines (71 loc) · 2.75 KB
/
AddressBookGUI.java
File metadata and controls
79 lines (71 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package com.company;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
/**
* AddressBookGUI creates a user interface for our AddressBook
* with the options to display all contacts, add a new contact,
* search an existing contact, remove an existing contact, or
* to close the program
* @Author Michael LaRussa
* @Since 3/17/2021
*/
public class AddressBookGUI extends JDialog{
private JPanel contentPane;
private JButton displayButton;
private JButton removeButton;
private JButton newButton;
private JScrollPane scrollPane;
JList <AddressEntry> addressEntryJList = new JList<AddressEntry>();
DefaultListModel<AddressEntry> myaddressEntryListModel = new DefaultListModel<AddressEntry>();
AddressBook ab = new AddressBook();
AddressEntry x = new AddressEntry("Michael", "LaRussa", "Calaveras Expy.", "Milpitas", "California", 95035, "555-123-4567", "Example@gmail.com");
/**
* Constructs the user Interface for our AddressBook
*/
public AddressBookGUI() {
setContentPane(contentPane);
setModal(true);
ab.add(x);
displayButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
myaddressEntryListModel = new DefaultListModel<AddressEntry>();
for(int i = 0; i<ab.addressEntryList.size(); i++)
{ myaddressEntryListModel.add(i, ab.addressEntryList.elementAt(i)); }
addressEntryJList = new JList<AddressEntry>(myaddressEntryListModel);
addressEntryJList.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
addressEntryJList.setLayoutOrientation(JList.HORIZONTAL_WRAP);
addressEntryJList.setVisibleRowCount(-1);
scrollPane.setViewportView(addressEntryJList);
}
});
newButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
NewGUI newGUI = new NewGUI(ab);
newGUI.pack();
newGUI.setVisible(true);
}
});
removeButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Integer index = addressEntryJList.getSelectedIndex();
ab.addressEntryList.removeElementAt(index);
}
});
}
/**
* This is the Main function
* It creates an instance of the AddressBookGUI object
*
* @param args
*/
public static void main(String[] args) {
AddressBookGUI dialog = new AddressBookGUI();
dialog.pack();
dialog.setVisible(true);
System.exit(0);
}
}