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: 3842937 • Letter: J

Question

JAVA

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

GUI examples

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

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;

public class person_details extends JFrame implements ActionListener
{
JLabel l_name, l_year, l_major, l_ft, l_email; // declaring Lebels for all inputs
JTextField name, major, email; //declaring text field for input data
   JComboBox FullTin = new JComboBox(); //Declaring and creating combo box to select among yes or no
   FullTin.addItem("Yes"); //adding option "Yes" to combo box
   FullTin.addItem("No"); //adding option "No" to combo box
   JComboBox year = new JComboBox(); //Declaring and creating Combo box to select year
   year.addItem("1"); //adding option "1" to combo box
   year.addItem("2"); //adding option "2" to combo box
   year.addItem("3");//adding option "3" to combo box
   year.addItem("4");//adding option "4" to combo box
JButton Insert, Clear; //declaring button for insert and clear
person_details()
{
setVisible(true);
setSize(700, 700);
setLayout(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setTitle("Person Details"); //set the title of the frame
l_name = new JLabel("Name:"); //adding text the lable
l_year = new JLabel("Year:");//adding text the lable
l_major = new JLabel("Major:");//adding text the lable
l_ft = new JLabel("FillTin:");//adding text the lable
l_email = new JLabel("Email:");//adding text the lable
name = new JTextField(); //creating text field to input data
major = new JTextField(); //creating text field to input data
email = new JTextField(); //creating text field to input data
Insert = new JButton("Insert"); //creating Button
Clear = new JButton("Clear"); //creating Button
Insert.addActionListener(this); //adding event listner to button "Insert"
Clear.addActionListener(this); //adding event listner to button "Clear"
add(l_name); //adding the element to frame
add(name);//adding the element to frame
add(l_year);//adding the element to frame
add(year);//adding the element to frame
add(l_major);//adding the element to frame
       add(major);//adding the element to frame
add(l_ft);//adding the element to frame
add(FullTin);//adding the element to frame
add(l_email);//adding the element to frame
add(email);//adding the element to frame
add(Insert);//adding the element to frame
add(Clear);//adding the element to frame
}

public void actionPerformed(ActionEvent e)
{
if (e.getSource() == Insert) //If event is "Insert" i.e Insert button is clicked
{
int x = 0;
String s1 = name.getText(); //get the value
String s2 = year.getText();//get the value
String s3 = major.getText();//get the value
String s4 = FullTin.getText();//get the value
String s5 = email.getText();//get the value
try
{
String database="student.mdb";//Databse with full path. In this case database exists in the current directory
               String url="jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)}; //databse driver
DBQ=" + database + ";DriverID=22;READONLY=false";
               Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
               Connection con=DriverManager.getConnection(url);
               Statement st=con.createStatement();
               ResultSet rs=st.executeQuery("insert into StudentData values('"+s1+"','"+s2+"','"+s3+"','"+s4+"','"+s5+"'");
}
catch (Exception ex)
{
System.out.println(ex);
}

}
else
{
name.setText("");//clearing the field
major.setText("");//clearing the field
email.setText("");//clearing the field
}
}
public static void main(String args[])
{
new person_details();
}
}