-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLibrarianGUI.java
More file actions
136 lines (102 loc) · 4.13 KB
/
Copy pathLibrarianGUI.java
File metadata and controls
136 lines (102 loc) · 4.13 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
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package lms;
import java.awt.Button;
import java.awt.Color;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
public class LibrarianGUI implements ActionListener {
private static String selectedOption = "Add Book to Database"; // default value
public LibrarianGUI(){
JFrame librarianWindow = new JFrame();
JPanel librarianContents = new JPanel();
//librarianContents.setBackground(Color.WHITE);
GridLayout pageLayout = new GridLayout(4,1,10,0);
librarianContents.setLayout(pageLayout);
JLabel header = new JLabel("Librarian Main Page");
header.setFont(new Font("Arial", Font.BOLD, 15));
header.setHorizontalAlignment(SwingConstants.CENTER);
header.setForeground(Color.black);
librarianContents.add(header);
JLabel instructions = new JLabel("Select an Action...");
instructions.setHorizontalAlignment(SwingConstants.CENTER);
librarianContents.add(instructions);
// create options
String[] options = {"Add Book to Database",
"Add Patron to Database",
"Get list of holds",
"Get list of Checkouts",
"Get list of overdue Books"};
JComboBox librarianDropDown = new JComboBox(options);
librarianDropDown.setSelectedIndex(0);
// from https://www.javatpoint.com/java-actionlistener -> anonymous class
librarianDropDown.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
// set value of selectedOption
// https://stackoverflow.com/questions/4962416/preferred-way-of-getting-the-selected-item-of-a-jcombobox
selectedOption = String.valueOf(librarianDropDown.getSelectedItem());
}
});
librarianContents.add(librarianDropDown);
Button goButton = new Button("GO!");
goButton.setActionCommand("go");
goButton.addActionListener(this);
JPanel bottomContents = new JPanel();
bottomContents.setLayout(new GridLayout(1,5));
bottomContents.add(new JLabel()); // place holder
bottomContents.add(new JLabel()); // place holder
bottomContents.add(goButton);
bottomContents.add(new JLabel()); // place holder
bottomContents.add(new JLabel()); // place holder
librarianContents.add(bottomContents);
librarianWindow.add(librarianContents);
// call method to display Welcome Window
//librarianWindow.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
//librarianWindow.setPreferredSize(new Dimension(400, 300));
librarianWindow.pack();
librarianWindow.setLocationRelativeTo(null);
librarianWindow.setTitle("Librarians - Main Page");
librarianWindow.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
//prints option selected
Connection connection = DatabaseConnection.openDatabase();
// actions based on selection
switch (selectedOption) {
case "Add Book to Database":
new AddBookGUI();
//WINDOW, drop-down list (keyword = type of search), 1 entry field, search button -> call the printFromDatabase/printResultSetinWindow methods / see all books button -> getAllBooks
break;
case "Add Patron to Database":
new CreatePatronGUI();
break;
case "Get list of holds":
//Open a window of all holds
new holdsFilter();
Librarian.getHoldsList(connection, "holdsview");
// Window of potential filter fields
break;
case "Get list of Checkouts":
//Open a window of all holds
new checkOutFilter();
Librarian.getCheckOutsList(connection, "checkoutsview");
// Window of potential filter fields
break;
case "Get list of overdue Books":
//Open a window of all holds
new overdueFilter();
Librarian.getOverdueList(connection, "checkoutsview");
// Window of potential filter fields
break;
}
DatabaseConnection.closeDatabase(connection);
}
}