You are on page 1of 65

Class Management System

Class Management System


Class Management System is a Java GUI application and created on Swing
Components like JButton, JTextFields, JCheckBox, JRadioButton,JPanel and so on. This
application allows users to insert, delete, update the class, students and lecturer
records.
Class Management System provides the facility to store the data about students,
class and lecturers by means a Student is pursuing which courses from which
Lecturer taking which Class. To run the project there are two .bat file i.e. compile
and run. Before run the project you have to take these following steps i.e.
connectivity steps:
1.
2.
3.
4.
5.
6.
7.

Goto Control Panel


Open Administrative Tools
Choose Data Source (ODBC)
Click Add Button
Select Server Native Client 10.0
Press Finish Button
Enter the Name ClassManagementSystem. You can set blank value in
Description and Write in Which SQL Server do you want to connect to?
Connection String i.e. MYPC\SQLEXPRESS
8. Then Press Finish Button
9. A Dialog Box Appear then press Test Data Source and then OK
10.Press OK
Now, Connectivity Process is complete you can compile the whole program using
compile.bat file and for run the program you have to run the run.bat file
The SQL query for creating the database CMS:
create database CMS;
use CMS;
create table Student
(SID varchar(50) primary key,
FName varchar(50),
LName varchar(50),
Mobile varchar(20),
Address varchar(100)
);
create table Lecturer
(LID varchar(50) primary key,
FName varchar(50),
LName varchar(50),
Campus varchar(100),
Phone varchar(20)
);

create table Class


(
CID varchar(50) primary
key,
UnitCode varchar(50),
UnitName varchar(50),
LID varchar(50) references
Lecturer(LID)
);
create table StudentCourse
(
SID varchar(50) references
Student(SID),
CID varchar(50) references
Class(CID)
);
[1]

Class Management System

[2]

These are the following screenshots after running Class Management System:

Login Panel

Enter the Login Credentials and you can proceed to Class Management System. The
Credentials are as follows:
Login: Admin
Password: admin
If the login is incorrect then following dialog box is appear

and then you will resumes the login screen.

Main Form

In the Application Menu, you can exit the Application Software or Press Alt + F4.
In the Student Menu:
1. You can insert a New Student or press Ctrl + S
2. You can Update the Student Details or press Ctrl + Alt +S
3. You can Delete the Student or press Ctrl + Shift + S
In the Class Menu:
1. You can insert a New Class or press Ctrl + C
2. You can Update the Class or press Ctrl + Alt +C
3. You can Delete the Class or press Ctrl + Shift + C
In the Lecturer Menu:
1. You can insert a New Lecturer or press Ctrl + L
2. You can Update the Lesturer or press Ctrl + Alt +L
3. You can Delete the Lecturer or press Ctrl + Shift + L
In the Report Menu:
1. You can print the Student Report

New Student

From the Please Select option you can select the Insert, Update and Delete the
Student details.

Update Student

Enter the Student ID and press Find button and you will get the information about
that student and the information is filled in the given form and press Update button.
Update button is currently disabled and it disables until the information is filled in
the form.

Delete Student

Enter the Student ID and press Find button and you will get the information about
that student and the information is filled in the given form and press Delete button.
Delete button is currently disabled and it disables until the information is filled in
the form.

New Class

From the Please Select option you can select the Insert, Update and Delete the
Student details.
In Insert New Class form you have to enter the Class ID, Unit Code and Unit Name.

Update Class

Enter the class ID and press Find button and you will get the information about
that class and the information is filled in the given form and press Update button.
Update button is currently disabled and it disables until the information is filled in
the form. Reset button is used to clear the all fields of the form.

Delete Class

Enter the class ID and press Find button and you will get the information about
that class and the information is filled in the given form and press Delete button.
Delete button is currently disabled and it disables until the information is filled in
the form. Reset button is used to clear the all fields of the given form.

Insert New Lecturer

From the Please Select option you can select the Insert, Update and Delete the
Lecturer details. In Insert New Lecturer form you have to entered the Lecturer ID,
Name, Campus, Phone and select the course of the student. Reset button is used to
clear the all fields of the given form.

Update Lecturer

Enter the Lecturer ID and press Find button and you will get the information about
that Lecturer and the information is filled in the given form and press Update
button. Update button is currently disabled and it disables until the information is
filled in the form. Reset button is used to clear the all fields of the form.

Delete Lecturer

Enter the Lecturer ID and press Find button and you will get the information about
that Lecturer and the information is filled in the given form and press Delete button.
Delete button is currently disabled and it disables until the information is filled in
the form. Reset button is used to clear the all fields of the given form..

Student Report

Enter the Student ID and press Find button and you will get the information about
that student. Reset button is used to clear the all fields of the given form.

Class Management System

