Hi I am new to this forum and want some help with some Java code. I am creating a Three Tier Structure and below is the GUI class of the project. The problem is I can't make it work to insert into the Database file. Could someone please help me with it? Thanks.
// GUI Visitor Register
package Register;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class VisitorRegister extends JFrame {
// GUI variables
// JLabel and JComboBox for Title
private JLabel TitleJLabel;
private JComboBox TitleJComboBox;
// JLabel and JTextField for FirstName
private JLabel FirstNameJLabel;
private JTextField FirstNameJTextField;
// JLabel and JTextField for LastName
private JLabel LastNameJLabel;
private JTextField LastNameJTextField;
// JLabel and JTextField for CompanyName
private JLabel CompanyNameJLabel;
private JTextField CompanyNameJTextField;
// JLabel and JComboBox for VisitorType
private JLabel VisitorTypeJLabel;
private JComboBox VisitorTypeJComboBox;
// JLabel and JTextField for HostName
private JLabel HostNameJLabel;
private JTextField HostNameJTextField;
// JLabel and JTextField for HostLocation
private JLabel HostLocationJLabel;
private JComboBox HostLocationJComboBox;
// JButton for NewVisitor
private JButton NewVisitorJButton;
// JButton for Appointment
private JButton AppointmentJButton;
// JButton for CancelAppointment
private JButton CancelAppointmentJButton;
// JButton for StaffHost
private JButton StaffHostJButton;
// JButton for Login
private JButton LoginJButton;
// JButton for LogOff
private JButton LogOffJButton;
// no-argument constructor
public VisitorRegister() {
createUserInterface();
}
// create and position GUI components; register event handlers
public void createUserInterface() {
// get content pane and set layout to null
Container contentPane = getContentPane();
contentPane.setLayout(null);
// set up TitleJLabel
TitleJLabel = new JLabel();
TitleJLabel.setText("Title: ");
TitleJLabel.setBounds(15, 15, 30, 25);// done (x, y, w, h)
contentPane.add(TitleJLabel);
// set up TitleJComboBox
String title[] = {"Dr", "Mr", "Mrs", "Ms"};
TitleJComboBox = new JComboBox(title);
TitleJComboBox.setBounds(50, 15, 50, 25);// done (x, y, w, h)
contentPane.add(TitleJComboBox);
// set up FirstNameJLabel
FirstNameJLabel = new JLabel();
FirstNameJLabel.setText("First Name: ");
FirstNameJLabel.setBounds(105, 15, 70, 25);// done (x, y, w, h)
contentPane.add(FirstNameJLabel);
// set up FirstNameJTextField
FirstNameJTextField = new JTextField();
FirstNameJTextField.setText(" ");
FirstNameJTextField.setBounds(180, 15, 125, 25);// done (x, y, w, h)
contentPane.add(FirstNameJTextField);
// set up LastNameJLabel
LastNameJLabel = new JLabel();
LastNameJLabel.setText("Last Name: ");
LastNameJLabel.setBounds(320, 15, 70, 25);// done (x, y, w, h)
contentPane.add(LastNameJLabel);
// set up LastNameJTextField
LastNameJTextField = new JTextField();
LastNameJTextField.setText(" ");
LastNameJTextField.setBounds(395, 15, 120, 25);// done (x, y, w, h)
contentPane.add(LastNameJTextField);
// set up CompanyNameJLabel
CompanyNameJLabel = new JLabel();
CompanyNameJLabel.setText("Company Name: ");
CompanyNameJLabel.setBounds(15, 55, 100, 25);// done (x, y, w, h)
contentPane.add(CompanyNameJLabel);
// set up CompanyNameJTextField
CompanyNameJTextField = new JTextField();
CompanyNameJTextField.setText(" ");
CompanyNameJTextField.setBounds(120, 55, 170, 25);// done (x, y, w, h)
contentPane.add(CompanyNameJTextField);
// set up VisitorTypeJLabel
VisitorTypeJLabel = new JLabel();
VisitorTypeJLabel.setText("Visitor Type: ");
VisitorTypeJLabel.setBounds(315, 55, 85, 25);// done (x, y, w, h)
contentPane.add(VisitorTypeJLabel);
// set up VisitorTypeJComboBox
String visitor[] = {"Cleaner", "Contractor", "Courier", "Staff", "Visitor"};
VisitorTypeJComboBox = new JComboBox(visitor);
VisitorTypeJComboBox.setBounds(395, 55, 120, 25);// done (x, y, w, h)
contentPane.add(VisitorTypeJComboBox);
// set up HostNameJLabel
HostNameJLabel = new JLabel();
HostNameJLabel.setText("Host's Full Name: ");
HostNameJLabel.setBounds(15, 95, 100, 25);// done (x, y, w, h)
contentPane.add(HostNameJLabel);
// set up HostNameJTextField
HostNameJTextField = new JTextField();
HostNameJTextField.setText(" ");
HostNameJTextField.setBounds(120, 95, 170, 25);// done (x, y, w, h)
contentPane.add(HostNameJTextField);
// set up HostLocationJLabel
HostLocationJLabel = new JLabel();
HostLocationJLabel.setText("Host Location: ");
HostLocationJLabel.setBounds(305, 95, 85, 25);// done (x, y, w, h)
contentPane.add(HostLocationJLabel);
// set up HostLocationJComboBox
String location[] = {"Ground Floor", "Lower Ground Floor", "1st Floor", "2nd Floor", "3rd Floor", "4th Floor", "5th Floor"};
HostLocationJComboBox = new JComboBox(location);
HostLocationJComboBox.setBounds(395, 95, 120, 25);// done (x, y, w, h)
contentPane.add(HostLocationJComboBox);
//set up NewVisitorJButton
NewVisitorJButton = new JButton();
NewVisitorJButton.setText("New Visitor");
NewVisitorJButton.setBounds(35, 135, 150, 30); // done (x, y, w, h)
contentPane.add(NewVisitorJButton);
// anonymous inner class for ActionListener
NewVisitorJButton.addActionListener(
new ActionListener() {
// method called when calculate JButton is pressed
public void actionPerformed(ActionEvent event) {
NewVisitorJButtonActionPerformed(event);
}
} // end of anonymous inner class
); // end call to addActionListener
// set up AppointmentJButton
AppointmentJButton = new JButton();
AppointmentJButton.setText("Make Appointment");
AppointmentJButton.setBounds(190, 135, 150, 30);// done (x, y, w, h)
contentPane.add(AppointmentJButton);
// anonymous inner class for ActionListener
AppointmentJButton.addActionListener(
new ActionListener() {
// method called when calculate JButton is pressed
public void actionPerformed(ActionEvent event) {
AppointmentJButtonActionPerformed(event);
}
} // end of anonymous inner class
); // end call to addActionListener
// set up CancelAppointmentJButton
CancelAppointmentJButton = new JButton();
CancelAppointmentJButton.setText("Cancel Appointment");
CancelAppointmentJButton.setBounds(345, 135, 150, 30);// done (x, y, w, h)
contentPane.add(CancelAppointmentJButton);
// anonymous inner class for ActionListener
CancelAppointmentJButton.addActionListener(
new ActionListener() {
// method called when calculate JButton is pressed
public void actionPerformed(ActionEvent event) {
CancelAppointmentJButtonActionPerformed(event);
}
} // end of anonymous inner class
); // end call to addActionListener
// set up LoginJButton
LoginJButton = new JButton();
LoginJButton.setText("Login Visitor");
LoginJButton.setBounds(35, 175, 150, 30);// done (x, y, w, h)
contentPane.add(LoginJButton);
// anonymous inner class for ActionListener
LoginJButton.addActionListener(
new ActionListener() {
// method called when calculate JButton is pressed
public void actionPerformed(ActionEvent event) {
LoginJButtonActionPerformed(event);
}
} // end of anonymous inner class
); // end call to addActionListener
// set up LogOffJButton
LogOffJButton = new JButton();
LogOffJButton.setText("Log Off Visitor");
LogOffJButton.setBounds(190, 175, 150, 30);// done (x, y, w, h)
contentPane.add(LogOffJButton);
// anonymous inner class for ActionListener
LogOffJButton.addActionListener(
new ActionListener() {
// method called when calculate JButton is pressed
public void actionPerformed(ActionEvent event) {
LogOffJButtonActionPerformed(event);
}
} // end of anonymous inner class
); // end call to addActionListener
// set up StaffHostJButton
StaffHostJButton = new JButton();
StaffHostJButton.setText("Add Staff / Host");
StaffHostJButton.setBounds(345, 175, 150, 30);// done (x, y, w, h)
contentPane.add(StaffHostJButton);
// anonymous inner class for ActionListener
StaffHostJButton.addActionListener(
new ActionListener() {
// method called when StaffHostJButton is pressed
public void actionPerformed(ActionEvent event) {
StaffHostJButtonActionPerformed(event);
}
} // end of anonymous inner class
); // end call to addActionListener
// set properties of application’s window
setTitle("Visitor's Register"); // set title bar text
setSize(540, 250); // set window size
setVisible(true); // display window
}// end method createUserInterface
// Methods for ActionListeners
private void NewVisitorJButtonActionPerformed(ActionEvent event) {
FirstNameJTextField.setText(" ");
LastNameJTextField.setText(" ");
CompanyNameJTextField.setText(" ");
HostNameJTextField.setText(" ");
}
private void AppointmentJButtonActionPerformed(ActionEvent event) {
String title = (String) TitleJComboBox.getSelectedItem();
String firstName = FirstNameJTextField.getText();
String lastName = LastNameJTextField.getText();
String companyName = CompanyNameJTextField.getText();
String visitor = (String) VisitorTypeJComboBox.getSelectedItem();
String host = HostNameJTextField.getText();
String location = (String) HostLocationJComboBox.getSelectedItem();
VisitorDA.initialize();
Visitor newVisitor = VisitorDA.newVisitor(rs.getString("title"), rs.getString ("fname"), rs.getString ("lname"), rs.getString ("compname"), rs.getString ("vistype"), rs.getString ("hname"), rs.getString ("location"));
// Visitor newVisitor = VisitorDA.newVisitor(title, firstName, lastName, companyName, visitor, host, location);
VisitorDA.terminate();
}// end method AppointmentJButtonActionPerformed
private void CancelAppointmentJButtonActionPerformed(ActionEvent event) {
}
private void LoginJButtonActionPerformed(ActionEvent event) {
}
private void LogOffJButtonActionPerformed(ActionEvent event) {
}
private void StaffHostJButtonActionPerformed(ActionEvent event) {
}
// main method
public static void main(String[] args) {
VisitorRegister application = new VisitorRegister();
application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
} // end method main
}