-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddGuestDialog.java
More file actions
675 lines (589 loc) · 23.9 KB
/
AddGuestDialog.java
File metadata and controls
675 lines (589 loc) · 23.9 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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
/* * * * * * * * * * *\
* AddGuestDialog.java
* Description: Allows user to enter guest information and save it, used for checking in and editing guests.
* Will validate each field when user submits. This dialog also has the card swipe feature. Rather
* than the user typing in the student room# and name and the guests name they can simply
* use a swipe card machine along with the student and guests FSU or Pierpont card.
*
* Date: 5/7/16
* @author Brandon Ballard & Hanif Mirza
\* * * * * * * * * * */
import java.awt.event.*;
import static javax.swing.GroupLayout.Alignment.*;
import java.util.*;
import java.text.*;
import java.sql.*;
import java.awt.*;
import javax.swing.*;
import javax.swing.event.*;
import java.util.Date;
class AddGuestDialog extends JDialog implements ActionListener,DocumentListener, KeyListener
{
JPanel buttonPanel, fieldPanel;
JButton cancelButton, addButton;
JTextField studentRoomTF, guestNameTF, guestAgeTF;
JLabel studentRoomLabel, studentNameLabel, guestNameLabel, overnightLabel, guestAgeLabel, titleLabel, guestIDLabel;
JCheckBox overnightCB;
JScrollPane scrollPane;
JComboBox residentNameCBox,guestIDTypes;
DefaultGUI myDefaultGUI;
Statement myStatement;
String keyString, residentRoomNo, residentName, residentID, guestName, guestIDtype, guestAge, overnightStatus, currTime, currDate, myVisitationID;
DateFormat dateFormat, timeFormat;
Hashtable<String,Resident> residentHT;
int row, keyCount;
//CONSTRUCTOR FOR ADDING A GUEST BY BRANDON BALLARD
public AddGuestDialog(DefaultGUI urDefaultGUI,Hashtable<String,Resident> urHashtable,Statement urStatement)
{
keyString = "";
keyCount = 0;
this.myStatement = urStatement;
this.residentHT = urHashtable;
this.myDefaultGUI = urDefaultGUI;
this.row = row;
dateFormat = new SimpleDateFormat("M/d/yyyy");
timeFormat = new SimpleDateFormat("h:mma");
//________________________________________________________________Create buttons and button panel
addButton = new JButton("Add Guest");
addButton.setBackground(Color.WHITE);
addButton.addActionListener(this);
addButton.setActionCommand("ADD");
addButton.setEnabled(false);
cancelButton = new JButton("Cancel");
cancelButton.setBackground(Color.WHITE);
cancelButton.addActionListener(this);
cancelButton.setActionCommand("CANCEL");
buttonPanel = new JPanel(new FlowLayout());
buttonPanel.setBackground(Color.GRAY);
buttonPanel.add(cancelButton);
buttonPanel.add(addButton);
//________________________________________________________________Add text fields for user input
fieldPanel = setFields();
studentRoomTF.getDocument().addDocumentListener(this);
guestNameTF.getDocument().addDocumentListener(this);
guestAgeTF.getDocument().addDocumentListener(this);
//________________________________________________________________Add components to container
getContentPane().add(fieldPanel, BorderLayout.CENTER);
getContentPane().add(buttonPanel, BorderLayout.SOUTH);
setupMainFrame();
}
//CONSTRUSTOR FOR EDITING A GUEST BY BRANDON BALLARD
public AddGuestDialog(DefaultGUI urDefaultGUI,Hashtable<String,Resident> urHashtable,Statement urStatement,String urVisitationID , int row)
{
keyString = "";
keyCount = 0;
this.myStatement = urStatement;
this.residentHT = urHashtable;
this.myDefaultGUI = urDefaultGUI;
this.myVisitationID = urVisitationID;
this.row = row;
dateFormat = new SimpleDateFormat("M/d/yyyy");
timeFormat = new SimpleDateFormat("h:mma");
//________________________________________________________________Create buttons and button panel
addButton = new JButton("Update Guest");
addButton.setBackground(Color.WHITE);
addButton.addActionListener(this);
addButton.setActionCommand("UPDATE");
getRootPane().setDefaultButton(addButton);
cancelButton = new JButton("Cancel");
cancelButton.setBackground(Color.WHITE);
cancelButton.addActionListener(this);
cancelButton.setActionCommand("CANCEL");
buttonPanel = new JPanel(new FlowLayout());
buttonPanel.setBackground(Color.GRAY);
buttonPanel.add(cancelButton);
buttonPanel.add(addButton);
//________________________________________________________________Add text fields for user input
fieldPanel = setFields();
//________________________________________________________________Populate text fields with selected accounts info
populateAllFields();
studentRoomTF.getDocument().addDocumentListener(this);
guestNameTF.getDocument().addDocumentListener(this);
guestAgeTF.getDocument().addDocumentListener(this);
//________________________________________________________________Add components to container
getContentPane().add(fieldPanel, BorderLayout.CENTER);
getContentPane().add(buttonPanel, BorderLayout.SOUTH);
setupMainFrame();
setTitle("Edit Guest");
}
//Written by Hanif Mirza, This function will use the information selected on table in DefaultGUI.java to populate text fields with guest info
void populateAllFields()
{
studentRoomTF.setText( myDefaultGUI.tableModel.getValueAt(row,5).toString() );
guestNameTF.setText( myDefaultGUI.tableModel.getValueAt(row,1).toString() );
guestAgeTF.setText( myDefaultGUI.tableModel.getValueAt(row,2).toString() );
guestIDTypes.setSelectedItem( myDefaultGUI.tableModel.getValueAt(row,3).toString() );
String overnightStatus = myDefaultGUI.tableModel.getValueAt(row,8).toString();
residentNameCBox.removeAllItems(); // remove all previous items from the combo box
residentNameCBox.addItem( myDefaultGUI.tableModel.getValueAt(row,4).toString() );
if ( overnightStatus.equals("No") )
{
overnightCB.setSelected(false);
}
else
{
overnightCB.setSelected(true);
}
}
//BY BRANDON BALLARD
public void actionPerformed(ActionEvent e)
{
if(e.getActionCommand().equals("ADD"))
{
doAddGuest();
}
else if(e.getActionCommand().equals("UPDATE"))
{
doUpdateGuest();
}
else if(e.getActionCommand().equals("CANCEL"))
{
this.dispose();
}
}
// Written by Hanif Mirza, This function update the information of currently checked-in guest
void doUpdateGuest()
{
try
{
validateFields();
Resident myResident = residentHT.get(residentRoomNo); // get the Resident object from resident's room number
String residentID = findKey(residentName,myResident.residentHashtable);//get resident ID (the key) from resident name (the value)
// database statement to update the check-out details
String sql = "UPDATE Visitation_Detail "
+ "SET guest_name = "+ "'"+guestName+"'" +","+ "guest_age = "+ guestAge +","
+ "guest_ID_type = "+ "'"+guestIDtype+"'" +","+ "overnight_status = "+ "'"+overnightStatus+"'" +","
+ "empID = "+ "'"+myDefaultGUI.userID+"'" +","+ "residentID = "+ "'"+residentID+"'"
+ " Where visitationID = "+ myVisitationID;
int confirmationNo = myStatement.executeUpdate(sql);
myDefaultGUI.tableModel.setValueAt(guestName, row,1);
myDefaultGUI.tableModel.setValueAt(guestAge, row,2);
myDefaultGUI.tableModel.setValueAt(guestIDtype, row,3);
myDefaultGUI.tableModel.setValueAt(residentName, row,4);
myDefaultGUI.tableModel.setValueAt(residentRoomNo, row,5);
myDefaultGUI.tableModel.setValueAt(overnightStatus, row,8);
myDefaultGUI.tableModel.setValueAt(myDefaultGUI.myFullName, row,9);
if( confirmationNo > 0)
{
this.dispose();
JOptionPane.showMessageDialog(this,"Guest has been updated", "Update successful" , JOptionPane.INFORMATION_MESSAGE );
}
}
catch(MyException myEx)
{
JOptionPane.showMessageDialog(this,myEx.getMessage());
}
catch ( SQLException sqlException )
{
JOptionPane.showMessageDialog(this, sqlException.getMessage());
}
catch ( Exception exception )
{
JOptionPane.showMessageDialog(this, exception.getMessage());
}
}
// Written by Hanif Mirza, this function will add the checked-in details of new guest to the database and also add it to the DefaultGUI table
void doAddGuest()
{
try
{
validateFields();
Resident myResident = residentHT.get(residentRoomNo); // get the Resident object from resident's room number
String residentID = findKey(residentName,myResident.residentHashtable);//get resident ID (the key) from resident name (the value)
// database statement to insert the check-in details
String sql = "INSERT INTO Visitation_Detail(guest_name,guest_age,guest_ID_type,visitation_date,time_in,overnight_status,empID,residentID)"
+ " VALUES ("+ "'"+guestName+"'" +","+ guestAge +","+ "'"+guestIDtype+"'" +","+ "CURDATE(),curtime(),"+ "'"+overnightStatus+"'" +","
+ "'"+myDefaultGUI.userID+"'" +","+ "'"+residentID+"'" +")";
int confirmationNo = myStatement.executeUpdate(sql,Statement.RETURN_GENERATED_KEYS);
ResultSet rs = myStatement.getGeneratedKeys(); // the Auto Generated Primary Key, which is visitation details ID
int visitationID = 0;
if (rs.next())
{
visitationID = rs.getInt(1);
}
rs.close();
Vector<Object> currentRow = new Vector<Object>();
currentRow.addElement(visitationID);
currentRow.addElement(guestName);
currentRow.addElement(guestAge);
currentRow.addElement(guestIDtype);
currentRow.addElement(residentName);
currentRow.addElement(residentRoomNo);
currentRow.addElement(currDate);
currentRow.addElement(currTime);
currentRow.addElement(overnightStatus);
currentRow.addElement(myDefaultGUI.myFullName);
myDefaultGUI.tableModel.addRow(currentRow); // add the new check-out details to out table
if( confirmationNo > 0)
{
this.dispose();
JOptionPane.showMessageDialog(this, guestName + " is checked in", "Check in successful" , JOptionPane.INFORMATION_MESSAGE);
}
}
catch(MyException myEx)
{
JOptionPane.showMessageDialog(this,myEx.getMessage(), "Warning ",JOptionPane.WARNING_MESSAGE);
}
catch ( SQLException sqlException )
{
JOptionPane.showMessageDialog(this, sqlException.getMessage());
}
catch ( Exception exception )
{
JOptionPane.showMessageDialog(this, exception.getMessage());
}
}
// Written by Hanif Mirza, this function will validate all the fields, if any field is invalid then it will through an exception
void validateFields() throws Exception
{
residentRoomNo = studentRoomTF.getText().trim();
residentName = residentNameCBox.getSelectedItem().toString();
guestIDtype = guestIDTypes.getSelectedItem().toString();
guestName = guestNameTF.getText().trim();
guestName = guestName.replaceAll("'", "\\\\'");
guestAge = guestAgeTF.getText().trim();
currDate = dateFormat.format(new Date());
currTime = timeFormat.format(new Date());
if(overnightCB.isSelected())
{
overnightStatus = "Yes";
}
else
{
overnightStatus = "No";
}
if (!Validate.validateNumber(residentRoomNo))
{
throw new MyException("Invalid room number");
}
else if (residentName.equals("-Select-"))
{
throw new MyException("Please select a student name");
}
else if (!Validate.validateFullName(guestName))
{
throw new MyException("Please enter first and last name of guest" + "\n" + "No special characters allowed (1@#$%&*)");
}
else if(checkIfValuesExist("Banned_Guest","guest_name",guestName))
{
throw new MyException(guestName+" has been banned from this location" + "\n" + "Please call campus police and notify RA");
}
else if (!Validate.validateNumber(guestAge))
{
throw new MyException("Invalid age");
}
else if (guestIDtype.equals("-Select-"))
{
throw new MyException("Please select an ID type");
}
else if (Validate.validateNumber(guestAge))
{
if (Integer.parseInt(guestAge) < 18)
{
JOptionPane.showMessageDialog(this,"Warning: This guest is under 18 years old, parental consent must be provided");
}
}
}
// Written by Hanif Mirza, this function will find resident ID (the key) using the resident full name (the value) from the hashtable
public String findKey(String value, Hashtable HT)
{
String myKey = "";
Set<String> keys = HT.keySet();
for(String key: keys)
{
if (HT.get(key).equals(value))
{
myKey = key;
}
}
return myKey;
}
// Written by Hanif Mirza,this function will return true if values exist in specific column of a database table
boolean checkIfValuesExist(String tableName,String columnName,String columnValue) throws Exception
{
String SQL_Query = "Select * "+"From "+tableName+" WHERE "+columnName+" LIKE "+ "'"+columnValue+"'";
ResultSet resultSet = myStatement.executeQuery(SQL_Query);// query database
if(!resultSet.next())
{
resultSet.close();
return false; // values don't exist, so return false
}
else
{
resultSet.close();
return true; // values exist, so return true
}
}
public void insertUpdate(DocumentEvent de)
{
residentRoomNo = studentRoomTF.getText().trim();
residentName = residentNameCBox.getSelectedItem().toString();
guestIDtype = guestIDTypes.getSelectedItem().toString();
guestName = guestNameTF.getText().trim();
guestAge = guestAgeTF.getText().trim();
// check if the users insert room number on studentRoomTF
if (de.getDocument() == studentRoomTF.getDocument() )
{
residentNameCBox.removeAllItems();
DefaultComboBoxModel model = new DefaultComboBoxModel();
model.addElement( "-Select-" );
if (residentHT.containsKey(residentRoomNo))
{
Resident myResident = residentHT.get(residentRoomNo); // get the resident object using the room number (key)
Set<String> keys = myResident.residentHashtable.keySet();
for(String key: keys)
{
String residentName = myResident.residentHashtable.get(key); //get the resident full name from the resident ID (key)
model.addElement( residentName );
}
}
residentNameCBox.setModel(model);
}
if( residentRoomNo.equals("") || guestName.equals("") || guestAge.equals("") )
{
addButton.setEnabled(false);
}
else
{
addButton.setEnabled(true);
}
}
public void changedUpdate(DocumentEvent de){}
public void removeUpdate(DocumentEvent de)
{
residentRoomNo = studentRoomTF.getText().trim();
residentName = residentNameCBox.getSelectedItem().toString();
guestIDtype = guestIDTypes.getSelectedItem().toString();
guestName = guestNameTF.getText().trim();
guestAge = guestAgeTF.getText().trim();
// check if the users insert room number on studentRoomTF
if (de.getDocument() == studentRoomTF.getDocument() )
{
residentNameCBox.removeAllItems();
DefaultComboBoxModel model = new DefaultComboBoxModel();
model.addElement( "-Select-" );
if ( residentHT.containsKey(residentRoomNo) )
{
Resident myResident = residentHT.get(residentRoomNo); // get the resident object using the room number (key)
Set<String> keys = myResident.residentHashtable.keySet();
for(String key: keys)
{
String residentName = myResident.residentHashtable.get(key);//get the resident full name from the resident ID (key)
model.addElement( residentName );
}
}
residentNameCBox.setModel(model);
}
if( residentRoomNo.equals("") || guestName.equals("") || guestAge.equals(""))
{
addButton.setEnabled(false);
}
else
{
addButton.setEnabled(true);
}
}
public void keyReleased(KeyEvent ke)
{
}
public void keyPressed(KeyEvent ke)
{
}
//BY BRANDON BALLARD, this function will detect when a user swipes a card in the appropriate text field.
public void keyTyped(KeyEvent ke)
{
//All cards start with a '%', so if the function detects a '%' and it hasn't previously detected one or if keyString
//starts with a '%', then the function adds the text to keyString and moves on to the if statement.
if((Character.toString(ke.getKeyChar()).equals("%") && keyCount == 0) || keyString.startsWith("%"))
{
keyCount++;
keyString = keyString + Character.toString(ke.getKeyChar());
//This if statemnt checks to see if keySting contains everything it needs to be considered a card. All cards end in
//'%HH' so it first checks for that and then makes sure the string is at least 20 characers long, if it is then it
//makes sure that the string contains at leat one '^' and at least one '?', if everything is good then the function
//recognizes the string as a card swipe and moves on to the for loop.
if(keyString.endsWith("%HH") && keyCount > 20 && keyString.contains("^") && keyString.contains("?"))
{
int y = 0;
keyCount = 0;
//this for loop starts at the end of keyString and backs up until it finds two '%' symbols, if it successfully
//found two then the function confirms that the user has swiped a card and proceeds.
for(int x = keyString.length() - 1; x >= 0; x--)
{
if(Character.toString(keyString.charAt(x)).equals("%"))
{
y++;
//After a card swipe is detected the function checks to see which text field the swipe took place in
//and calls the appropriate function.
if(y == 2)
{
residentRoomNo = keyString.substring(x);
if(this.getFocusOwner() == studentRoomTF)
{
processCardSwipe();
}
else if(this.getFocusOwner() == guestNameTF)
{
processGuestCardSwipe();
}
else if(this.getFocusOwner() == guestAgeTF)
{
JOptionPane.showMessageDialog(null, "Could not read card \n Please enter guest age manually", "Error" , JOptionPane.ERROR_MESSAGE);
guestAgeTF.setText("");
}
keyString = "";
x = -1;
}
}
}
}
}
}
/* Written by Hanif Mirza. This function will process the resident's card swipe. It will parse the resident card ID
and access the database with that card ID to get all information of the resident. If it's valid resident then
it will populate all the fields of the resident. All this sequence of code must be done in a thread. */
void processCardSwipe()
{
SwingUtilities.invokeLater(new Runnable() {
public void run()
{
String studentID = residentRoomNo.substring(residentRoomNo.indexOf("B")+1 , residentRoomNo.indexOf("^"));
studentRoomTF.setText("");
try
{
String SQL_Query = "SELECT CONCAT(r.first_name,\" \",r.last_name),r.room_number FROM Resident r WHERE r.userID = " + studentID ;
ResultSet rs = myStatement.executeQuery(SQL_Query);// Query to get the lockout number of the resident
if(!rs.next())
{
//show Joptionpane if result set is empty
JOptionPane.showMessageDialog(null,"Resident could not be found", "Error" , JOptionPane.ERROR_MESSAGE );
studentRoomTF.requestFocus();
}
else
{
rs.first();//move ResultSet cursor to previous row
String resName = rs.getString(1);
residentRoomNo = rs.getInt(2)+"";
studentRoomTF.setText(residentRoomNo);
residentNameCBox.removeAllItems(); // remove all previous items from the combo box
DefaultComboBoxModel model = new DefaultComboBoxModel();
model.addElement( resName );
residentNameCBox.setModel(model);
guestNameTF.requestFocus();
}
rs.close();
}
catch ( SQLException sqlException )
{
JOptionPane.showMessageDialog(null, "Resident could not be found", "Error" , JOptionPane.ERROR_MESSAGE );
studentRoomTF.setText(residentRoomNo);
}
catch ( Exception exception )
{
JOptionPane.showMessageDialog(null, exception.getMessage(), "Error" , JOptionPane.ERROR_MESSAGE );
studentRoomTF.setText(residentRoomNo);
}
}
});
}
/* Written by Hanif Mirza. This function will process the guest's card swipe. It will parse the guest name from the guest ID and
set it to the guestNameTF. All this sequence of code must be done in a thread. */
void processGuestCardSwipe()
{
SwingUtilities.invokeLater(new Runnable() {
public void run()
{
try
{
String studentID = guestName.substring(guestName.indexOf("B")+1 , guestName.indexOf("^"));
guestName = guestName.substring(guestName.indexOf("^")+1);
String lastName = guestName.substring(0,guestName.indexOf("/")).trim();
String part1 = lastName.substring(0,1);
String part2 = lastName.substring(1).toLowerCase();
lastName = part1 + part2; // First letter of last name is uppercase and rest of it are lower case
String firstName = guestName.substring(guestName.indexOf("/")+1,guestName.indexOf("^")).trim();
if(firstName.split(" ").length > 1)
{
firstName = firstName.split(" ")[0];
}
String firstPart = firstName.substring(0,1);
String secPart = firstName.substring(1).toLowerCase();
firstName = firstPart + secPart; // First letter of first name is uppercase and rest of it are lower case
guestNameTF.setText(firstName +" "+lastName);
guestAgeTF.requestFocus();
}
catch(Exception e)
{
guestNameTF.setText("");
JOptionPane.showMessageDialog(null, "Could not read card \n Please enter geust name manually", "Error" , JOptionPane.ERROR_MESSAGE);
guestNameTF.requestFocus();
}
}
});
}
//BY BRANDON BALLARD, adds fields using a group layout
JPanel setFields()
{
GroupLayout layout;
JPanel p;
studentRoomLabel = new JLabel("Room Number:");
studentRoomLabel.setForeground(Color.WHITE);
studentNameLabel = new JLabel("Student Name:");
studentNameLabel.setForeground(Color.WHITE);
guestNameLabel = new JLabel("Guest Name:");
guestNameLabel.setForeground(Color.WHITE);
guestAgeLabel = new JLabel("Guest Age:");
guestAgeLabel.setForeground(Color.WHITE);
overnightLabel = new JLabel("Overnight:");
overnightLabel.setForeground(Color.WHITE);
guestIDLabel = new JLabel("ID Type:");
guestIDLabel.setForeground(Color.WHITE);
studentRoomTF = new JTextField(30);
studentRoomTF.addKeyListener(this);
guestNameTF = new JTextField();
guestNameTF.addKeyListener(this);
guestAgeTF = new JTextField();
guestAgeTF.addKeyListener(this);
residentNameCBox = new JComboBox();
residentNameCBox.addItem("-Select-");
residentNameCBox.addActionListener(this);
String[] comboTypes = { "-Select-","FSU", "PCTC", "DL","Other" };
guestIDTypes = new JComboBox<>(comboTypes);
guestIDTypes.addActionListener(this);
overnightCB = new JCheckBox();
overnightCB.setBackground(new Color(1, 0.1f, 0.1f).darker().darker());
p = new JPanel();
p.setBackground(new Color(1, 0.1f, 0.1f).darker().darker());
layout = new GroupLayout(p);
p.setLayout(layout);
layout.setAutoCreateGaps(true);
layout.setAutoCreateContainerGaps(true);
GroupLayout.SequentialGroup hGroup = layout.createSequentialGroup();
hGroup.addGroup(layout.createParallelGroup().addComponent(studentNameLabel).addComponent(studentRoomLabel).addComponent(guestNameLabel).addComponent(guestAgeLabel).addComponent(guestIDLabel).addComponent(overnightLabel));
hGroup.addGroup(layout.createParallelGroup().addComponent(residentNameCBox).addComponent(studentRoomTF).addComponent(guestNameTF).addComponent(guestAgeTF).addComponent(guestIDTypes).addComponent(overnightCB));
layout.setHorizontalGroup(hGroup);
GroupLayout.SequentialGroup vGroup = layout.createSequentialGroup();
vGroup.addGroup(layout.createParallelGroup(BASELINE).addComponent(studentRoomLabel).addComponent(studentRoomTF));
vGroup.addGroup(layout.createParallelGroup(BASELINE).addComponent(studentNameLabel).addComponent(residentNameCBox));
vGroup.addGroup(layout.createParallelGroup(BASELINE).addComponent(guestNameLabel).addComponent(guestNameTF));
vGroup.addGroup(layout.createParallelGroup(BASELINE).addComponent(guestAgeLabel).addComponent(guestAgeTF));
vGroup.addGroup(layout.createParallelGroup(BASELINE).addComponent(guestIDLabel).addComponent(guestIDTypes));
vGroup.addGroup(layout.createParallelGroup(BASELINE).addComponent(overnightLabel).addComponent(overnightCB));
layout.setVerticalGroup(vGroup);
return(p);
}
void setupMainFrame()
{
Dimension d;
Toolkit tk;
tk = Toolkit.getDefaultToolkit();
d = tk.getScreenSize();
setTitle("Add Guest");
setSize(d.width/3, d.height/3);
setSize(d.width/3, 270);
setLocation(d.width/3, d.height/4 + d.height/20);
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
setModalityType(Dialog.ModalityType.APPLICATION_MODAL);
setVisible(true);
}
}