/*****************************Student Form**********************/
package myPackage;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
public class studentForm extends JDialog implements ActionListener
{
JPanel p1,p2,p3,p4;
JLabel l0,l1,l2,l3,l4,l5,l6,l7;
JTextField t1,t2,t3,t4,t5;
TextArea ta1;
JButton b1,b2,b3,b4;
JRadioButton r1,r2,r3;
ButtonGroup bg1;
JCheckBox cb[];
int rowcount=0;
public studentForm()
{
p1=new JPanel();
p2=new JPanel();
p3=new JPanel();
p4=new JPanel();
getContentPane().add(p1);
setSize(350,700);
// setLocationRelativeTo(null);
setLocation(10,50);
setVisible(true);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setAlwaysOnTop(true);
setTitle("Student");
setResizable(false);
l0=new
l1=new
l2=new
l3=new
l4=new
l5=new

JLabel("Please Select");
JLabel("Student");
JLabel("Student ID");
JLabel("Name");
JLabel("Mobile");
JLabel("Address");

t1=new JTextField(20);
t2=new JTextField(20);
t3=new JTextField(20);

ta1=new TextArea();
l1.setFont(new Font("Cambria",Font.BOLD,24));
t1.setFont(new Font("Cambria",Font.BOLD,20));
t2.setFont(new Font("Cambria",Font.BOLD,18));
t3.setFont(new Font("Cambria",Font.BOLD,18));
ta1.setFont(new Font("Cambria",Font.BOLD,18));
b1=new JButton("Insert");
b2=new JButton("Reset");
b3=new JButton("Cancel");
b4=new JButton("Find");
b4.setVisible(false);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
r1=new JRadioButton("New Student");
r2=new JRadioButton("Update Student");
r3=new JRadioButton("Delete Student");
bg1=new ButtonGroup();
bg1.add(r1);
bg1.add(r2);
bg1.add(r3);
// p1.setBackground(Color.blue);
// p2.setBackground(Color.red);
// p3.setBackground(Color.green);
p1.setLayout(new BorderLayout());
p3.setLayout(null);
p1.add(p2,BorderLayout.NORTH);
p1.add(p3,BorderLayout.CENTER);
p2.add(l1);
p3.add(
p3.add(
p3.add(
p3.add(

l0);
r1);
r2);
r3);

p3.add( l2);
p3.add( t1);
p3.add( l3);
p3.add( t2);
p3.add( l4);
p3.add( t3);
p3.add( l5);
p3.add(ta1);
p3.add( b1);
p3.add( b2);
p3.add( b3);
p3.add( b4);
p3.add( p4);
l0.setBounds(10,10,100,30);
r1.setBounds(120,10,150,30);
r2.setBounds(120,40,150,30);
r3.setBounds(120,70,150,30);
l2.setBounds(10,110,100,30);
t1.setBounds(120,110,80,30);
b4.setBounds(210,110,60,30);
l3.setBounds(10,150,100,30);
t2.setBounds(120,150,205,30);
l4.setBounds(10,190,100,30);
t3.setBounds(120,190,205,30);
l5.setBounds(10,230,100,30);
ta1.setBounds(120,230,205,70);
p4.setBounds(10,300,320,250);
b1.setBounds(20,550,90,40);
b2.setBounds(120,550,90,40);
b3.setBounds(220,550,90,40);
// p4.setBackground(Color.blue);
p4.setLayout(new GridLayout(10,2));
l6=new JLabel("Please Select the Course of the Student");
p4.add(l6);
hello();
r1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{

l1.setText("Insert New Student");


b1.setText("Insert");
setTitle("New Student");
b4.setVisible(false);
b1.setEnabled(true);
}});
r2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
l1.setText("Update Existing Student");
b1.setText("Update");
setTitle("Update Student");
b4.setVisible(true);
b1.setEnabled(false);
}
});
r3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
l1.setText("Delete Student");
b1.setText("Delete");
setTitle("Delete Student");
b4.setVisible(true);
b1.setEnabled(false);
}
});
addWindowListener(new WindowAdapter(){
public void windowActivated(WindowEvent we)
{
t1.requestFocus();
}
});
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==b1)
{
String s1=new String(b1.getText());
String s01=new String(t1.getText());
String s02=new String(t2.getText());
String s04=new String(t3.getText());
String s05=new String(ta1.getText());
String s021="";
String s022="";
for(int i=0,st=0;i<s02.length();i++)

{
if(s02.charAt(i)==32)
{
st=1;
}
if(st==1)
{
s022=s022+s02.charAt(i);
}
else
{
s021=s021+s02.charAt(i);
}
}
if(s1.equals("Insert"))
{
System.out.println("Insertion Successful");
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String
dataSourceName
"ClassManagementSystem";
String
dbURL
=
"jdbc:odbc:"
dataSourceName;
Connection
con
DriverManager.getConnection(dbURL, "","");

=
+
=

PreparedStatement
ps=con.prepareStatement("insert into Student values (?,?,?,?,?)");
ps.setString(1,s01);
ps.setString(2,s021);
ps.setString(3,s022);
ps.setString(4,s04);
ps.setString(5,s05);
ps.executeUpdate();
// JOptionPane jp=new JOptionPane();
//
JDialog
dg=new
jp.createDialog("Successful");
// dg.setAlwaysOnTop(true);
// dg.setVisible(true);
// jp.setAlwaysOnTop(true);
ps.close();
con.close();

JOptionPane jp=new JOptionPane();


jp.showMessageDialog(null,"Data
Insertion
Successfully");
t1.setText("");
t2.setText("");
t3.setText("");
ta1.setText("");
}
catch(Exception e)
{
}

try
{
for(int i=0;i<rowcount;i++)
{
if(cb[i].isSelected())
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String
dataSourceName
"ClassManagementSystem";
String dbURL = "jdbc:odbc:"
dataSourceName;
Connection
con
DriverManager.getConnection(dbURL, "","");

=
+
=

String
sx=new
String(cb[i].getLabel().replaceAll("( )+",""));
PreparedStatement
ps1=con.prepareStatement("insert into StudentCourse values (?,?)");
ps1.setString(1,s01);
ps1.setString(2,sx);
ps1.executeUpdate();
}
}
}
catch(Exception e)
{
}
}
else if(s1.equals("Update"))

{
System.out.println("Updation Successful");
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String
dataSourceName
"ClassManagementSystem";
String
dbURL
=
"jdbc:odbc:"
dataSourceName;
Connection
con
DriverManager.getConnection(dbURL, "","");
PreparedStatement
ps=con.prepareStatement("update
Student
FName=?,LName=?,Mobile=?,Address=? where SID='"+s01+"'");

=
+
=

set

ps.setString(1,s021);
ps.setString(2,s022);
ps.setString(3,s04);
ps.setString(4,s05);
ps.executeUpdate();
JOptionPane jp=new JOptionPane();
jp.showMessageDialog(null,"Data

Updated

Successfully");
t1.setText("");
t2.setText("");
t3.setText("");
ta1.setText("");
ps.close();
con.close();
}
catch(Exception e)
{
}
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String
dataSourceName
"ClassManagementSystem";
String
dbURL
=
"jdbc:odbc:"
dataSourceName;

=
+

Connection
DriverManager.getConnection(dbURL, "","");

con

PreparedStatement
ps=con.prepareStatement("delete StudentCourse where SID=?");
ps.setString(1,s01);
ps.executeUpdate();
ps.close();
con.close();
}
catch(Exception e)
{
}
try
{
for(int i=0;i<rowcount;i++)
{
if(cb[i].isSelected())
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String
dataSourceName
"ClassManagementSystem";
String dbURL = "jdbc:odbc:"
dataSourceName;
Connection
con
DriverManager.getConnection(dbURL, "","");

=
+
=

String
sx=new
String(cb[i].getLabel().replaceAll("( )+",""));
PreparedStatement
ps1=con.prepareStatement("insert into StudentCourse values (?,?)");
ps1.setString(1,s01);
ps1.setString(2,sx);
ps1.executeUpdate();
System.out.print("Value
Gayi"+s01+sx);
}
}
}
catch(Exception e)
{

}
}
else if(s1.equals("Delete"))
{
s01=new String(t1.getText());
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String
dataSourceName
"ClassManagementSystem";
String
dbURL
=
"jdbc:odbc:"
dataSourceName;
Connection
con
DriverManager.getConnection(dbURL, "","");

=
+
=

PreparedStatement
ps=con.prepareStatement("delete StudentCourse where SID=?");
ps.setString(1,s01);
ps.executeUpdate();
ps.close();
con.close();
}
catch(Exception e)
{
}
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String
dataSourceName
"ClassManagementSystem";
String
dbURL
=
"jdbc:odbc:"
dataSourceName;
Connection
con
DriverManager.getConnection(dbURL, "","");
PreparedStatement
ps=con.prepareStatement("delete Student where SID=?");
ps.setString(1,s01);
ps.executeUpdate();
JOptionPane jp=new JOptionPane();

=
+
=

