21BCM075 Csi0403 Assignment 4
21BCM075 Csi0403 Assignment 4
OUTPUT :
Q.2 Explain the complete Life cycle of Thread with
diagram?
Lifecycle of a thread :
It has 5 different phases in its lifecycle :
a. New
b. Runnable
c. Running
d. Waiting
e. Dead
Q.3 Write a Java program that 4 inputs in Text field as
Rollno, Name, Phone no and email id from the user on
the clicking of Registration button and insert it into the
table Student.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
setLayout(null);
setSize(500, 500);
setTitle("Registration Form");
getContentPane().setBackground(new Color(204, 255, 204));
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
b1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
String DB_URL = "jdbc:mysql://localhost:3306/assignment3_ooad";
String USER = "root";
String PASS = "1234";
Connection conn = DriverManager.getConnection(DB_URL, USER, PASS);
System.out.println("database connected...");
pstmt.executeUpdate();
System.out.println("data inserted succesfully..");
conn.close();
l5.setVisible(true);
} catch (SQLException a) {
a.printStackTrace();
}
}
});
}
OUTPUT :
Q.4 Extend the above program by verifying Roll no and
email id by taking input from 2 text field and click login
button which will check that both entries are matched
perfectly or not and display “ Login Successfully”.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
setLayout(null);
setSize(400, 400);
setTitle("Login Form");
getContentPane().setBackground(new Color(255, 204, 219));
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
b2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
t1.setText("");
t2.setText("");
}
});
b1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
String DB_URL = "jdbc:mysql://localhost:3306/assignment3_ooad";
String USER = "root";
String PASS = "1234";
Connection conn = DriverManager.getConnection(DB_URL, USER, PASS);
System.out.println("database connected...");
String q = "select * from student where email_id='" + emailID + "'and Rollno='" + rollno +
"'";
ResultSet rs = stmt.executeQuery(q);
if (rs.next()) {
dispose();
JFrame jf = new JFrame();
JLabel l3 = new JLabel("Login Successfull..");
jf.add(l3);
l3.setBounds(70, 100, 300, 100);
l3.setFont(new Font("Cascadia code", Font.BOLD, 26));
jf.setLayout(null);
jf.setSize(400, 400);
jf.getContentPane().setBackground(new Color(255, 204, 219));
jf.setVisible(true);
} else {
JFrame f = new JFrame();
JOptionPane.showMessageDialog(f, "emailID or Rollno!!");
t1.setText("");
t2.setText("");
}
conn.close();
} catch (Exception a) {
a.printStackTrace();
}
}
});
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
}
}
OUTPUT :
Q.5 Explain the use of Component “ JTABLE” in the
swing with the help of code.
import javax.swing.*;
import java.awt.event.*;
jf.setSize(400, 400);
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
}
}
OUTPUT :