-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathA02FrontEnd.java
More file actions
180 lines (155 loc) · 5.71 KB
/
A02FrontEnd.java
File metadata and controls
180 lines (155 loc) · 5.71 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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.text.*;
public class A02FrontEnd extends JFrame implements ItemListener, ActionListener{
/**
* The purpose of this class is to create the FrontEnd/GUI and provide listener functions.
* You cannot write/perform any database interaction functions/actions in this class.
* You can only invoke a suitable function from A02MiddleTier class on the click event of Submit button.
*/
JCheckBox eventConference;
JCheckBox eventJournal;
JCheckBox eventBook;
JRadioButton allDates;
JRadioButton dateRange;
ButtonGroup dateSelection;
JTextArea queryOutput;
JLabel fromLabel;
JLabel toLabel;
JTextField fromDate;
JTextField toDate;
JButton submitQuery;
public A02FrontEnd() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
this.setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
JLabel emptyLabel1 = new JLabel(" \n ");
JPanel emptyPanel1 = new JPanel(new GridLayout(0, 1));
emptyPanel1.add(emptyLabel1);
c.fill = GridBagConstraints.HORIZONTAL;
c.gridx = 0;
c.gridy = 0;
this.add(emptyPanel1, c);
eventConference = new JCheckBox("EventConference");
eventConference.setSelected(false);
eventJournal = new JCheckBox("EventJournal");
eventJournal.setSelected(false);
eventBook = new JCheckBox("EventBook");
eventBook.setSelected(false);
eventConference.addItemListener(this);
eventJournal.addItemListener(this);
eventBook.addItemListener(this);
JPanel eventPanel = new JPanel(new GridLayout(0, 1));
eventPanel.add(eventConference);
eventPanel.add(eventJournal);
eventPanel.add(eventBook);
c.fill = GridBagConstraints.HORIZONTAL;
c.gridx = 1;
c.gridy = 0;
this.add(eventPanel, c);
c.fill = GridBagConstraints.HORIZONTAL;
c.gridx = 2;
c.gridy = 0;
this.add(emptyPanel1, c);
allDates = new JRadioButton("All Events");
allDates.setSelected(true);
dateRange = new JRadioButton("Period");
dateRange.setSelected(false);
dateSelection = new ButtonGroup();
allDates.addItemListener(this);
dateRange.addItemListener(this);
dateSelection.add(allDates);
dateSelection.add(dateRange);
JPanel datePanel = new JPanel(new GridLayout(0, 1));
datePanel.add(allDates);
datePanel.add(dateRange);
fromLabel = new JLabel(" From ");
fromLabel.setEnabled(false);
toLabel = new JLabel(" To ");
toLabel.setEnabled(false);
fromDate = new JTextField();
fromDate.setEnabled(false);
toDate = new JTextField();
toDate.setEnabled(false);
JPanel dateRangePanel = new JPanel(new GridLayout(0, 4));
dateRangePanel.add(fromLabel);
dateRangePanel.add(fromDate);
dateRangePanel.add(toLabel);
dateRangePanel.add(toDate);
datePanel.add(dateRangePanel);
c.fill = GridBagConstraints.HORIZONTAL;
c.gridx = 7;
c.gridy = 0;
this.add(datePanel, c);
JLabel emptyLabel2 = new JLabel(" \n ");
JPanel emptyPanel2 = new JPanel(new GridLayout(0, 1));
emptyPanel2.add(emptyLabel2);
c.fill = GridBagConstraints.HORIZONTAL;
c.gridx = 3;
c.gridy = 1;
this.add(emptyPanel2, c);
submitQuery = new JButton("Submit");
submitQuery.addActionListener(this);
JPanel submitPanel = new JPanel(new GridLayout(0, 1));
submitPanel.add(submitQuery);
c.fill = GridBagConstraints.NONE;
c.anchor = GridBagConstraints.LINE_START;
c.gridx = 6;
c.gridy = 2;
this.add(submitPanel, c);
JLabel emptyLabel3 = new JLabel(" \n ");
JPanel emptyPanel3 = new JPanel(new GridLayout(0, 1));
emptyPanel3.add(emptyLabel3);
c.fill = GridBagConstraints.HORIZONTAL;
c.gridx = 5;
c.gridy = 3;
this.add(emptyPanel3, c);
queryOutput = new JTextArea(15,100);
queryOutput.setText("The\nQuery\nOutput\nwill\nAppear\nhere.");
JScrollPane outputPanel = new JScrollPane(queryOutput);
c.gridwidth = GridBagConstraints.REMAINDER;
c.fill = GridBagConstraints.BOTH;
c.gridx = 0;
c.gridy = 4;
this.add(outputPanel, c);
this.setBounds(50, 50, 1200, 500);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
//this function is the listener for three check boxes and two radio buttons
public void itemStateChanged(ItemEvent e) {
Object source = e.getItemSelectable();
if (source == eventConference) {
System.out.println("1");
} else if (source == eventJournal) {
System.out.println("2");
} else if (source == eventBook) {
System.out.println("3");
} else if (source == dateRange) {
if (dateRange.isSelected()) {
fromLabel.setEnabled(true);
toLabel.setEnabled(true);
fromDate.setEnabled(true);
toDate.setEnabled(true);
}
else {
fromLabel.setEnabled(false);
toLabel.setEnabled(false);
fromDate.setEnabled(false);
toDate.setEnabled(false);
}
System.out.println("4");
} else if (source == allDates) {
System.out.println("5");
}
}
/** Listens to the submit button click */
public void actionPerformed(ActionEvent e) {
queryOutput.setText(queryOutput.getText()+"\n"+fromDate.getText()+"\n"+toDate.getText());
}
}