jp.showMessageDialog(null,"Data

Deletion

Successfully");
// jp.setAlwaysOnTop(true);
t1.setText("");
t2.setText("");
t3.setText("");
ta1.setText("");
}
catch(Exception e)
{
}
}
clear();
System.out.println("Student ID : "+s01);
System.out.println("First Name : "+s021);
System.out.println("Last Name : "+s022);
System.out.println("Mobile No : "+s04);
System.out.println("Address : "+s05);
}
if(ae.getSource()==b2)
{
t1.setText("");
t2.setText("");
t3.setText("");
ta1.setText("");
clear();
selection(1);
}
if(ae.getSource()==b3)
{
dispose();
}
if(ae.getSource()==b4)
{
String s01=new String(t1.getText());
int status=0;
clear();
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String dataSourceName = "ClassManagementSystem";
String dbURL = "jdbc:odbc:" + dataSourceName;
Connection
con
=
DriverManager.getConnection(dbURL, "","");

Statement ps=con.createStatement();
ps.execute("select
FName,LName,Mobile,Address
from Student where SID='"+s01+"'");
ResultSet rs=ps.getResultSet();
while ( rs.next() )
{
t2.setText((""+(rs.getString(1))+"
"+
(rs.getString(2))).replaceAll("( )+",""));
t3.setText(""+
(rs.getString(3)).replaceAll("( )+",""));
ta1.setText(""+
(rs.getString(4)).replaceAll("( )+",""));
status=1;
b1.setEnabled(true);
}
ps.close();
con.close();
}
catch(Exception e)
{
}
if(status==0)
{
JOptionPane jp=new JOptionPane();
jp.showMessageDialog(null,"Invalid
Information\nPlease Check the ID");
b1.setEnabled(false);
t1.setText("");
t2.setText("");
t3.setText("");
ta1.setText("");
}
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String dataSourceName = "ClassManagementSystem";
String dbURL = "jdbc:odbc:" + dataSourceName;
Connection
con
=
DriverManager.getConnection(dbURL, "","");
Statement ps=con.createStatement();
ps.execute("select CID from StudentCourse where
SID='"+s01+"'");

ResultSet rs=ps.getResultSet();
if(rs!=null)
while ( rs.next() )
{
String
fromdb=new
String((rs.getString(1)).replaceAll("( )+",""));
System.out.print("From Db : "+fromdb);
tictac(fromdb);
}
}
catch(Exception e)
{
System.out.print(""+e.getMessage());
}
}
}
public void tictac(String string)
{
for(int i=0;i<rowcount;i++)
{
if(cb[i].getLabel().equals(string))
{
cb[i].setSelected(true);
break;
}
}
}
public void clear()
{
for(int i=0;i<rowcount;i++)
{
cb[i].setSelected(false);
}
}
public void selection(int i)
{
if(i==1)
{
r1.setSelected(true);
l1.setText("Insert New Student");
b1.setText("Insert");
setTitle("New Student");
b4.setVisible(false);
b1.setEnabled(true);

}
else if(i==2)
{
r2.setSelected(true);
l1.setText("Update Existing Student");
b1.setText("Update");
setTitle("Update Student");
b4.setVisible(true);
b1.setEnabled(false);
}
else if(i==3)
{
r3.setSelected(true);
l1.setText("Delete Student");
b1.setText("Delete");
setTitle("Delete Student");
b4.setVisible(true);
b1.setEnabled(false);
}
else
{
selection(1);
}
}
public void hello()
{
rowcount=0;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String dataSourceName = "ClassManagementSystem";
String dbURL = "jdbc:odbc:" + dataSourceName;
Connection con = DriverManager.getConnection(dbURL,
"","");
Statement s = con.createStatement();
s.execute("select UnitName from Class");
ResultSet rs = s.getResultSet();
if(rs !=null)
while ( rs.next() )
{
System.out.println("hello : "+(rs.getString(1)));
rowcount++;
}

System.out.println("Total No of Rows : "+rowcount);


}
catch(Exception e)
{
System.out.println(""+e.getMessage());
}
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String dataSourceName = "ClassManagementSystem";
String dbURL = "jdbc:odbc:" + dataSourceName;
Connection con = DriverManager.getConnection(dbURL,
"","");
Statement s = con.createStatement();
s.execute("select CID from Class");
ResultSet rs = s.getResultSet();
cb=new JCheckBox[rowcount];
int i=0;
if(rs !=null)
while (
rs.next() )
{
String
String(""+rs.getString(1).replaceAll("( )+",""));
cb[i]=new JCheckBox(s1);
p4.add(cb[i]);
System.out.println("Item "+i+" Added");
i++;
}
}
catch(Exception e)
{
System.out.println(""+e.getMessage());
}
}
// public static void main(String []args)
// {
// studentForm sF=new studentForm();
// sF.selection(1);
// }
}

s1=new

/***********************************Class
From*********************************/
package myPackage;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
public class classForm extends JDialog implements ActionListener
{
JPanel p1,p2,p3;
JLabel l0,l1,l2,l3,l4,l5;
JTextField t1,t2,t3,t4;
JButton b1,b2,b3,b4;
JRadioButton r1,r2,r3;
ButtonGroup bg1;
public classForm()
{
p1=new JPanel();
p2=new JPanel();
p3=new JPanel();
getContentPane().add(p1);
setSize(350,400);
// setLocationRelativeTo(null);
setLocation(10,100);
setVisible(true);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setAlwaysOnTop(true);
setTitle("Class");
setResizable(false);
l0=new
l1=new
l2=new
l3=new
l4=new

JLabel("Please Select");
JLabel("Class");
JLabel("Class ID");
JLabel("Unit Code");
JLabel("Unit Name");

t1=new JTextField(20);
t2=new JTextField(20);
t3=new JTextField(20);
l1.setFont(new
t1.setFont(new
t2.setFont(new
t3.setFont(new

Font("Cambria",Font.BOLD,24));
Font("Cambria",Font.BOLD,20));
Font("Cambria",Font.BOLD,18));
Font("Cambria",Font.BOLD,18));

b1=new
b2=new
b3=new
b4=new

JButton("Insert");
JButton("Reset");
JButton("Cancel");
JButton("Find");

b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
r1=new JRadioButton("New Class");
r2=new JRadioButton("Update Class");
r3=new JRadioButton("Delete Class");
bg1=new ButtonGroup();
bg1.add(r1);
bg1.add(r2);
bg1.add(r3);
// p1.setBackground(Color.blue);
// p2.setBackground(Color.red);
// p3.setBackground(Color.green);
p1.setLayout(new BorderLayout());
p3.setLayout(null);
p1.add(p2,BorderLayout.NORTH);
p1.add(p3,BorderLayout.CENTER);
p2.add(l1);
p3.add(
p3.add(
p3.add(
p3.add(
p3.add(
p3.add(
p3.add(
p3.add(
p3.add(
p3.add(

l0);
r1);
r2);
r3);
l2);
t1);
l3);
t2);
l4);
t3);

p3.add( b1);
p3.add( b2);

p3.add( b3);
p3.add( b4);
l0.setBounds(10,10,100,30);
r1.setBounds(120,10,150,30);
r2.setBounds(120,40,150,30);
r3.setBounds(120,70,150,30);
l2.setBounds(10,110,100,30);
t1.setBounds(120,110,80,30);
l3.setBounds(10,150,100,30);
t2.setBounds(120,150,205,30);
l4.setBounds(10,190,100,30);
t3.setBounds(120,190,205,30);
b1.setBounds(20,250,90,40);
b2.setBounds(120,250,90,40);
b3.setBounds(220,250,90,40);
b4.setBounds(210,110,60,30);
r1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
l1.setText("Insert New Class");
b1.setText("Insert");
setTitle("New Class");
b4.setVisible(false);
b1.setEnabled(true);
}});
r2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
l1.setText("Update Existing Class");
b1.setText("Update");
setTitle("Update Class");
b4.setVisible(true);
b1.setEnabled(false);
}
});
r3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
l1.setText("Delete Class");
b1.setText("Delete");
setTitle("Delete Class");

