0% found this document useful (0 votes)
20 views5 pages

Add Student Details

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views5 pages

Add Student Details

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

package School_Management_System;

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

public class AddStudentDetails extends JFrame implements ActionListener


{
JLabel l1,l2,l3,l4,l5,l6,l7,l8,l9,l10,l11,l12,l13,l14,l15;
JButton bt1,bt2;
JTextField tf1,tf2,tf3,tf4,tf5,tf6,tf7,tf8,tf9,tf10,tf11,tf12,tf13,tf14;
JFrame f;
JPasswordField pf1;
Choice ch1,ch2;

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);

l2=new JLabel("Add Student Details for Signup");


l2.setBounds(230,50,500,50);
l2.setFont(new Font("Arial",Font.BOLD,30));
l2.setForeground(new Color(8,161,92));
l1.add(l2);
f.add(l1);
l3=new JLabel("Name");
l3.setBounds(50,150,150,30);
l3.setFont(new Font("Arial",Font.BOLD,20));
l3.setForeground(Color.DARK_GRAY);
l1.add(l3);

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);

l7=new JLabel("Father Name");


l7.setBounds(50,250,140,30);
l7.setFont(new Font("Arial",Font.BOLD,20));
l7.setForeground(Color.DARK_GRAY);
l1.add(l7);

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"));

}
}

catch (Exception ex)


{
ex.printStackTrace();
}

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);

l12=new JLabel("Blood Group");


l12.setBounds(450,350,140,30);
l12.setFont(new Font("Arial",Font.BOLD,20));
l12.setForeground(Color.DARK_GRAY);
l1.add(l12);

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);

l14=new JLabel("Roll NO.");


l14.setBounds(50,400,150,30);
l14.setFont(new Font("Arial",Font.BOLD,20));
l14.setForeground(Color.DARK_GRAY);
l1.add(l14);

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();

String q = "insert into student


values('"+stu_id+"','"+name+"','"+username+"','"+password+"','"+email+"','"+father_
name+"','"+phone+"','"+class1+"','"+section+"','"+gender+"','"+blood+"','"+dob+"','
"+roll_no+"')";
obj.stm.executeUpdate(q);
JOptionPane.showMessageDialog(null, "Details Successfully
Inserted");
f.setVisible(false);

}
catch (Exception ex)
{
ex.printStackTrace();
}
}
if(ae.getSource()==bt2)
{
f.setVisible(false);
}
}
public static void main(String[] args)
{
new AddStudentDetails().setVisible(true);
}

You might also like