import java.awt.Color;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.BorderFactory;import javax.swing.JOptionPane;/**
* Description : this is the main method and can store the information that
* entered from the MyFrame
*
* @author Yuxiong Wang
* @version 1.0
*
*/publicclassCheckInimplementsActionListener{/** The main frame that let user enter information */
MyFrame myFrame;/** String array to store the information */
String[] info;/**
* Program entrance. Create variable myProg and use method runProg() to run the
* Program
*
* @param args no use in this program
*/publicstaticvoidmain(String[] args){
CheckIn myProg =newCheckIn();
myProg.runProg();}/**
* Create user interface and add action listener to 'Next step'.<br>
* <p>
* MyFrame for the first stage user interface<br>
* Use the String array 'info' to store user information.<br>
* <p>
* Add action listener to 'Next step'.
*/publicvoidrunProg(){
myFrame =newMyFrame();
info =newString[7];
myFrame.button1.addActionListener(this);}/**
* Handle the click event.<br>
* <p>
* When the user clicks on the "Next step" button, this program will check the
* information wether all entered.<br>
* If not all information are completed, this program will not proceed to the
* check in completion stage and an error dialog box will display prompting the
* user to complete the missing information.<br>
* At the same time, the incomplete session is highlighted in red so that user
* can easily check the missing information to be completed.<br>
* If all the information are completed by the user, this program will pop-up a
* dialog box to confirm with the user for the final confirmation before the
* check in process is completed. And, if user clicks "Yes", this program will
* proceed to the check in completion stage which will close the "Workshop Check
* In" window and open the "Check in complete!" window, if user clicks "No",
* this program will go back and the information entered will still here for
* user to perfect.<br>
*
* @param e the event happened
*/publicvoidactionPerformed(ActionEvent e){int guarantee =1;// the guarantee = 1 means that all the information have been filled/*
* if the user didn't fill/select in the First name, then highlight the
* textfield and set guarantee =0 if the user have filled/selected in the first
* name, store it in the array info and cancel the red border(if it exists)
*/if(myFrame.textField1.getText().equals("")){
myFrame.textField1.setBorder(
BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.RED,2),"First Name"));
guarantee =0;}else{
info[0]= myFrame.textField1.getText()+" ";
myFrame.textField1.setBorder(
BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.GRAY),"First Name"));}if(myFrame.textField2.getText().equals("")){
myFrame.textField2.setBorder(
BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.RED,2),"Surname"));
guarantee =0;}else{
info[0]= info[0]+ myFrame.textField2.getText();
myFrame.textField2
.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.GRAY),"Surname"));}if(myFrame.textField3.getText().equals("")){
myFrame.textField3
.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.RED,2),"Email"));
guarantee =0;}else{
info[3]= myFrame.textField3.getText();
myFrame.textField3.setBorder(null);}if(myFrame.textField4.getText().equals("")){
myFrame.textField4.setBorder(
BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.RED,2),"Phone number"));
guarantee =0;}else{
info[4]= myFrame.textField4.getText();
myFrame.textField4.setBorder(null);}if(myFrame.textField5.getText().equals("")){
myFrame.textField5.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.RED,2),"Booking reference code"));
guarantee =0;}/*
* if the user have filled in the Booking reference code, store it in the array
* info and cancel the red border(if it exists)
*/else{
myFrame.textField5.setBorder(null);
info[6]= myFrame.textField4.getText();}if(myFrame.comboBox1.getSelectedItem().toString()==""){
myFrame.comboBox1
.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.RED,2),"Month"));
guarantee =0;}else{
info[1]= myFrame.comboBox1.getSelectedItem().toString()+" ";
myFrame.comboBox1.setBorder(null);}/*
* if the user didn't select Year, then highlight the textfield and set
* guarantee =0
*/if(myFrame.comboBox2.getSelectedItem().toString()==""){
myFrame.comboBox2
.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.RED,2),"Year"));
guarantee =0;}else{
info[1]= info[1]+ myFrame.comboBox2.getSelectedItem().toString();
myFrame.comboBox2.setBorder(null);}if(myFrame.comboBox3.getSelectedItem().toString()==""){
myFrame.comboBox3.setBorder(
BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.RED,2),"Programme"));
guarantee =0;}else{
info[2]= myFrame.comboBox3.getSelectedItem().toString()+", Year ";
myFrame.comboBox3.setBorder(null);}if(myFrame.comboBox4.getSelectedItem().toString()==""){
myFrame.comboBox4
.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.RED,2),"Year"));
guarantee =0;}else{
info[2]= info[2]+ myFrame.comboBox4.getSelectedItem().toString();
myFrame.comboBox4.setBorder(null);}if(!myFrame.checkBox1.isSelected()){
myFrame.checkBox1.setBorderPainted(true);
myFrame.checkBox1.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.RED,2)));
guarantee =0;}else{
myFrame.checkBox1.setBorder(null);}if(!myFrame.checkBox2.isSelected()){
myFrame.checkBox2.setBorderPainted(true);
myFrame.checkBox2.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.RED,2)));
guarantee =0;}else{
myFrame.checkBox2.setBorder(null);}if(guarantee ==0){
JOptionPane.showMessageDialog(myFrame,"Please fill in the missing information","Missing information",
JOptionPane.ERROR_MESSAGE);}elseif(guarantee ==1)// if all the information have been filled{// Pop the confirmation window lets the user confirm whether to proceedint n = JOptionPane.showConfirmDialog(myFrame,"Hava you checked all the information is correct? You can't change the information once the information is submitted.?","Confirm check in?", JOptionPane.YES_NO_OPTION);// if the user clicked the yes then new the anotherFrameif(n == JOptionPane.YES_OPTION){
AnotherFrame anotherFrame =newAnotherFrame(info);}}}}
import java.awt.BorderLayout;import java.awt.Color;import java.awt.Font;import java.awt.GridLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.BorderFactory;import javax.swing.JButton;import javax.swing.JCheckBox;import javax.swing.JComboBox;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JTextField;import javax.swing.border.EtchedBorder;/**
* Description : This class defines the main frame
*
* @author Yuxiong Wang
* @version 1.0
*
*/publicclassMyFrameextendsJFrameimplementsActionListener{/**
* The panel for the rows.
*/
JPanel panel1, panel2, panel3, panel4, panel5, panel6, panel7, panel8, panel9;/**
* TextField for user to input
*/
JTextField textField1, textField2, textField3, textField4, textField5;/** First grid in the bus-panel */
JLabel label1;/** Drop-down list for user to select */
JComboBox comboBox1, comboBox2, comboBox3, comboBox4;/** Check box for user to select */
JCheckBox checkBox1, checkBox2;/** Buttons for user to click */
JButton button1, button2, button3;/**
* Class constructor.<br>
*
* Create every thing in the "Workshop Check In" window
*/publicMyFrame(){// create the panels
panel1 =newJPanel(newBorderLayout());
panel2 =newJPanel();
panel3 =newJPanel();
panel4 =newJPanel();
panel5 =newJPanel();
panel6 =newJPanel();
panel7 =newJPanel();
panel8 =newJPanel();
panel9 =newJPanel();// create the label and set the font
label1 =newJLabel("Please complete the information below:", JLabel.CENTER);
Font font =newFont(null, Font.PLAIN,20);
label1.setFont(font);// create the textfield and set the border
textField1 =newJTextField(10);
textField2 =newJTextField(10);
textField3 =newJTextField(20);
textField3.setBorder(BorderFactory.createBevelBorder(EtchedBorder.LOWERED));
textField4 =newJTextField(20);
textField4.setBorder(BorderFactory.createBevelBorder(EtchedBorder.LOWERED));
textField5 =newJTextField(6);
textField5.setBorder(BorderFactory.createBevelBorder(EtchedBorder.LOWERED));// add the information in the list to a String respectively
String s1[]={"","January","Febuary","March","April","May","June","Junary","Auguet","Septemper","October","November","December"};
String s2[]={"","1998","1999","2000","2001","2002","2003","2004","2005"};
String s3[]={"","Telecommunications Engineering with Management","Internet of Things Engineering","E-commerce and Law",};
String s4[]={"","1","2","3","4"};// create the comboBox and set the border
comboBox1 =newJComboBox<String>(s1);
comboBox2 =newJComboBox<String>(s2);
comboBox3 =newJComboBox<String>(s3);
comboBox3.setBorder(BorderFactory.createBevelBorder(EtchedBorder.LOWERED));
comboBox4 =newJComboBox<String>(s4);
comboBox4.setBorder(BorderFactory.createBevelBorder(EtchedBorder.LOWERED));// create the buttons
button1 =newJButton("Next step");
button2 =newJButton("Clear");
button3 =newJButton("Exit");// listening register
button1.addActionListener(this);
button2.addActionListener(this);
button3.addActionListener(this);// set action command
button1.setActionCommand("Next step");
button2.setActionCommand("Clear");
button3.setActionCommand("Exit");// create the checkBox
checkBox1 =newJCheckBox("I have read and agree to the terms and conditions");
checkBox2 =newJCheckBox("I confirm that the information provided is correct");// add border to the textfields:
textField1
.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.GRAY),"First Name"));
textField2.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.GRAY),"Surname"));// add borders to the panels:
panel2.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.GRAY),"Name"));
panel3.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.GRAY),"Date of Birth"));
panel4.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.GRAY),"Programme"));
panel5.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.GRAY),"Email"));
panel6.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.GRAY),"Phone number"));
panel7.setBorder(
BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.GRAY),"Booking reference code"));
panel8.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.GRAY)));
panel9.setBorder(BorderFactory.createBevelBorder(EtchedBorder.LOWERED));// add the components to the panels// panel1
panel1.add(label1, BorderLayout.CENTER);// panel2
panel2.add(textField1);
panel2.add(textField2);// panel3
panel3.add(comboBox1);
panel3.add(comboBox2);// panel4
panel4.add(comboBox3);
panel4.add(comboBox4);// panel5
panel5.add(textField3);// panel6
panel6.add(textField4);// panel7
panel7.add(textField5);// panel8
panel8.add(checkBox1);
panel8.add(checkBox2);// panel9
panel9.add(button1);
panel9.add(button2);
panel9.add(button3);// add the panels to the frame:this.add(panel1);this.add(panel2);this.add(panel3);this.add(panel4);this.add(panel5);this.add(panel6);this.add(panel7);this.add(panel8);this.add(panel9);// set the layout of the framethis.setLayout(newGridLayout(9,1));this.setTitle("Workshop Check In");// the settings of framethis.setSize(500,800);this.setVisible(true);this.setDefaultCloseOperation(EXIT_ON_CLOSE);this.setResizable(false);}/**
* Handle the click event.<br>
* When the user clicks on the "Clear" button, this program will erase the
* entered information and if there have box is highlighted in red, it will
* remove the red highlight to go back to original state.<br>
* <p>
* When the user clicks on the "Exit" button, this program will exit.<br>
*
* @param e the event happened
*/@OverridepublicvoidactionPerformed(ActionEvent e){// make the programe exitif(e.getActionCommand().equals("Exit")){
System.exit(0);}if(e.getActionCommand().equals("Clear")){// clear the textfield
textField1.setText("");
textField2.setText("");
textField3.setText("");
textField4.setText("");
textField5.setText("");// set the combobox to null
comboBox1.setSelectedIndex(0);
comboBox2.setSelectedIndex(0);
comboBox3.setSelectedIndex(0);
comboBox4.setSelectedIndex(0);// erase the red border
textField1.setBorder(
BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.GRAY),"First Name"));
textField2
.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.GRAY),"Surname"));
textField3.setBorder(null);
textField4.setBorder(null);
textField5.setBorder(null);
comboBox1.setBorder(null);
comboBox2.setBorder(null);
comboBox3.setBorder(null);
comboBox4.setBorder(null);
checkBox1.setBorder(null);
checkBox2.setBorder(null);}}}
/**
*
* Description : This class defines the frame used for showing information.
* Copyright(c) 2021
*
* @author Yuxiong Wang
* @version 1.0
*/import java.awt.BorderLayout;import java.awt.Font;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.BorderFactory;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JTextArea;import javax.swing.border.EtchedBorder;publicclassAnotherFrameextendsJFrameimplementsActionListener{/** The panel in the frame */
JPanel panel1, panel2, panel3;/** The label in the first line. */
JLabel label;/** The 'Finish' button. */
JButton button;/** The board to show user's information. */
JTextArea textArea;/**
* Class constructor.<br>
* To initialize the AnotherFrame class
*
* @param info the String array used to store the information get from myFrame
*/publicAnotherFrame(String[] info){// create the panel in the North,Center,South respectively
panel1 =newJPanel();
panel2 =newJPanel();
panel3 =newJPanel();// create the lable in the top and set font of it
label =newJLabel("You have checked in successfully.");
Font font =newFont(null, Font.PLAIN,20);
label.setFont(font);// create the textArea and set font
textArea =newJTextArea();
Font font2 =newFont(null, Font.PLAIN,15);
textArea.setFont(font2);// add the information to the textfield:
textArea.append("Full name: ");
textArea.append(info[0]+"\n");
textArea.append("Date of birth: ");
textArea.append(info[1]+"\n");
textArea.append("Programme: ");
textArea.append(info[2]+"\n");
textArea.append("Email: ");
textArea.append(info[3]+"\n");
textArea.append("Phone number: ");
textArea.append(info[4]+"\n");// set the border and the background
textArea.setBorder(BorderFactory.createBevelBorder(EtchedBorder.LOWERED));
textArea.setBackground(null);// make the textArea can not be editable
textArea.setEditable(false);// can editable// create the button
button =newJButton("Finish");// add the components to the panels:
panel1.add(label);
panel2.add(textArea);
panel2.setBorder(BorderFactory.createBevelBorder(EtchedBorder.LOWERED));
panel3.add(button);
panel3.setBorder(BorderFactory.createBevelBorder(EtchedBorder.LOWERED));// add the panel to the framethis.add(panel1, BorderLayout.NORTH);this.add(panel2, BorderLayout.CENTER);this.add(panel3, BorderLayout.SOUTH);// the settings of framethis.setSize(540,240);this.setVisible(true);this.setDefaultCloseOperation(EXIT_ON_CLOSE);this.setResizable(false);this.setTitle("Check In complete!");// listening registration:
button.addActionListener(this);// set action command:
button.setActionCommand("Finish");}@Override/**
* Handle the click event.<br>
* When the user clicks on the "Finish" button, this program will exit.<br>
*
* @param e the event happened
*/publicvoidactionPerformed(ActionEvent e){if(e.getActionCommand().equals("Finish")){
System.exit(0);}}}