b4.setVisible(true);
b1.setEnabled(false);
}
});
addWindowListener(new WindowAdapter(){
public void windowActivated(WindowEvent we)
{
t1.requestFocus();
}
});
selection(1);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==b1)
{
String s1=new String(b1.getText());
String s01=new String(t1.getText());
String s02=new String(t2.getText());
String s03=new String(t3.getText());
if(s1.equals("Insert"))
{
System.out.println("Insertion Successful");
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String
dataSourceName
"ClassManagementSystem";
String
dbURL
=
"jdbc:odbc:"
dataSourceName;
Connection
con
DriverManager.getConnection(dbURL, "","");

=
+
=

PreparedStatement
ps=con.prepareStatement("insert
into
Class
(CID,UnitCode,UnitName)
values (?,?,?)");
ps.setString(1,s01);
ps.setString(2,s02);
ps.setString(3,s03);
ps.executeUpdate();
JOptionPane jp=new JOptionPane();
jp.showMessageDialog(null,"Data
Insertion
Successfully");
t1.setText("");

t2.setText("");
t3.setText("");
}
catch(Exception e)
{
}
}
else if(s1.equals("Update"))
{
System.out.println("Updation Successful");
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String
dataSourceName
"ClassManagementSystem";
String
dbURL
=
"jdbc:odbc:"
dataSourceName;
Connection
con
DriverManager.getConnection(dbURL, "","");

=
+
=

PreparedStatement
ps=con.prepareStatement("update Class set UnitCode=?,UnitName=? where
CID='"+s01+"'");
ps.setString(1,s02);
ps.setString(2,s03);
ps.executeUpdate();
JOptionPane jp=new JOptionPane();
jp.showMessageDialog(null,"Data
Successfully");
t1.setText("");
t2.setText("");
t3.setText("");
}
catch(Exception e)
{
}
}
else if(s1.equals("Delete"))
{
System.out.println("Deletion Successful");

Updated

s01=new String(t1.getText());
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String
dataSourceName
"ClassManagementSystem";
String
dbURL
=
"jdbc:odbc:"
dataSourceName;
Connection
con
DriverManager.getConnection(dbURL, "","");
PreparedStatement
ps=con.prepareStatement("delete Class where CID=?");
ps.setString(1,s01);
ps.executeUpdate();
JOptionPane jp=new JOptionPane();
jp.showMessageDialog(null,"Data
Successfully");
t1.setText("");
t2.setText("");
t3.setText("");
}
catch(Exception e)
{
}
}
System.out.println("Class ID : "+s01);
System.out.println("Unit Code : "+s02);
System.out.println("Unit Name : "+s03);
}
if(ae.getSource()==b2)
{
t1.setText("");
t2.setText("");
t3.setText("");
selection(1);
hello();
}
if(ae.getSource()==b3)
{
dispose();
}
if(ae.getSource()==b4)

=
+
=

Deletion

{
String s01=new String(t1.getText());
int status=0;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String dataSourceName = "ClassManagementSystem";
String dbURL = "jdbc:odbc:" + dataSourceName;
Connection
con
=
DriverManager.getConnection(dbURL, "","");
Statement ps=con.createStatement();
ps.execute("select UnitCode,UnitName
where CID='"+s01+"'");
ResultSet rs=ps.getResultSet();
while ( rs.next() )
{
t2.setText((""+
(rs.getString(1)).replaceAll("( )+","")));
t3.setText((""+
(rs.getString(2)).replaceAll("( )+","")));
status=1;
b1.setEnabled(true);
}
}
catch(Exception e)
{
}
if(status==0)
{
JOptionPane jp=new JOptionPane();
jp.showMessageDialog(null,"Invalid
Information\nPlease Check the ID");
b1.setEnabled(false);
t2.setText("");
t3.setText("");
}
}
}
public void hello()
{
try
{

from

Class

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String dataSourceName = "ClassManagementSystem";
String dbURL = "jdbc:odbc:" + dataSourceName;
Connection con = DriverManager.getConnection(dbURL,
"","");
Statement s = con.createStatement();
s.execute("select UnitName from Class");
ResultSet rs = s.getResultSet();
int rowcount=0;
if(rs !=null)
while ( rs.next() )
{
System.out.println("hello : "+(rs.getString(1)));
rowcount++;
}
System.out.println("Total No of Rows : "+rowcount);
}
catch(Exception e)
{
}
}
public void selection(int i)
{
if(i==1)
{
r1.setSelected(true);
l1.setText("Insert New Class");
b1.setText("Insert");
setTitle("New Class");
b4.setVisible(false);
b1.setEnabled(true);
}
else if(i==2)
{
r2.setSelected(true);
l1.setText("Update Existing Class");
b1.setText("Update");
setTitle("Update Class");
b4.setVisible(true);
b1.setEnabled(false);
}
else if(i==3)
{

r3.setSelected(true);
l1.setText("Delete Class");
b1.setText("Delete");
setTitle("Delete Class");
b4.setVisible(true);
b1.setEnabled(false);
}
else
{
selection(1);
}
}
// public static void main(String []args)
// {
// classForm cF=new classForm();
// cF.selection(3);
// }
}
/***************************Lecturer Form*******************/
package myPackage;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
public class lecturerForm extends JDialog implements ActionListener
{
JPanel p1,p2,p3,p4;
JLabel l0,l1,l2,l3,l4,l5,l6;
JTextField t1,t2,t3,t4;
JButton b1,b2,b3,b4;
JRadioButton r1,r2,r3;
ButtonGroup bg1;
JCheckBox cb[];
int rowcount=0;
public lecturerForm()
{
p1=new JPanel();
p2=new JPanel();
p3=new JPanel();
p4=new JPanel();
getContentPane().add(p1);
setSize(350,650);
// setLocationRelativeTo(null);

setLocation(10,100);
setVisible(true);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setAlwaysOnTop(true);
setTitle("Lecturer");
setResizable(false);
l0=new
l1=new
l2=new
l3=new
l4=new
l5=new

JLabel("Please Select");
JLabel("Lecturer");
JLabel("Lecturer ID");
JLabel("Name");
JLabel("Campus");
JLabel("Phone");

t1=new
t2=new
t3=new
t4=new

JTextField(20);
JTextField(20);
JTextField(20);
JTextField(20);

l1.setFont(new
t1.setFont(new
t2.setFont(new
t3.setFont(new
t4.setFont(new
b1=new
b2=new
b3=new
b4=new

Font("Cambria",Font.BOLD,24));
Font("Cambria",Font.BOLD,20));
Font("Cambria",Font.BOLD,18));
Font("Cambria",Font.BOLD,18));
Font("Cambria",Font.BOLD,18));

JButton("Insert");
JButton("Reset");
JButton("Cancel");
JButton("Find");

b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
r1=new JRadioButton("New Lecturer");
r2=new JRadioButton("Update Lecturer");
r3=new JRadioButton("Delete Lecturer");
bg1=new ButtonGroup();
bg1.add(r1);
bg1.add(r2);
bg1.add(r3);
// p1.setBackground(Color.blue);

// p2.setBackground(Color.red);
// p3.setBackground(Color.green);
// p4.setBackground(Color.green);
p1.setLayout(new BorderLayout());
p3.setLayout(null);
p1.add(p2,BorderLayout.NORTH);
p1.add(p3,BorderLayout.CENTER);
p2.add(l1);
p3.add(
p3.add(
p3.add(
p3.add(
p3.add(
p3.add(
p3.add(
p3.add(
p3.add(
p3.add(
p3.add(
p3.add(
p3.add(
p3.add(
p3.add(
p3.add(
p3.add(

l0);
r1);
r2);
r3);
l2);
t1);
l3);
t2);
l4);
t3);
l5);
t4);
b1);
b2);
b3);
b4);
p4);

l0.setBounds(10,10,100,30);
r1.setBounds(110,10,110,30);
r2.setBounds(110,40,120,30);
r3.setBounds(110,70,120,30);
l2.setBounds(10,110,100,30);
t1.setBounds(120,110,80,30);
b4.setBounds(210,110,60,30);
l3.setBounds(10,150,100,30);
t2.setBounds(120,150,205,30);
l4.setBounds(10,190,100,30);
t3.setBounds(120,190,205,30);
l5.setBounds(10,230,100,30);
t4.setBounds(120,230,205,30);

p4.setBounds(10,270,320,250);
b1.setBounds(20,520,90,40);
b2.setBounds(120,520,90,40);
b3.setBounds(220,520,90,40);

p4.setLayout(new GridLayout(10,2));
l6=new JLabel("Please Select the Course of the Student");
p4.add(l6);
valuefromdb();
r1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
l1.setText("Insert New Lecturer");
b1.setText("Insert");
setTitle("New Lecturer");
b4.setVisible(false);
b1.setEnabled(true);
}});
r2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
l1.setText("Update Existing Lecturer");
b1.setText("Update");
setTitle("Update Lecturer");
b4.setVisible(true);
b1.setEnabled(false);
}
});
r3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
l1.setText("Delete Lecturer");
b1.setText("Delete");
setTitle("Delete Lecturer");
b4.setVisible(true);
b1.setEnabled(false);
}
});
addWindowListener(new WindowAdapter(){
public void windowActivated(WindowEvent we)
{

t1.requestFocus();
}
});
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==b1)
{
String s1=new String(b1.getText());
String s01=new String(t1.getText());
String s02=new String(t2.getText());
String s03=new String(t3.getText());
String s04=new String(t4.getText());
String s021="";
String s022="";
for(int i=0,st=0;i<s02.length();i++)
{
if(s02.charAt(i)==32)
{
st=1;
}
if(st==1)
{
s022=s022+s02.charAt(i);
}
else
{
s021=s021+s02.charAt(i);
}
}
if(s1.equals("Insert"))
{
System.out.println("Insertion Successful");
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String
dataSourceName
"ClassManagementSystem";
String
dbURL
=
"jdbc:odbc:"
dataSourceName;
Connection
con
DriverManager.getConnection(dbURL, "","");

=
+
=

PreparedStatement
ps=con.prepareStatement("insert into Lecturer values (?,?,?,?,?)");
ps.setString(1,s01);
ps.setString(2,s021);
ps.setString(3,s022);
ps.setString(4,s03);
ps.setString(5,s04);
ps.executeUpdate();
ps.close();
con.close();
JOptionPane jp=new JOptionPane();
jp.showMessageDialog(null,"Data
Insertion
Successfully");
t1.setText("");
t2.setText("");
t3.setText("");
t4.setText("");
}
catch(Exception e)
{
}
try
{
for(int i=0;i<rowcount;i++)
{
if(cb[i].isSelected())
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String
dataSourceName
"ClassManagementSystem";
String dbURL = "jdbc:odbc:"
dataSourceName;
Connection
con
DriverManager.getConnection(dbURL, "","");

=
+
=

String
sx=new
String(cb[i].getLabel().replaceAll("( )+",""));
PreparedStatement
ps1=con.prepareStatement("update Class set LID=? where CID='"+sx+"'");
ps1.setString(1,s01);

ps1.executeUpdate();
}
}
}
catch(Exception e)
{
}
}
else if(s1.equals("Update"))
{
System.out.println("Updation Successful");
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String
dataSourceName
"ClassManagementSystem";
String
dbURL
=
"jdbc:odbc:"
dataSourceName;
Connection
con
DriverManager.getConnection(dbURL, "","");
PreparedStatement
ps=con.prepareStatement("update
Lecturer
FName=?,LName=?,Campus=?,Phone=? where LID='"+s01+"'");

=
+
=

set

ps.setString(1,s021);
ps.setString(2,s022);
ps.setString(3,s03);
ps.setString(4,s04);
ps.executeUpdate();
JOptionPane jp=new JOptionPane();
jp.showMessageDialog(null,"Data
Successfully");
t1.setText("");
t2.setText("");
t3.setText("");
t4.setText("");
}
catch(Exception e)
{
}

Updated

try
{
for(int i=0;i<rowcount;i++)
{
if(cb[i].isSelected())
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String
dataSourceName
"ClassManagementSystem";
String dbURL = "jdbc:odbc:"
dataSourceName;
Connection
con
DriverManager.getConnection(dbURL, "","");

=
+
=

String
sx=new
String(cb[i].getLabel().replaceAll("( )+",""));
PreparedStatement
ps1=con.prepareStatement("update Class set LID=? where CID='"+sx+"'");
ps1.setString(1,s01);
ps1.executeUpdate();
}
}
}
catch(Exception e)
{
}
}
else if(s1.equals("Delete"))
{
s01=new String(t1.getText());
System.out.println("Deletion : "+s01);
try
{
for(int i=0;i<rowcount;i++)
{
if(cb[i].isSelected())
{
System.out.println("yyyyyyyyyyyy");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

String

dataSourceName

"ClassManagementSystem";
String

dbURL

"jdbc:odbc:"

dataSourceName;
Connection
DriverManager.getConnection(dbURL, "","");

con

String
String(cb[i].getLabel().replaceAll("( )+",""));

sx=new

System.out.println("jkajd"+sx+"dfsf");
//
PreparedStatement
ps1=con.prepareStatement("update Class set LID=? where CID='"+sx+"'");
PreparedStatement
ps1=con.prepareStatement("update Class set LID=? where CID=?");
ps1.setString(1,null);
ps1.setString(2,sx);
ps1.executeUpdate();
}
}
}
catch(Exception e)
{
System.out.println(""+e.getMessage());
}
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String
dataSourceName
"ClassManagementSystem";
String
dbURL
=
"jdbc:odbc:"
dataSourceName;
Connection
con
DriverManager.getConnection(dbURL, "","");
PreparedStatement
ps=con.prepareStatement("delete Lecturer where LID=?");
ps.setString(1,s01);
ps.executeUpdate();
JOptionPane jp=new JOptionPane();
jp.showMessageDialog(null,"Data
Successfully");
t1.setText("");

=
+
=

Deletion

t2.setText("");
t3.setText("");
t4.setText("");
}
catch(Exception e)
{
System.out.println(""+e.getMessage());
}
}
System.out.println("Lecturer ID : "+s01);
System.out.println("First Name : "+s021);
System.out.println("Last Name : "+s022);
System.out.println("Campus : "+s03);
System.out.println("Phone : "+s04);
}
if(ae.getSource()==b2)
{
t1.setText("");
t2.setText("");
t3.setText("");
t4.setText("");
selection(1);
}
if(ae.getSource()==b3)
{
dispose();
}
if(ae.getSource()==b4)
{
String s01=new String(t1.getText());
int status=0;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String dataSourceName = "ClassManagementSystem";
String dbURL = "jdbc:odbc:" + dataSourceName;
Connection
con
=
DriverManager.getConnection(dbURL, "","");
Statement ps=con.createStatement();
ps.execute("select FName,LName,Campus,Phone from
Lecturer where LID='"+s01+"'");
ResultSet rs=ps.getResultSet();

while ( rs.next() )
{
t2.setText((""+(rs.getString(1))+
(rs.getString(2))).replaceAll("( )+",""));
t3.setText(""+
(rs.getString(3)).replaceAll("( )+",""));
t4.setText(""+
(rs.getString(4)).replaceAll("( )+",""));
status=1;
b1.setEnabled(true);
}
}
catch(Exception e)
{
}
if(status==0)
{
JOptionPane jp=new JOptionPane();
jp.showMessageDialog(null,"Invalid
Information\nPlease Check the ID");
b1.setEnabled(false);
t2.setText("");
t3.setText("");
t4.setText("");
}
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String dataSourceName = "ClassManagementSystem";
String dbURL = "jdbc:odbc:" + dataSourceName;
Connection
con
=
DriverManager.getConnection(dbURL, "","");
Statement ps=con.createStatement();
ps.execute("select
CID
from
Class

where

LID='"+s01+"'");
ResultSet rs=ps.getResultSet();
if(rs!=null)
while ( rs.next() )
{
String
fromdb=new
String((rs.getString(1)).replaceAll("( )+",""));
System.out.print("From Db : "+fromdb);

tictac(fromdb);
}
}
catch(Exception e)
{
System.out.print(""+e.getMessage());
}
}
}
public void tictac(String string)
{
for(int i=0;i<rowcount;i++)
{
if(cb[i].getLabel().equals(string))
{
cb[i].setSelected(true);
break;
}
}
}
public void selection(int i)
{
if(i==1)
{
r1.setSelected(true);
l1.setText("Insert New Lecturer");
b1.setText("Insert");
setTitle("New Lecturer");
b4.setVisible(false);
b1.setEnabled(true);
}
else if(i==2)
{
r2.setSelected(true);
l1.setText("Update Existing Lecturer");
b1.setText("Update");
setTitle("Update Lecturer");
b4.setVisible(true);
b1.setEnabled(false);
}
else if(i==3)
{
r3.setSelected(true);
l1.setText("Delete Lecturer");

b1.setText("Delete");
setTitle("Delete Lecturer");
b4.setVisible(true);
b1.setEnabled(false);
}
else
{
selection(1);
}
}
public void valuefromdb()
{
rowcount=0;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String dataSourceName = "ClassManagementSystem";
String dbURL = "jdbc:odbc:" + dataSourceName;
Connection con = DriverManager.getConnection(dbURL,
"","");
Statement s = con.createStatement();
s.execute("select UnitName from Class");
ResultSet rs = s.getResultSet();
if(rs !=null)
while ( rs.next() )
{
System.out.println("hello : "+(rs.getString(1)));
rowcount++;
}
System.out.println("Total No of Rows : "+rowcount);
}
catch(Exception e)
{
System.out.println(""+e.getMessage());
}
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String dataSourceName = "ClassManagementSystem";
String dbURL = "jdbc:odbc:" + dataSourceName;

