Add New Class
Add New Class
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.sql.*;
import java.util.Random;
public class AddNewClass extends JFrame implements ActionListener
{
JLabel l1,l2,l3,l4,l5,l6;
JButton bt1,bt2;
JTextField t1;
JFrame f;
Choice ch1,ch2,ch3;
public AddNewClass()
{
f=new JFrame("Add New Class 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 New Class Details");
l2.setBounds(450,110,500,50);
l2.setFont(new Font("Arial",Font.BOLD,30));
l2.setForeground(new Color(84,2,224));
l1.add(l2);
f.add(l1);
l3=new JLabel("Class Name");
l3.setBounds(400,200,150,30);
l3.setFont(new Font("Arial",Font.BOLD,30));
l3.setForeground(new Color(59,2,117));
l1.add (l3);
ch1=new Choice();
ch1.add("1");
ch1.add("2");
ch1.add("3");
ch1.add("4");
ch1.add("5");
ch1.add("6");
ch1.add("7");
ch1.add("8");
ch1.add("9");
ch1.add("10");
ch1.add("11");
ch1.add("12");
ch1.setBounds(600,200,150,30);
ch1.setFont(new Font("Arial",Font.BOLD,20));
l1.add(ch1);
l4=new JLabel("Section");
l4.setBounds(400,250,200,30);
l4.setFont(new Font("Arial",Font.BOLD,30));
l4.setForeground(new Color(59,2,117));
l1.add (l4);
ch2=new Choice();
ch2.add("A");
ch2.add("B");
ch2.add("C");
ch2.setBounds(600,250,150,30);
ch2.setFont(new Font("Arial",Font.BOLD,20));
l1.add(ch2);
l5=new JLabel("Student Strength");
l5.setBounds(400,300,200,30);
l5.setFont(new Font("Arial",Font.BOLD,30));
l5.setForeground(new Color(59,2,117));
l1.add (l5);
ch3=new Choice();
ch3.add("10");
ch3.add("20");
ch3.add("30");
ch3.setBounds(600,300,150,30);
ch3.setFont(new Font("Arial",Font.BOLD,20));
l1.add(ch3);
l6=new JLabel("Enrolled Student");
l6.setBounds(400,350,200,30);
l6.setFont(new Font("Arial",Font.BOLD,30));
l6.setForeground(new Color(59,2,117));
l1.add (l6);
t1=new JTextField();
t1.setBounds(600,350,150,30);
t1.setFont(new Font("Arial",Font.BOLD,20));
t1.setEditable(false);
t1.setText("0");
l1.add(t1);
bt1=new JButton("Add Class");
bt1.setBackground(Color.BLACK);
bt1.setForeground(Color.WHITE);
bt1.setBounds(400,400,150,40);
l1.add(bt1);
bt2=new JButton("Back");
bt2.setBackground(new Color(88,245,174));
bt2.setForeground(Color.BLACK);
bt2.setBounds(600,400,150,40);
l1.add(bt2);
bt1.addActionListener(this);
bt2.addActionListener(this);
f.setVisible(true);
f.setSize(840,600);
f.setLocation(300,100);
f.setResizable(false);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==bt1)
{
String classname=ch1.getSelectedItem();
String section=ch2.getSelectedItem();
String enroll_stu=ch3.getSelectedItem();
String enrolled=t1.getText();
Random r=new Random();
String class_id=""+Math.abs(r.nextInt()%100000);
try
{
ConnectionClass obj=new ConnectionClass();
String q = "insert into class
values('"+class_id+"','"+classname+"','"+section+"','"+enroll_stu+"','"+enrolled+"'
)";
obj.stm.executeUpdate(q);
JOptionPane.showMessageDialog(null,"Details Successfully
Inserted");
f.setVisible(false);
}
catch (Exception ex)
{
f.setVisible(false);
}
}
if (e.getSource()==bt2)
{
new AddNewClass().setVisible(false);
}
}
public static void main(String[] args)
{
new AddNewClass().setVisible(true);
}