-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathContactBookMainUI.java
110 lines (96 loc) · 3.48 KB
/
ContactBookMainUI.java
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/**
* contacts book
* autor Diego Alfaro
* github diegoalfarog
* @version 0.1
* date: 4/15/2021
*/
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import java.awt.FlowLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class ContactBookMainUI extends JFrame {
private static final long serialVersionUID = 1023761073924873760L;
private JButton addContactButton;
private JButton searchContactButton;
private JButton showAllContactsButton;
private JButton removeContactButton;
private JButton removeAllContactsButton;
private JButton exitButton;
public ContactBookMainUI(ContactBook contactBook) {
super("Contact Book");
JFrame contextPaternComponent = this;
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
setLayout(new FlowLayout(FlowLayout.CENTER, 5, 10));
addContactButton = new JButton("Add Contact");
searchContactButton = new JButton("Search Contact");
showAllContactsButton = new JButton("Show All Contacts");
removeContactButton = new JButton("Remove Contact");
removeAllContactsButton = new JButton("Remove All Contact");
exitButton = new JButton("Exit");
add(addContactButton);
add(searchContactButton);
add(showAllContactsButton);
add(removeContactButton);
add(removeAllContactsButton);
add(exitButton);
addContactButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evento) {
contextPaternComponent.setVisible(false);
new ContactBookAddContactUI(contextPaternComponent, contactBook);
}
});
searchContactButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evento) {
if (contactBook.isEmpty()) {
JOptionPane.showMessageDialog(contextPaternComponent, "Contact Book is empty");
return;
}
contextPaternComponent.setVisible(false);
new ContactBookSearchOrRemoveUI(contextPaternComponent, contactBook, "Search", "Select");
}
});
showAllContactsButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evento) {
if (contactBook.isEmpty()) {
JOptionPane.showMessageDialog(contextPaternComponent, "Contact Book is empty");
return;
}
contextPaternComponent.setVisible(false);
new ContactBookShowAllUI(contextPaternComponent, contactBook);
}
});
removeContactButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evento) {
if (contactBook.isEmpty()) {
JOptionPane.showMessageDialog(contextPaternComponent, "Contact Book is empty");
return;
}
contextPaternComponent.setVisible(false);
new ContactBookSearchOrRemoveUI(contextPaternComponent, contactBook, "Remove", "Select");
}
});
removeAllContactsButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evento) {
if (contactBook.isEmpty()) {
JOptionPane.showMessageDialog(contextPaternComponent, "Contact Book is empty");
return;
}
contactBook.removeAllContact();
JOptionPane.showMessageDialog(contextPaternComponent, "All contacts removed succesfully");
}
});
exitButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evento) {
JOptionPane.showMessageDialog(contextPaternComponent,
"will exit from the aplication(will lose all information)", "warning", JOptionPane.WARNING_MESSAGE);
System.exit(0);
}
});
this.setLocationRelativeTo(null);
this.setSize(200, 300);
this.setVisible(true);
}
}