Connection

con

DriverManager.getConnection(dbURL,

"","");
Statement s = con.createStatement();
s.execute("select CID from Class");
ResultSet rs = s.getResultSet();
cb=new JCheckBox[rowcount];
int i=0;
if(rs !=null)
while (
rs.next() )
{
String
s1=new
String(""+rs.getString(1).replaceAll("( )+",""));
cb[i]=new JCheckBox(s1);
p4.add(cb[i]);
System.out.println("Item "+i+" Added");
i++;
}
}
catch(Exception e)
{
System.out.println(""+e.getMessage());
}
}
// public static void main(String []args)
// {
// lecturerForm lF=new lecturerForm();
// lF.selection(3);
// }
}
/**************************Student Report**************************/
package myPackage;
import javax.swing.*;
import java.awt.*;
import java.awt.print.*;
import java.awt.event.*;
import java.sql.*;
public class reportStudent extends JDialog implements ActionListener
{
JPanel p1,p2,p3,p4;
JLabel l0,l1,l2,l3,l4,l5,l6,l7;
JTextField t1,t2,t3,t4,t5;
TextArea ta1;
JButton b1,b2,b3,b4;

JRadioButton r1,r2,r3;
public reportStudent()
{
p1=new JPanel();
p2=new JPanel();
p3=new JPanel();
getContentPane().add(p1);
setSize(450,500);
// setLocationRelativeTo(null);
setLocation(10,100);
setVisible(true);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setAlwaysOnTop(true);
setTitle("Student Report");
setResizable(false);
setLayout(new BorderLayout());
add(p1,BorderLayout.NORTH);
add(p2,BorderLayout.CENTER);
add(p3,BorderLayout.SOUTH);
// p1.setBackground(Color.blue);
// p2.setBackground(Color.red);
// p3.setBackground(Color.green);
l0=new JLabel("Enter the Student ID");
t1=new JTextField(15);
b1=new JButton("Find");
// p1.setLayout(new GridLayout(1,3));
p1.add(l0);
p1.add(t1);
p1.add(b1);
p2.setLayout(new GridLayout(10,1));
l1=new JLabel("Name : ");
l2=new JLabel("Student ID : ");
l3=new JLabel("Mobile : ");
l4=new JLabel("Total Subjects : ");
l1.setFont(new
l2.setFont(new
l3.setFont(new
l4.setFont(new

Font("Cambria",Font.BOLD,24));
Font("Cambria",Font.BOLD,24));
Font("Cambria",Font.BOLD,24));
Font("Cambria",Font.BOLD,24));

p2.add(l1);
p2.add(l2);
p2.add(l3);
p2.add(l4);
b2=new JButton("Print");
b3=new JButton("Reset");
b4=new JButton("Cancel");
p3.add(b2);
p3.add(b3);
p3.add(b4);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==b1)
{
String s01=new String(t1.getText());
int status=0;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String dataSourceName = "ClassManagementSystem";
String dbURL = "jdbc:odbc:" + dataSourceName;
Connection
con
=
DriverManager.getConnection(dbURL, "","");
Statement ps=con.createStatement();
ps.execute("select
FName,LName,Mobile,Address
from Student where SID='"+s01+"'");
ResultSet rs=ps.getResultSet();
while ( rs.next() )
{
l1.setText(("Name
:
"+(rs.getString(1))+
(rs.getString(2))).replaceAll("( )+",""));
l2.setText("Student ID : "+s01);
l3.setText("Mobile
:
"+
(rs.getString(3)).replaceAll("( )+",""));
status=1;

b1.setEnabled(true);
}
ps.close();
con.close();
}
catch(Exception e)
{
}
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String dataSourceName = "ClassManagementSystem";
String dbURL = "jdbc:odbc:" + dataSourceName;
Connection
con
=
DriverManager.getConnection(dbURL, "","");
Statement ps=con.createStatement();
ps.execute("select COUNT(*) from myreport where
SID='"+s01+"'");
ResultSet rs=ps.getResultSet();
while ( rs.next() )
{
l4.setText("Total
Subjects
(rs.getString(1)).replaceAll("( )+",""));
}
ps.close();
con.close();
}
catch(Exception e)
{
}
if(status==0)
{
JOptionPane jp=new JOptionPane();
jp.showMessageDialog(null,"Invalid
Information\nPlease Check the ID");
l1.setText("Name : ");
l2.setText("Student ID : ");
l3.setText("Mobile : ");
l4.setText("Total Subjects : ");
}
p2.repaint();
}

"+

if(ae.getSource()==b2)
{
printComponenet();
}
if(ae.getSource()==b3)
{
l1.setText("Name : ");
l2.setText("Student ID : ");
l3.setText("Mobile : ");
l4.setText("Total Subjects : ");
t1.setText("");
}
if(ae.getSource()==b4)
{
dispose();
}
}
public void printComponenet()
{
PrinterJob job = PrinterJob.getPrinterJob();
job.setJobName("p2");
job.setPrintable (new Printable()
{
public int print(Graphics

pg,

PageFormat

pageNum)
{
if (pageNum > 0)
{
return Printable.NO_SUCH_PAGE;
}
Graphics2D g2 = (Graphics2D) pg;
g2.translate(pf.getImageableX(),
pf.getImageableY());
p2.paint(g2);
return Printable.PAGE_EXISTS;
}
});
boolean ok = job.printDialog();
if (ok)
{
try
{

pf,

int

job.print();
}
catch (PrinterException ex)
{
}
}
}
// public static void main(String []args)
// {
// new reportStudent();
// }
}
/********************Main Form*********************/
import myPackage.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import javax.swing.UIManager.LookAndFeelInfo;
import javax.swing.UnsupportedLookAndFeelException;
public
class
mainForm
extends
JFrame
implements
ActionListener,MouseListener
{
JMenuBar mb1;
JToolBar tb1;
JMenu m1,m2,m3,m4,m5,m6,m7;
JMenuItem
mi11,mi12,mi21,mi22,mi23,mi31,mi32,mi33,mi41,mi42,mi43,mi51,mi52,mi71;
JButton b11,b21,b22,b23,b31,b32,b33,b41,b42,b43,b51;
ButtonGroup b1;
String look;
JFrame f1;
JPanel p1;
JLabel ll1,ll2,ll3,ll4,ll5,ll6,ll7;
JTextField tf1;
JPasswordField pf1;
public mainForm()
{
setExtendedState(Frame.MAXIMIZED_BOTH);
setSize(800,600);
setLocationRelativeTo(null);
setVisible(true);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setAlwaysOnTop(false);
setTitle("Class Management System");
setResizable(true);
setLayout(new BorderLayout());

setIconImage(Toolkit.getDefaultToolkit().getImage("images/student.png"
));
setVisible(false);
loginForm();
mb1=new JMenuBar();
m1=new
m2=new
m3=new
m4=new
m5=new
m6=new
m7=new

JMenu("Application");
JMenu("Student");
JMenu("Class");
JMenu("Lecturer");
JMenu("Look & Feel");
JMenu("Help");
JMenu("Report");

mi11=new JMenuItem("Exit",new ImageIcon("images/exit.png"));


mi21=new
JMenuItem("New
Student",new
ImageIcon("images/submit.png"));
mi22=new
JMenuItem("Update
Student",new
ImageIcon("images/reset.png"));
mi23=new
JMenuItem("Delete
Student",new
ImageIcon("images/cancel.png"));
mi31=new
JMenuItem("New
Class",new
ImageIcon("images/Submit.png"));
mi32=new
JMenuItem("Update
Class",new
ImageIcon("images/reset.png"));
mi33=new
JMenuItem("Delete
Class",new
ImageIcon("images/cancel.png"));
mi41=new
JMenuItem("New
Lecturer",new
ImageIcon("images/Submit.png"));
mi42=new
JMenuItem("Update
Lecturer",new
ImageIcon("images/reset.png"));
mi43=new
JMenuItem("Delete
Lecturer",new
ImageIcon("images/cancel.png"));
mi71=new
ImageIcon("images/printer.png"));

JMenuItem("Student",new

mb1.add(m1);
mb1.add(m2);
mb1.add(m3);
mb1.add(m4);
mb1.add(m7);
mb1.add(Box.createHorizontalGlue());
mb1.add(m5);
// mb1.add(m6);
m1.add(mi11);
m2.add(mi21);
m2.add(mi22);
m2.add(mi23);
m3.add(mi31);
m3.add(mi32);
m3.add(mi33);
m4.add(mi41);
m4.add(mi42);
m4.add(mi43);
m7.add(mi71);
setJMenuBar(mb1);
tb1=new JToolBar();
// tb1.setFloatable(false);
b11=new JButton(new ImageIcon("images/exit.png"));
b21=new JButton(new ImageIcon("images/submit.png"));
b22=new JButton(new ImageIcon("images/reset.png"));
b23=new JButton(new ImageIcon("images/cancel.png"));
b31=new JButton(new ImageIcon("images/Submit.png"));
b32=new JButton(new ImageIcon("images/reset.png"));
b33=new JButton(new ImageIcon("images/cancel.png"));
b41=new JButton(new ImageIcon("images/Submit.png"));
b42=new JButton(new ImageIcon("images/reset.png"));
b43=new JButton(new ImageIcon("images/cancel.png"));
b51=new JButton(new ImageIcon("images/printer.png"));
b11.setToolTipText("Quit Application");
b21.setToolTipText("Insert New Student");
b22.setToolTipText("Update Existing Student");
b23.setToolTipText("Delete Student");

b31.setToolTipText("Insert New Class");


b32.setToolTipText("Update Existing Class");
b33.setToolTipText("Delete Class");
b41.setToolTipText("Insert New Lecturer");
b42.setToolTipText("Update Existing Lecturer");
b43.setToolTipText("Delete Lecturer");
b51.setToolTipText("Student Report");
tb1.add(b11);
tb1.addSeparator();
tb1.add(new JLabel("Student"));
tb1.add(b21);
tb1.add(b22);
tb1.add(b23);
tb1.addSeparator();
tb1.add(new JLabel("Class"));
tb1.add(b31);
tb1.add(b32);
tb1.add(b33);
tb1.addSeparator();
tb1.add(new JLabel("Lecturer"));
tb1.add(b41);
tb1.add(b42);
tb1.add(b43);
tb1.addSeparator();
tb1.add(new JLabel("Report"));
tb1.add(b51);
this.add(tb1,BorderLayout.NORTH);
mi11.addActionListener(this);
mi21.addActionListener(this);
mi22.addActionListener(this);
mi23.addActionListener(this);
mi31.addActionListener(this);
mi32.addActionListener(this);
mi33.addActionListener(this);
mi41.addActionListener(this);
mi42.addActionListener(this);
mi43.addActionListener(this);
mi71.addActionListener(this);
b11.addActionListener(this);
b21.addActionListener(this);
b22.addActionListener(this);
b23.addActionListener(this);
b31.addActionListener(this);

b32.addActionListener(this);
b33.addActionListener(this);
b41.addActionListener(this);
b42.addActionListener(this);
b43.addActionListener(this);
manageLookAndFeels();

mi21.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.
KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_MASK));

