Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

JAVA Can anyone turn this database information into GUI please? Thanks. Add comm

ID: 3844270 • Letter: J

Question

JAVA

Can anyone turn this database information into GUI please? Thanks. Add comments to code please.


TABLE TOOLS HOME CREATE EXTERNAL DATA DATABASE TOOLS FIELDS TABLE New Totals Ascending Tr Selection Descending Advanced Save Spelling Copy Filter Refresh 2 Remove Sort Format painter Y Toggle Filter All. X Delete More Clipboard Sort & Filter Records les Student Data Name Yea Major FullTin Email Julie 3 Sociology julieh@supermail.com David 4 Art. davidr Supermail.com Carolyn 1 Accounting carolynw@supermail.com 3 Biology billk@supermail.com Arthur 2 Mathematics arthurj@supermail.com Nancy 4 Sociology nancy a@supermail.com

Explanation / Answer

package exceptions;

/* Tyler Normile
* Java Registration Form with field input validation.
*/

import java.awt.*;   //import older gui library for content pane
import javax.swing.*;   //import newer gui library for labels, textfields, and button
import java.awt.event.*; //import gui event action library

class DataBaseForm extends JFrame implements ActionListener {

// declare labels used on GUI screen
private JLabel labelName, labelYear, labelMajor, labelFullTime, labelYes, labelNo, labelEmail;
private JLabel labelError, labelRegistration; // used for good and bad messages
// declare text fields used on GUI screen
private JTextField textName, textYear, textMajor, textEmail;
// declare button used on GUI screen
private JButton submitButton, clearButton;
//declre Check box
   private JCheckBox CheckYes, CheckNO;
  
