Add Student Details
Add Student Details
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.sql.*;
import java.util.Random;
public AddStudentDetails()
{
f=new JFrame("Add New Student Details");
f.setBackground(Color.WHITE);
f.setLayout(null);
l1=new JLabel();
l1.setBounds(0,0,840,600);
l1.setLayout(null);
ImageIcon img=new
ImageIcon(ClassLoader.getSystemResource("School_Management_System/Icons/
AddTeacher.jpg"));
Image i1=img.getImage().getScaledInstance(840, 600,Image.SCALE_SMOOTH );
ImageIcon img1=new ImageIcon(i1);
l1.setIcon(img1);
tf1=new JTextField();
tf1.setBounds(200,150,150,30);
l1.add(tf1);
l4=new JLabel("Username");
l4.setBounds(450,150,200,30);
l4.setFont(new Font("Arial",Font.BOLD,20));
l4.setForeground(Color.DARK_GRAY);
l1.add(l4);
tf2=new JTextField();
tf2.setBounds(600,150,150,30);
l1.add(tf2);
l5=new JLabel("Password");
l5.setBounds(50,200,150,30);
l5.setFont(new Font("Arial",Font.BOLD,20));
l5.setForeground(Color.DARK_GRAY);
l1.add(l5);
pf1=new JPasswordField();
pf1.setBounds(200,200,150,30);
l1.add (pf1);
l6=new JLabel("Email");
l6.setBounds(450,200,200,30);
l6.setFont(new Font("Arial",Font.BOLD,20));
l6.setForeground(Color.DARK_GRAY);
l1.add(l6);
tf3=new JTextField();
tf3.setBounds(600,200,150,30);
l1.add(tf3);
tf4=new JTextField();
tf4.setBounds(200,250,150,30);
l1.add(tf4);
l8=new JLabel("Phone");
l8.setBounds(450,250,100,30);
l8.setFont(new Font("Arial",Font.BOLD,20));
l8.setForeground(Color.DARK_GRAY);
l1.add(l8);
tf5=new JTextField();
tf5.setBounds(600,250,150,30);
l1.add(tf5);
l9=new JLabel("Class");
l9.setBounds(50,300,160,30);
l9.setFont(new Font("Arial",Font.BOLD,20));
l9.setForeground(Color.DARK_GRAY);
l1.add(l9);
ch1=new Choice();
try
{
ConnectionClass obj=new ConnectionClass();
String q="select * from class";
ResultSet rest=obj.stm.executeQuery(q);
while (rest.next())
{
ch1.add(rest.getString("class_name"));
}
}
catch (Exception ex)
{
ex.printStackTrace();
}
ch1.setBounds(200,300,150,30);
l1.add(ch1);
l10=new JLabel("Section");
l10.setBounds(450,300,100,30);
l10.setFont(new Font("Arial",Font.BOLD,20));
l10.setForeground(Color.DARK_GRAY);
l1.add(l10);
ch2=new Choice();
try
{
ConnectionClass obj=new ConnectionClass();
String q="select * from class";
ResultSet rest=obj.stm.executeQuery(q);
while (rest.next())
{
ch2.add(rest.getString("section"));
}
}
ch2.setBounds(600,300,150,30);
l1.add(ch2);
l11=new JLabel("Gender");
l11.setBounds(50,350,100,30);
l11.setFont(new Font("Arial",Font.BOLD,20));
l11.setForeground(Color.DARK_GRAY);
l1.add(l11);
tf6=new JTextField();
tf6.setBounds(200,350,150,30);
l1.add(tf6);
tf7=new JTextField();
tf7.setBounds(600,350,150,30);
l1.add(tf7);
l13=new JLabel("D.O.B");
l13.setBounds(450,400,100,30);
l13.setFont(new Font("Arial",Font.BOLD,20));
l13.setForeground(Color.DARK_GRAY);
l1.add(l13);
tf8=new JTextField();
tf8.setBounds(600,400,150,30);
l1.add(tf8);
tf9=new JTextField();
tf9.setBounds(200,400,150,30);
l1.add(tf9);
tf9.setEditable(false);
bt1=new JButton("Submit");
bt1.setBounds(200,500,150,30);
bt2=new JButton("Cancel");
bt2.setBounds(450,500,150,30);
bt1.setForeground(Color.WHITE);
bt2.setForeground(Color.BLACK);
bt1.setBackground(Color.BLACK);
bt2.setBackground(new Color(191,247,161));
bt1.addActionListener(this);
bt2.addActionListener(this);
l1.add(bt1);
l1.add(bt2);
f.setVisible(true);
f.setSize(840,600);
f.setLocation(300, 100);
f.setResizable(false);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==bt1)
{
String name=tf1.getText();
String username=tf2.getText();
String password=pf1.getText();
String email=tf3.getText();
String father_name=tf4.getText();
String phone=tf5.getText();
String class1=ch1.getSelectedItem();
String section=ch2.getSelectedItem();
String gender=tf6.getText();
String blood=tf7.getText();
String dob=tf8.getText();
String roll_no=tf9.getText();
Random r = new Random();
String stu_id=""+Math.abs(r.nextInt()% 10000000);
try
{
ConnectionClass obj=new ConnectionClass();
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
if(ae.getSource()==bt2)
{
f.setVisible(false);
}
}
public static void main(String[] args)
{
new AddStudentDetails().setVisible(true);
}