mi22.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.
KeyEvent.VK_S,
java.awt.event.InputEvent.ALT_MASK
|
java.awt.event.InputEvent.CTRL_MASK));

mi23.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.
KeyEvent.VK_S,
java.awt.event.InputEvent.SHIFT_MASK
|
java.awt.event.InputEvent.CTRL_MASK));

mi31.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.
KeyEvent.VK_C, java.awt.event.InputEvent.CTRL_MASK));

mi32.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.
KeyEvent.VK_C,
java.awt.event.InputEvent.ALT_MASK
|
java.awt.event.InputEvent.CTRL_MASK));

mi33.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.
KeyEvent.VK_C,
java.awt.event.InputEvent.SHIFT_MASK
|
java.awt.event.InputEvent.CTRL_MASK));

mi41.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.
KeyEvent.VK_L, java.awt.event.InputEvent.CTRL_MASK));

mi42.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.
KeyEvent.VK_L,
java.awt.event.InputEvent.ALT_MASK
|
java.awt.event.InputEvent.CTRL_MASK));

mi43.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.
KeyEvent.VK_L,
java.awt.event.InputEvent.SHIFT_MASK
|
java.awt.event.InputEvent.CTRL_MASK));

mi11.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.
KeyEvent.VK_F4, java.awt.event.InputEvent.ALT_MASK));