   // declare content pane
  
private Container contentPane;

public DataBaseForm() {
createGUI();
} // ends constructor

private void createGUI() {
try {
// get content pane and set the layout to null
contentPane = getContentPane();
contentPane.setLayout(null);   //free-form layout
setFont(new Font("TimesRoman", Font.ITALIC, 14));

// create the name label
labelName = new JLabel();   //instantiate new JLabel
labelName.setText("Name");   //set label text to name
labelName.setLocation(38, 10);   //set location of JLabel
labelName.setSize(200, 25);   //set size of JLabel
labelName.setForeground(Color.BLACK);//set initial background color
contentPane.add(labelName);   //add JLabel to content pane

// create the name text box
textName = new JTextField();   //instantiate new JTextField
textName.setText("");   //clear JTextField
textName.setToolTipText("Please type in full name - last name first");
textName.setLocation(75, 10);   //set location of JTextFfield
textName.setSize(200, 25); //set size of JTextField
contentPane.add(textName); //add jextfield to content pane

// create the Year label
labelYear = new JLabel();
labelYear.setText("Year");
labelYear.setLocation(38, 50);
labelYear.setSize(200, 25);
labelYear.setForeground(Color.BLACK);
contentPane.add(labelYear);

// create the Year text box
textYear = new JTextField();
textYear.setText("");
textYear.setToolTipText("Please type Year");
textYear.setLocation(75, 50);
textYear.setSize(60, 25);
contentPane.add(textYear);

// create the Major label
labelMajor = new JLabel();
labelMajor.setText("Major");
labelMajor.setLocation(38, 90);
labelMajor.setSize(200, 25);
labelMajor.setForeground(Color.BLACK);
contentPane.add(labelMajor);

// create the Major text box
textMajor = new JTextField();
textMajor.setText("");
textMajor.setToolTipText("Please type in Major specialization");
textMajor.setLocation(75, 90);
textMajor.setSize(130, 25);
contentPane.add(textMajor);

// create the FullTime label
labelFullTime = new JLabel();
labelFullTime.setText("FullTime");
labelFullTime.setLocation(40, 130);
labelFullTime.setSize(300, 25);
labelFullTime.setForeground(Color.BLACK);
contentPane.add(labelFullTime);

// create the YES check box
CheckYes = new JCheckBox();
CheckYes.setText("YES");
CheckYes.setLocation(95, 130);
CheckYes.setSize(50, 25);
contentPane.add(CheckYes);

// create the NO check box
CheckNO = new JCheckBox();
CheckNO.setText("No");
CheckNO.setLocation(155, 130);
CheckNO.setSize(130, 25);
contentPane.add(CheckNO);
  
          
  
// create the email label
labelEmail = new JLabel();
labelEmail.setText("Email");
labelEmail.setLocation(38, 180);
labelEmail.setSize(300, 25);
labelEmail.setForeground(Color.BLACK);
contentPane.add(labelEmail);
  
// create the email text box
textEmail = new JTextField();
textEmail.setText("");
textEmail.setToolTipText("Must be a valid email address containing ' @ '");
textEmail.setLocation(75, 180);
textEmail.setSize(130, 25);
contentPane.add(textEmail);
  
  
  
// create the submit button
submitButton = new JButton();
submitButton.setText("Submit");
submitButton.setToolTipText("Click "submit " when the form is completely filled out");
submitButton.setLocation(125, 450);
submitButton.setSize(100, 30);
contentPane.add(submitButton);
submitButton.addActionListener(this);

clearButton = new JButton();
clearButton.setText("Clear");
clearButton.setToolTipText("Click "clear " when you want to clear the form");
clearButton.setLocation(250, 450);
clearButton.setSize(100, 30);
contentPane.add(clearButton);
clearButton.addActionListener(this);

// create the error label
labelError = new JLabel();
labelError.setText("Please correct items in red");
labelError.setLocation(150, 500);
labelError.setSize(190, 25);
labelError.setForeground(Color.RED);
labelError.setVisible(false);
contentPane.add(labelError);

// create the registration label
labelRegistration = new JLabel();
labelRegistration.setText("Thank you for your DataBase Registration.");
labelRegistration.setLocation(145, 500);
labelRegistration.setSize(190, 25);
labelRegistration.setForeground(Color.BLACK);
labelRegistration.setVisible(false);
contentPane.add(labelRegistration);

// set properties of window
setTitle("DataBase Form");   //set window title
setSize(475, 600); //set window size
setVisible(true);
} catch (Exception e) {
}
}// ends creatGUI method.

public static void main(String args[]) {
DataBaseForm application = new DataBaseForm();
application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}// ends main

public void actionPerformed(ActionEvent event) {
try {
if (event.getActionCommand().equals("Submit")) {
//Statements get executed here when SUBMIT button is pressed.
//Using the "&" instead of "&&" ensures that all check methods get called.
//If you used the "&", you would only see one error at a time.
//The form cannot be submitted until all the errors are fixed (every method returns true).
if (checkName() & checkYear() & checkMajor() & checkEmail()) {
labelRegistration.setVisible(true); //all information is entered and correct
labelError.setVisible(false);   //hide this message if visible
submitButton.removeActionListener(this); // stop listening to submit button - form complete
clearButton.removeActionListener(this); // stop listening to clear button - form complete
} else {
labelError.setVisible(true); //all information is not valid on form
labelRegistration.setVisible(false); //hide this message when bad information entered
}
} if (event.getActionCommand().equals("Clear"))
{
textName.setText("");
textYear.setText("");
textMajor.setText("");
textEmail.setText("");
labelError.setVisible(false);
labelRegistration.setVisible(false);
labelName.setForeground(Color.BLACK);
labelYear.setForeground(Color.BLACK);
labelYes.setForeground(Color.BLACK);
labelNo.setForeground(Color.BLACK);
labelEmail.setForeground(Color.BLACK);
labelFullTime.setForeground(Color.BLACK);
labelMajor.setForeground(Color.BLACK);
  
}
} catch (Exception e) { }
}// ends actionPerformed method

/* The checkName method looks at the contents of the name text field.
The method requires that the length is greater than zero to pass (return true).
If the length is greater than zero, the method returns true and sets the label
color to black. If the length is zero, the method returns false and changes the
label color to red. */
private boolean checkName() {
if (textName.getText().length() == 0) {
labelName.setForeground(Color.RED);   //name is not correct
return false;
} else {
labelName.setForeground(Color.BLACK); //name is correct
return true;
}
} //end of method


/* The CHeckYEar method looks at the contents of the Year text field.
The method requires that the length is at least 5 to pass (return true).
If the length is at least 5, the method returns true and sets the label
color to black. If the length is less than 5, the method returns false and
changes the label color to red. */
private boolean checkYear() {
if (textYear.getText().length() < 5) {
labelYear.setForeground(Color.RED);   //address is not correct
return false;
} else {
labelYear.setForeground(Color.BLACK);   //address is correct
return true;
}
} //end of method

/* The CheckMajor method looks at the contents of the Specialization text field.
The method requires that the length is greater than zero to pass (return true).
If the length is greater than zero, the method returns true and sets the label
color to black. If the length is zero, the method returns false and changes the
label color to red. */
private boolean checkMajor() {
if (textMajor.getText().length() == 0) {
labelMajor.setForeground(Color.RED);   //city is not correct
return false;
} else {
labelMajor.setForeground(Color.BLACK);   //city is correct
return true;
}
} //end of method


private boolean checkEmail() {
if (textEmail.getText().contains("@"))
{
labelEmail.setForeground(Color.BLACK);   //email is correct and contains @ symbol
return true;
} else
{
labelEmail.setForeground(Color.RED);   //email is not correct
return false;
}
} //end of the method
  
  
  
}// ends program