Hostel Allotment System
Login In Java..☺
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class Login extends JFrame implements ActionListener
{
JButton SUBMIT;
JButton Cancel;
//JPanel panel;
JLabel label1,label2;
final JTextField text1,text2;
Login()
{
setLayout(null);
label1 = new JLabel("Username:");
label1.setFont(new Font("Lucida Fax",0,15));
label1.setBounds(50,50,100,100);
text1 = new JTextField(15);
text1.setFont(new Font("Lucida Fax",0,15));
text1.setBounds(150,85,170,30);
label2 = new JLabel("Password:");
label2.setFont(new Font("Lucida Fax",0,15));
label2.setBounds(50,100,100,100);
text2 = new JPasswordField(15);
text2.setFont(new Font("Lucida Fax",0,15));
text2.setBounds(150,135,170,30);
SUBMIT=new JButton("SUBMIT");
//SUBMIT.setFont(new Font("Lucida Fax",0,15));
SUBMIT.setBounds(110,190,80,30);
//SUBMIT.setFont(new Font("Lucida Fax",0,15));
SUBMIT.setBounds(110,190,80,30);
Cancel=new JButton("Cancel");
Cancel.setBounds(220,190,80,30);
Cancel.addActionListener(this);
add(label1);
add(text1);
add(label2);
add(text2);
add(SUBMIT);
add(Cancel);
//add(panel,BorderLayout.CENTER);
SUBMIT.addActionListener(this);
setTitle("LOGIN FORM");
}
public void actionPerformed(ActionEvent ae)
{
String value1=text1.getText();
String value2=text2.getText();
if (value1.equals("Zaheer") && value2.equals("zaheer")) {
dispose();
project obj=new project();
obj.setVisible(true);
obj.setSize(975,680);
obj.setLocation(10,10);
obj.setDefaultCloseOperation(EXIT_ON_CLOSE);
}
if(ae.getSource()==Cancel)
{
System.exit(0);
}
}
}
class Start
{
public static void main(String arg[])
{
try
{
Login frame=new Login();
frame.setSize(400,300);
frame.setLocation(300,200);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
catch(Exception e)
{JOptionPane.showMessageDialog(null, e.getMessage());}
}
}
OUTPUT:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
class project extends JFrame implements ActionListener
{
JButton h,h2,h3,h4,h5,h6,h7;
JLabel lb1,lb2,lb3,lb4,lb5,lb6,lb7,lb8;
JTextField txt,txt1,txt2,txt3,txt4,txt5,txt6,txt7;
JButton Save,Search,Update,Delete,AddNew,Quit;
JButton bu,bu1,bu2,bu3,bu4,bu5;
JLabel images,series,zaheer;
Icon i,j,k,l,m,n,o,q,r;
public project ()
{
JPanel p = new JPanel();
/**********************Label with Images******************************/
images = new JLabel("Choose the Hostle");
images.setFont(new Font("Lucida Fax",0, 21));
images.setForeground(Color.red);
images.setBounds(150,350,800,240);
i = new ImageIcon("1.jpg");
j=new ImageIcon("2.jpg");
k=new ImageIcon("3.jpg");
l=new ImageIcon("4.jpg");
m=new ImageIcon("5.jpg");
n=new ImageIcon("6.jpg");
o=new ImageIcon("7.jpg");
p.add(images);
q = new ImageIcon("8.jpg");
series = new JLabel (q);
series.setBounds(130,440,800,240);
p.add(series);
r = new ImageIcon("9.jpg");
zaheer = new JLabel (r);
zaheer.setBounds(385,480,800,260);
p.add(zaheer);
JLabel lb1 = new JLabel ("Reg No :");
lb1.setForeground(Color.red);
lb1.setBounds(300,60,60,40);
lb1.setFont(new Font("Lucida Fax",0, 21));
p.add(lb1);
/************************Labels And TextFields******************************/
txt = new JTextField (" " ,15);
txt.setBounds(395,60,200,40);
txt.setForeground(Color.red);
txt.setFont(new Font("Lucida Fax",0, 21));
p.add(txt);
JLabel lb2 = new JLabel ("Name :");
lb2.setForeground(Color.red);
lb2.setBounds(300,120,200,40);
lb2.setFont(new Font("Lucida Fax",0, 21));
p.add(lb2);
txt1 = new JTextField (" " ,15);
txt1.setBounds(395,120,200,40);
txt1.setForeground(Color.red);
txt1.setFont(new Font("Lucida Fax",0, 21));
p.add(txt1);
JLabel lb3 = new JLabel ("F-Name:");
lb3.setBounds(300,180,200,40);
lb3.setForeground(Color.red);
lb3.setFont(new Font("Lucida Fax",0, 21));
p.add(lb3);
txt2 = new JTextField (" " ,15);
txt2.setBounds(395,180,200,40);
txt2.setForeground(Color.red);
txt2.setFont(new Font("Lucida Fax",0, 21));
p.add(txt2);
JLabel lb4 = new JLabel ("Cast :");
lb4.setBounds(300,240,200,40);
lb4.setForeground(Color.red);
lb4.setFont(new Font("Lucida Fax",0, 21));
p.add(lb4);
txt3 = new JTextField (" " ,15);
txt3.setBounds(395,240,200,40);
txt3.setForeground(Color.red);
txt3.setFont(new Font("Lucida Fax",0, 21));
p.add(txt3);
lb5 = new JLabel ("Term :");
lb5.setForeground(Color.red);
lb5.setBounds(640,60,200,40);
lb5.setFont(new Font("Lucida Fax",0, 21));
p.add(lb5);
txt4 = new JTextField (" " ,15);
txt4.setBounds(750,60,200,40);
txt4.setForeground(Color.red);
txt4.setFont(new Font("Lucida Fax",0, 21));
p.add(txt4);
lb6 = new JLabel ("Faculty :");
lb6.setForeground(Color.red);
lb6.setBounds(640,120,200,40);
lb6.setFont(new Font("Lucida Fax",0, 21));
p.add(lb6);
txt5 = new JTextField (" " ,15);
txt5.setBounds(750,120,200,40);
txt5.setForeground(Color.red);
txt5.setFont(new Font("Lucida Fax",0, 21));
p.add(txt5);
lb7 = new JLabel ("Address :");
lb7.setBounds(640,180,200,40);
lb7.setForeground(Color.red);
lb7.setFont(new Font("Lucida Fax",0, 21));
p.add(lb7);
txt6 = new JTextField (" " ,15);
txt6.setBounds(750,180,200,40);
txt6.setForeground(Color.red);
txt6.setFont(new Font("Lucida Fax",0, 21));
p.add(txt6);
lb8 = new JLabel ("Phone :");
lb8.setBounds(640,240,200,40);
lb8.setForeground(Color.red);
lb8.setFont(new Font("Lucida Fax",0, 21));
p.add(lb8);
txt7 = new JTextField (" " ,15);
txt7.setBounds(750,240,200,40);
txt7.setForeground(Color.red);
txt7.setFont(new Font("Lucida Fax",0, 21));
p.add(txt7);
/********************* Labels And Buttons**********************/
p.setBackground(Color.black);
p.setLayout(null);
JLabel title = new JLabel ("Hostle Allotment System");
title.setBounds(350,0,400,40);
title.setFont(new Font("Lucida Fax",Font.BOLD, 21));
title.setForeground(Color.yellow);
p.add(title);
JLabel symbol = new JLabel ("----------------------------------------");
symbol.setBounds(350,10,400,40);
symbol.setForeground(Color.yellow);
symbol.setFont(new Font("Lucida Fax",Font.BOLD, 21));
p.add(symbol);
h = new JButton ("1. Latif Hostel");
h.addActionListener(this);
h.setBounds(10,60,200,40);
h.setFont(new Font("Lucida Fax",Font.BOLD, 17));
h2 = new JButton ("2. Qasim Hostel");
h2.addActionListener(this);
h2.setBounds(10,110,200,40);
h2.setFont(new Font("Lucida Fax",Font.BOLD, 17));
h3 = new JButton ("3. Sufi Hostel");
h3.addActionListener(this);
h3.setBounds(10,160,200,40);
h3.setFont(new Font("Lucida Fax",Font.BOLD, 17));
h4 = new JButton ("4. Sachal Hostel");
h4.addActionListener(this);
h4.setBounds(10,210,200,40);
h4.setFont(new Font("Lucida Fax",Font.BOLD, 17));
h5 = new JButton ("5. Sarmast Hostel");
h5.addActionListener(this);
h5.setBounds(10,260,200,40);
h5.setFont(new Font("Lucida Fax",Font.BOLD, 17));
h6 = new JButton ("6. Iqbal Hostel");
h6.addActionListener(this);
h6.setBounds(10,310,200,40);
h6.setFont(new Font("Lucida Fax",Font.BOLD, 17));
h7 = new JButton ("7. Zulfiqar Hostel");
h7.addActionListener(this);
h7.setBounds(10,360,200,40);
h7.setFont(new Font("Lucida Fax",Font.BOLD, 17));
p.add(h);
p.add(h2);
p.add(h3);
p.add(h4);
p.add(h5);
p.add(h6);
p.add(h7);
bu = new JButton ("Add New");
bu.addActionListener(this);
bu.setBounds(300,310,100,30);
bu1 = new JButton ("Save");
bu1.addActionListener(this);
bu1.setBounds(410,310,100,30);
bu2 = new JButton ("Search");
bu2.addActionListener(this);
bu2.setBounds(520,310,100,30);
bu3 = new JButton ("Update");
bu3.addActionListener(this);
bu3.setBounds(630,310,100,30);
bu4 = new JButton ("Delete");
bu4.addActionListener(this);
bu4.setBounds(740,310,100,30);
bu5 = new JButton ("Quit");
bu5.addActionListener(this);
bu5.setBounds(850,310,100,30);
p.add(bu);
p.add(bu1);
p.add(bu2);
p.add(bu3);
p.add(bu4);
p.add(bu5);
add(p);
}
/*********************** Method for Inserting the recods*************************/
public void addnew()
{
txt.setText(" ");
txt1.setText(" ");
txt2.setText(" ");
txt3.setText(" ");
txt4.setText(" ");
txt5.setText(" ");
txt6.setText(" ");
txt7.setText(" ");
txt.requestFocus();
}
/************************* Method for Saving the recods*************************/
public void save()
{
try
{
if((txt.getText().length()==0) || (txt1.getText().length()==0) ||
(txt2.getText().length()==0) || (txt3.getText().length()==0) ||
(txt4.getText().length()==0) || (txt5.getText().length()==0) ||
(txt6.getText().length()==0) || (txt7.getText().length()==0))
{
JOptionPane.showMessageDialog(this,"Blank Record specified");
}
else {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("Jdbc:Odbc:test");
PreparedStatement stm=con.prepareStatement("insert into students values (?,?,?,?,?,?,?,?)" );
stm.setString(1, txt.getText().trim());
stm.setString(2, txt1.getText().trim());
stm.setString(3, txt2.getText().trim());
stm.setString(4, txt3.getText().trim());
stm.setString(5, txt4.getText().trim());
stm.setString(6, txt5.getText().trim());
stm.setString(7, txt6.getText().trim());
stm.setString(8, txt7.getText().trim());
int i=stm.executeUpdate();
JOptionPane.showMessageDialog(this,String.valueOf(i)+"Rows Inserted");
con.close();
} //end of else
} // end of try
catch(Exception e) {
JOptionPane.showMessageDialog(this,e.getMessage());
}
} // end of function connection
/********************* Method for Searching the recods*************************/
public void search()
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("Jdbc:Odbc:test");
PreparedStatement stm=con.prepareStatement("Select*from students where RegNo=? " );
stm.setString(1, txt.getText().trim());
ResultSet rst=stm.executeQuery();
if(rst.next())
{
txt.setText(rst.getString(1));
txt1.setText(rst.getString(2));
txt2.setText(rst.getString(3));
txt3.setText(rst.getString(4));
txt4.setText(rst.getString(5));
txt5.setText(rst.getString(6));
txt6.setText(rst.getString(7));
txt7.setText(rst.getString(8));
}
else{
JOptionPane.showMessageDialog(this,"Record Not Found");
}
con.close();
} // end of try
catch(Exception e) {
JOptionPane.showMessageDialog(this,e.getMessage());
}
} // end of function connection
/*************************************** Method for Updating the recods*************************/
public void update()
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("Jdbc:Odbc:test");
PreparedStatement stm=con.prepareStatement("update [students] set [Name]=?, [Father Name]=?, [Cast]=? , [Term]=?, [Faculty]=?, [Address]=? , [Phone]=? where [RegNo]=?");
stm.setString(1, txt.getText().trim());
stm.setString(2, txt1.getText().trim());
stm.setString(3, txt2.getText().trim());
stm.setString(4, txt3.getText().trim());
stm.setString(5, txt4.getText().trim());
stm.setString(6, txt5.getText().trim());
stm.setString(7, txt6.getText().trim());
stm.setString(8, txt7.getText().trim());
int i=stm.executeUpdate();
JOptionPane.showMessageDialog(this,String.valueOf(i)+"Rows Updated");
con.close();
} // end of try
catch(Exception e) {
JOptionPane.showMessageDialog(this,e.getMessage());
}
} // end of function connection
/*************************************** Method for Updating the recods*************************/
public void delete()
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("Jdbc:Odbc:test");
PreparedStatement stm=con.prepareStatement("Delete * from students where RegNo=?");
stm.setString(1, txt.getText().trim());
int i=stm.executeUpdate();
JOptionPane.showMessageDialog(this,"Record Deleted");
con.close();
} // end of try
catch(Exception e) {
JOptionPane.showMessageDialog(this,e.getMessage());
}
} // end of function connection
/***************************************************ActionListeners************************************************/
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==h)
{
txt.setText("2K9-IT-");
images.setText(null);
images.setIcon(i);
}
if(e.getSource()==h2)
{
txt.setText("2K9-PD-");
images.setText(null);
images.setIcon(j);
}
if(e.getSource()==h3)
{
txt.setText("2K9-PT-");
images.setText(null);
images.setIcon(k);
}
if(e.getSource()==h4)
{
txt.setText("2K9-SS-");
images.setText(null);
images.setIcon(l);
}
if(e.getSource()==h5)
{
txt.setText("2K9-ENG-");
images.setText(null);
images.setIcon(m);
}
if(e.getSource()==h6)
{
txt.setText("2K9-AV-");
images.setText(null);
images.setIcon(n);
}
if(e.getSource()==h7)
{
txt.setText("2K9-FT-");
images.setText(null);
images.setIcon(o);
}
if(e.getSource()==bu) addnew();
if(e.getSource()==bu1) save();
if(e.getSource()==bu2) search();
if(e.getSource()==bu3) update();
if(e.getSource()==bu4) delete();
if(e.getSource()==bu5) System.exit(0);
}
public static void main(String args [])
{
project obj = new project();
obj.setLocation(10,10);
obj.setSize(975,680);
obj.setDefaultCloseOperation(EXIT_ON_CLOSE);
obj.setVisible(true);
}
}
/**************Created By : Zaheer Abbas Aghani 2K9-IT-152*******************/
OUTPUT :
MS ACCESS DATABASE FOR PROJECT...
/*************Crated By: Zaheer Abbas Aghani***********From: Pakistan*******************/
Login In Java..☺
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class Login extends JFrame implements ActionListener
{
JButton SUBMIT;
JButton Cancel;
//JPanel panel;
JLabel label1,label2;
final JTextField text1,text2;
Login()
{
setLayout(null);
label1 = new JLabel("Username:");
label1.setFont(new Font("Lucida Fax",0,15));
label1.setBounds(50,50,100,100);
text1 = new JTextField(15);
text1.setFont(new Font("Lucida Fax",0,15));
text1.setBounds(150,85,170,30);
label2 = new JLabel("Password:");
label2.setFont(new Font("Lucida Fax",0,15));
label2.setBounds(50,100,100,100);
text2 = new JPasswordField(15);
text2.setFont(new Font("Lucida Fax",0,15));
text2.setBounds(150,135,170,30);
SUBMIT=new JButton("SUBMIT");
//SUBMIT.setFont(new Font("Lucida Fax",0,15));
SUBMIT.setBounds(110,190,80,30);
//SUBMIT.setFont(new Font("Lucida Fax",0,15));
SUBMIT.setBounds(110,190,80,30);
Cancel=new JButton("Cancel");
Cancel.setBounds(220,190,80,30);
Cancel.addActionListener(this);
add(label1);
add(text1);
add(label2);
add(text2);
add(SUBMIT);
add(Cancel);
//add(panel,BorderLayout.CENTER);
SUBMIT.addActionListener(this);
setTitle("LOGIN FORM");
}
public void actionPerformed(ActionEvent ae)
{
String value1=text1.getText();
String value2=text2.getText();
if (value1.equals("Zaheer") && value2.equals("zaheer")) {
dispose();
project obj=new project();
obj.setVisible(true);
obj.setSize(975,680);
obj.setLocation(10,10);
obj.setDefaultCloseOperation(EXIT_ON_CLOSE);
}
if(ae.getSource()==Cancel)
{
System.exit(0);
}
}
}
class Start
{
public static void main(String arg[])
{
try
{
Login frame=new Login();
frame.setSize(400,300);
frame.setLocation(300,200);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
catch(Exception e)
{JOptionPane.showMessageDialog(null, e.getMessage());}
}
}
OUTPUT:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
class project extends JFrame implements ActionListener
{
JButton h,h2,h3,h4,h5,h6,h7;
JLabel lb1,lb2,lb3,lb4,lb5,lb6,lb7,lb8;
JTextField txt,txt1,txt2,txt3,txt4,txt5,txt6,txt7;
JButton Save,Search,Update,Delete,AddNew,Quit;
JButton bu,bu1,bu2,bu3,bu4,bu5;
JLabel images,series,zaheer;
Icon i,j,k,l,m,n,o,q,r;
public project ()
{
JPanel p = new JPanel();
/**********************Label with Images******************************/
images = new JLabel("Choose the Hostle");
images.setFont(new Font("Lucida Fax",0, 21));
images.setForeground(Color.red);
images.setBounds(150,350,800,240);
i = new ImageIcon("1.jpg");
j=new ImageIcon("2.jpg");
k=new ImageIcon("3.jpg");
l=new ImageIcon("4.jpg");
m=new ImageIcon("5.jpg");
n=new ImageIcon("6.jpg");
o=new ImageIcon("7.jpg");
p.add(images);
q = new ImageIcon("8.jpg");
series = new JLabel (q);
series.setBounds(130,440,800,240);
p.add(series);
r = new ImageIcon("9.jpg");
zaheer = new JLabel (r);
zaheer.setBounds(385,480,800,260);
p.add(zaheer);
JLabel lb1 = new JLabel ("Reg No :");
lb1.setForeground(Color.red);
lb1.setBounds(300,60,60,40);
lb1.setFont(new Font("Lucida Fax",0, 21));
p.add(lb1);
/************************Labels And TextFields******************************/
txt = new JTextField (" " ,15);
txt.setBounds(395,60,200,40);
txt.setForeground(Color.red);
txt.setFont(new Font("Lucida Fax",0, 21));
p.add(txt);
JLabel lb2 = new JLabel ("Name :");
lb2.setForeground(Color.red);
lb2.setBounds(300,120,200,40);
lb2.setFont(new Font("Lucida Fax",0, 21));
p.add(lb2);
txt1 = new JTextField (" " ,15);
txt1.setBounds(395,120,200,40);
txt1.setForeground(Color.red);
txt1.setFont(new Font("Lucida Fax",0, 21));
p.add(txt1);
JLabel lb3 = new JLabel ("F-Name:");
lb3.setBounds(300,180,200,40);
lb3.setForeground(Color.red);
lb3.setFont(new Font("Lucida Fax",0, 21));
p.add(lb3);
txt2 = new JTextField (" " ,15);
txt2.setBounds(395,180,200,40);
txt2.setForeground(Color.red);
txt2.setFont(new Font("Lucida Fax",0, 21));
p.add(txt2);
JLabel lb4 = new JLabel ("Cast :");
lb4.setBounds(300,240,200,40);
lb4.setForeground(Color.red);
lb4.setFont(new Font("Lucida Fax",0, 21));
p.add(lb4);
txt3 = new JTextField (" " ,15);
txt3.setBounds(395,240,200,40);
txt3.setForeground(Color.red);
txt3.setFont(new Font("Lucida Fax",0, 21));
p.add(txt3);
lb5 = new JLabel ("Term :");
lb5.setForeground(Color.red);
lb5.setBounds(640,60,200,40);
lb5.setFont(new Font("Lucida Fax",0, 21));
p.add(lb5);
txt4 = new JTextField (" " ,15);
txt4.setBounds(750,60,200,40);
txt4.setForeground(Color.red);
txt4.setFont(new Font("Lucida Fax",0, 21));
p.add(txt4);
lb6 = new JLabel ("Faculty :");
lb6.setForeground(Color.red);
lb6.setBounds(640,120,200,40);
lb6.setFont(new Font("Lucida Fax",0, 21));
p.add(lb6);
txt5 = new JTextField (" " ,15);
txt5.setBounds(750,120,200,40);
txt5.setForeground(Color.red);
txt5.setFont(new Font("Lucida Fax",0, 21));
p.add(txt5);
lb7 = new JLabel ("Address :");
lb7.setBounds(640,180,200,40);
lb7.setForeground(Color.red);
lb7.setFont(new Font("Lucida Fax",0, 21));
p.add(lb7);
txt6 = new JTextField (" " ,15);
txt6.setBounds(750,180,200,40);
txt6.setForeground(Color.red);
txt6.setFont(new Font("Lucida Fax",0, 21));
p.add(txt6);
lb8 = new JLabel ("Phone :");
lb8.setBounds(640,240,200,40);
lb8.setForeground(Color.red);
lb8.setFont(new Font("Lucida Fax",0, 21));
p.add(lb8);
txt7 = new JTextField (" " ,15);
txt7.setBounds(750,240,200,40);
txt7.setForeground(Color.red);
txt7.setFont(new Font("Lucida Fax",0, 21));
p.add(txt7);
/********************* Labels And Buttons**********************/
p.setBackground(Color.black);
p.setLayout(null);
JLabel title = new JLabel ("Hostle Allotment System");
title.setBounds(350,0,400,40);
title.setFont(new Font("Lucida Fax",Font.BOLD, 21));
title.setForeground(Color.yellow);
p.add(title);
JLabel symbol = new JLabel ("----------------------------------------");
symbol.setBounds(350,10,400,40);
symbol.setForeground(Color.yellow);
symbol.setFont(new Font("Lucida Fax",Font.BOLD, 21));
p.add(symbol);
h = new JButton ("1. Latif Hostel");
h.addActionListener(this);
h.setBounds(10,60,200,40);
h.setFont(new Font("Lucida Fax",Font.BOLD, 17));
h2 = new JButton ("2. Qasim Hostel");
h2.addActionListener(this);
h2.setBounds(10,110,200,40);
h2.setFont(new Font("Lucida Fax",Font.BOLD, 17));
h3 = new JButton ("3. Sufi Hostel");
h3.addActionListener(this);
h3.setBounds(10,160,200,40);
h3.setFont(new Font("Lucida Fax",Font.BOLD, 17));
h4 = new JButton ("4. Sachal Hostel");
h4.addActionListener(this);
h4.setBounds(10,210,200,40);
h4.setFont(new Font("Lucida Fax",Font.BOLD, 17));
h5 = new JButton ("5. Sarmast Hostel");
h5.addActionListener(this);
h5.setBounds(10,260,200,40);
h5.setFont(new Font("Lucida Fax",Font.BOLD, 17));
h6 = new JButton ("6. Iqbal Hostel");
h6.addActionListener(this);
h6.setBounds(10,310,200,40);
h6.setFont(new Font("Lucida Fax",Font.BOLD, 17));
h7 = new JButton ("7. Zulfiqar Hostel");
h7.addActionListener(this);
h7.setBounds(10,360,200,40);
h7.setFont(new Font("Lucida Fax",Font.BOLD, 17));
p.add(h);
p.add(h2);
p.add(h3);
p.add(h4);
p.add(h5);
p.add(h6);
p.add(h7);
bu = new JButton ("Add New");
bu.addActionListener(this);
bu.setBounds(300,310,100,30);
bu1 = new JButton ("Save");
bu1.addActionListener(this);
bu1.setBounds(410,310,100,30);
bu2 = new JButton ("Search");
bu2.addActionListener(this);
bu2.setBounds(520,310,100,30);
bu3 = new JButton ("Update");
bu3.addActionListener(this);
bu3.setBounds(630,310,100,30);
bu4 = new JButton ("Delete");
bu4.addActionListener(this);
bu4.setBounds(740,310,100,30);
bu5 = new JButton ("Quit");
bu5.addActionListener(this);
bu5.setBounds(850,310,100,30);
p.add(bu);
p.add(bu1);
p.add(bu2);
p.add(bu3);
p.add(bu4);
p.add(bu5);
add(p);
}
/*********************** Method for Inserting the recods*************************/
public void addnew()
{
txt.setText(" ");
txt1.setText(" ");
txt2.setText(" ");
txt3.setText(" ");
txt4.setText(" ");
txt5.setText(" ");
txt6.setText(" ");
txt7.setText(" ");
txt.requestFocus();
}
/************************* Method for Saving the recods*************************/
public void save()
{
try
{
if((txt.getText().length()==0) || (txt1.getText().length()==0) ||
(txt2.getText().length()==0) || (txt3.getText().length()==0) ||
(txt4.getText().length()==0) || (txt5.getText().length()==0) ||
(txt6.getText().length()==0) || (txt7.getText().length()==0))
{
JOptionPane.showMessageDialog(this,"Blank Record specified");
}
else {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("Jdbc:Odbc:test");
PreparedStatement stm=con.prepareStatement("insert into students values (?,?,?,?,?,?,?,?)" );
stm.setString(1, txt.getText().trim());
stm.setString(2, txt1.getText().trim());
stm.setString(3, txt2.getText().trim());
stm.setString(4, txt3.getText().trim());
stm.setString(5, txt4.getText().trim());
stm.setString(6, txt5.getText().trim());
stm.setString(7, txt6.getText().trim());
stm.setString(8, txt7.getText().trim());
int i=stm.executeUpdate();
JOptionPane.showMessageDialog(this,String.valueOf(i)+"Rows Inserted");
con.close();
} //end of else
} // end of try
catch(Exception e) {
JOptionPane.showMessageDialog(this,e.getMessage());
}
} // end of function connection
/********************* Method for Searching the recods*************************/
public void search()
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("Jdbc:Odbc:test");
PreparedStatement stm=con.prepareStatement("Select*from students where RegNo=? " );
stm.setString(1, txt.getText().trim());
ResultSet rst=stm.executeQuery();
if(rst.next())
{
txt.setText(rst.getString(1));
txt1.setText(rst.getString(2));
txt2.setText(rst.getString(3));
txt3.setText(rst.getString(4));
txt4.setText(rst.getString(5));
txt5.setText(rst.getString(6));
txt6.setText(rst.getString(7));
txt7.setText(rst.getString(8));
}
else{
JOptionPane.showMessageDialog(this,"Record Not Found");
}
con.close();
} // end of try
catch(Exception e) {
JOptionPane.showMessageDialog(this,e.getMessage());
}
} // end of function connection
/*************************************** Method for Updating the recods*************************/
public void update()
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("Jdbc:Odbc:test");
PreparedStatement stm=con.prepareStatement("update [students] set [Name]=?, [Father Name]=?, [Cast]=? , [Term]=?, [Faculty]=?, [Address]=? , [Phone]=? where [RegNo]=?");
stm.setString(1, txt.getText().trim());
stm.setString(2, txt1.getText().trim());
stm.setString(3, txt2.getText().trim());
stm.setString(4, txt3.getText().trim());
stm.setString(5, txt4.getText().trim());
stm.setString(6, txt5.getText().trim());
stm.setString(7, txt6.getText().trim());
stm.setString(8, txt7.getText().trim());
int i=stm.executeUpdate();
JOptionPane.showMessageDialog(this,String.valueOf(i)+"Rows Updated");
con.close();
} // end of try
catch(Exception e) {
JOptionPane.showMessageDialog(this,e.getMessage());
}
} // end of function connection
/*************************************** Method for Updating the recods*************************/
public void delete()
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("Jdbc:Odbc:test");
PreparedStatement stm=con.prepareStatement("Delete * from students where RegNo=?");
stm.setString(1, txt.getText().trim());
int i=stm.executeUpdate();
JOptionPane.showMessageDialog(this,"Record Deleted");
con.close();
} // end of try
catch(Exception e) {
JOptionPane.showMessageDialog(this,e.getMessage());
}
} // end of function connection
/***************************************************ActionListeners************************************************/
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==h)
{
txt.setText("2K9-IT-");
images.setText(null);
images.setIcon(i);
}
if(e.getSource()==h2)
{
txt.setText("2K9-PD-");
images.setText(null);
images.setIcon(j);
}
if(e.getSource()==h3)
{
txt.setText("2K9-PT-");
images.setText(null);
images.setIcon(k);
}
if(e.getSource()==h4)
{
txt.setText("2K9-SS-");
images.setText(null);
images.setIcon(l);
}
if(e.getSource()==h5)
{
txt.setText("2K9-ENG-");
images.setText(null);
images.setIcon(m);
}
if(e.getSource()==h6)
{
txt.setText("2K9-AV-");
images.setText(null);
images.setIcon(n);
}
if(e.getSource()==h7)
{
txt.setText("2K9-FT-");
images.setText(null);
images.setIcon(o);
}
if(e.getSource()==bu) addnew();
if(e.getSource()==bu1) save();
if(e.getSource()==bu2) search();
if(e.getSource()==bu3) update();
if(e.getSource()==bu4) delete();
if(e.getSource()==bu5) System.exit(0);
}
public static void main(String args [])
{
project obj = new project();
obj.setLocation(10,10);
obj.setSize(975,680);
obj.setDefaultCloseOperation(EXIT_ON_CLOSE);
obj.setVisible(true);
}
}
/**************Created By : Zaheer Abbas Aghani 2K9-IT-152*******************/
OUTPUT :
MS ACCESS DATABASE FOR PROJECT...
/*************Crated By: Zaheer Abbas Aghani***********From: Pakistan*******************/
2 comments:
A very Good Project Bro
thank you
Post a Comment