mi71.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.
KeyEvent.VK_T, java.awt.event.InputEvent.CTRL_MASK));
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==mi11||ae.getSource()==b11)
{
System.exit(0);
}
if(ae.getSource()==mi21||ae.getSource()==b21)
{
studentForm sF=new studentForm();
sF.selection(1);
}
if(ae.getSource()==mi22||ae.getSource()==b22)
{
studentForm sF=new studentForm();
sF.selection(2);
}
if(ae.getSource()==mi23||ae.getSource()==b23)
{
studentForm sF=new studentForm();
sF.selection(3);
}
if(ae.getSource()==mi31||ae.getSource()==b31)
{
classForm cF=new classForm();
cF.selection(1);
}
if(ae.getSource()==mi32||ae.getSource()==b32)
{
classForm cF=new classForm();

cF.selection(2);
}
if(ae.getSource()==mi33||ae.getSource()==b33)
{
classForm cF=new classForm();
cF.selection(3);
}
if(ae.getSource()==mi41||ae.getSource()==b41)
{
lecturerForm lF=new lecturerForm();
lF.selection(1);
}
if(ae.getSource()==mi42||ae.getSource()==b42)
{
lecturerForm lF=new lecturerForm();
lF.selection(2);
}
if(ae.getSource()==mi43||ae.getSource()==b43)
{
lecturerForm lF=new lecturerForm();
lF.selection(3);
}
if(ae.getSource()==mi71)
{
new reportStudent();
}
}
public void mouseClicked(MouseEvent ae){}
public void mouseEntered(MouseEvent ae) {}
public void mousePressed(MouseEvent ae)
{
// System.out.println("ID : "+tf1.getText());
// System.out.println("ID : "+pf1.getText());
if(tf1.getText().equals("Admin")
pf1.getText().equals("admin"))
{
ll3.setVisible(true);
ll2.setVisible(false);
}
else
{
JOptionPane.showMessageDialog(null,"Please
Login ID or Password");
}
}

&&

Check

the

public void mouseReleased(MouseEvent ae)


{
if(tf1.getText().equals("Admin")
&&
pf1.getText().equals("admin"))
{
setVisible(true);
f1.setVisible(false);
}
}
public void mouseExited(MouseEvent ae) {}
public void manageLookAndFeels()
{
final
LookAndFeelInfo
lookAndFeelInfo[]=UIManager.getInstalledLookAndFeels();
ButtonGroup lookAndFeelGroup=new ButtonGroup();
for(int i=0;i<lookAndFeelInfo.length;i++)
{
String lookAndFeelName=lookAndFeelInfo[i].getName();
JRadioButtonMenuItem radioButtonMenuItem=new
JRadioButtonMenuItem(lookAndFeelName);
final int j=i;
final JFrame frame=this;
m5.add(radioButtonMenuItem);
lookAndFeelGroup.add(radioButtonMenuItem);
radioButtonMenuItem.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e) {
try {
UIManager.setLookAndFeel(lookAndFeelInfo[j].ge
tClassName());
SwingUtilities.updateComponentTreeUI(frame);
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
} catch (InstantiationException ex) {
ex.printStackTrace();
} catch (IllegalAccessException ex) {
ex.printStackTrace();
} catch (UnsupportedLookAndFeelException ex) {
ex.printStackTrace();
}
}
});
if(lookAndFeelName.equalsIgnoreCase("Metal"))

{
radioButtonMenuItem.setSelected(true);
}
}
}
public void loginForm()
{
f1=new JFrame();
f1.setSize(390,265);
f1.setLocationRelativeTo(null);
f1.setVisible(true);
f1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f1.setAlwaysOnTop(false);
f1.setTitle("Class Management System - Login");
f1.setResizable(false);

f1.setIconImage(Toolkit.getDefaultToolkit().getImage("images/student.p
ng"));
// f1.setUndecorated(true);
// f1.addWindowListener(new WindowAdapter(){
// public void windowActivated(WindowEvent we)
// {
// tf1.requestFocus();
// }
// });
p1=new JPanel();
p1.setLayout(null);
f1.getContentPane().add(p1);
ll1=new
ll2=new
ll3=new
tf1=new
pf1=new

JLabel(new ImageIcon("images/loginpanel.png"));
JLabel(new ImageIcon("images/button.png"));
JLabel(new ImageIcon("images/loading.gif"));
JTextField();
JPasswordField();

p1.add(tf1);
p1.add(pf1);
p1.add(ll2);
p1.add(ll3);
p1.add(ll1);
ll1.setBounds(0,0,383,234);
tf1.setBounds(160,90,200,25);

pf1.setBounds(160,120,200,25);
ll2.setBounds(220,150,150,53);
ll3.setBounds(100,160,200,20);
ll3.setVisible(false);
ll2.addMouseListener(this);
}
public static void main(String []as)
{
new mainForm();
}
}

You might also like