26714384 hostel management system source code in java by b vinod kumar

43
import java.awt.event.*; import java.awt.*; import javax.swing.*; import java.sql.*; import javax.swing.table.*; public class Project implements ActionListener { JButton b1,b2,b3; JLabel l,l1,l2,l3; JTextField tf1; JPasswordField tf2; JFrame f; JPanel p,p1,p2,p3,p4,p5; public Project() { f=new JFrame("Login Form"); l1=new JLabel("Please Enter Username and Password"); l=new JLabel("WELCOME"); l.setForeground(Color.BLUE); l1.setFont(new Font("ARIAL",Font.BOLD,25)); l.setFont(new Font(Font.SANS_SERIF,Font.BOLD,40)); l1.setForeground(Color.RED); l2=new JLabel("UserName :"); l3=new JLabel("PassWord :"); l2.setFont(new Font("",Font.BOLD,17)); l3.setFont(new Font("",Font.BOLD,17)); tf1=new JTextField(10); tf2=new JPasswordField(10); b1=new JButton("Login"); b2=new JButton("Reset"); b3=new JButton("Exit"); p=new JPanel(); p1=new JPanel(); p2=new JPanel(); p3=new JPanel(); p4=new JPanel(); p5=new JPanel(); p1.setLayout(new BoxLayout(p1,BoxLayout.X_AXIS)); p1.add(l2); p1.add(tf1); p2.setLayout(new BoxLayout(p2,BoxLayout.X_AXIS)); p2.add(l3); p2.add(tf2); p3.add(b1); p3.add(b2); p4.setLayout(new FlowLayout()); p4.add(l); p5.setLayout(new FlowLayout()); p5.add(l1); p3.add(b3); f.setLayout(new FlowLayout()); Dimension d=Toolkit.getDefaultToolkit().getScreenSize(); int width=(int)d.getWidth(); p.setLayout(new BoxLayout(p,BoxLayout.Y_AXIS)); p.add(p4); p.add(Box.createRigidArea(new Dimension(width,75))); p.add(p5); f.add(p); f.add(Box.createRigidArea(new Dimension(width,50)));

Upload: payal-srivastava

Post on 14-Apr-2015

115 views

Category:

Documents


6 download

DESCRIPTION

java book

TRANSCRIPT

Page 1: 26714384 Hostel Management System Source Code in JAVA by B Vinod Kumar

import java.awt.event.*;import java.awt.*;import javax.swing.*;import java.sql.*;import javax.swing.table.*;public class Project implements ActionListener{ JButton b1,b2,b3; JLabel l,l1,l2,l3; JTextField tf1;

JPasswordField tf2; JFrame f; JPanel p,p1,p2,p3,p4,p5;

public Project() {

f=new JFrame("Login Form"); l1=new JLabel("Please Enter Username and Password");

l=new JLabel("WELCOME");l.setForeground(Color.BLUE);l1.setFont(new Font("ARIAL",Font.BOLD,25));l.setFont(new Font(Font.SANS_SERIF,Font.BOLD,40));l1.setForeground(Color.RED);

l2=new JLabel("UserName :"); l3=new JLabel("PassWord :");

l2.setFont(new Font("",Font.BOLD,17));l3.setFont(new Font("",Font.BOLD,17));

tf1=new JTextField(10); tf2=new JPasswordField(10);

b1=new JButton("Login"); b2=new JButton("Reset");

b3=new JButton("Exit");p=new JPanel();p1=new JPanel();p2=new JPanel();p3=new JPanel();p4=new JPanel();p5=new JPanel();p1.setLayout(new BoxLayout(p1,BoxLayout.X_AXIS));p1.add(l2);p1.add(tf1);p2.setLayout(new BoxLayout(p2,BoxLayout.X_AXIS));p2.add(l3);p2.add(tf2);p3.add(b1);p3.add(b2);p4.setLayout(new FlowLayout());p4.add(l);p5.setLayout(new FlowLayout());p5.add(l1);p3.add(b3);f.setLayout(new FlowLayout());Dimension d=Toolkit.getDefaultToolkit().getScreenSize();int width=(int)d.getWidth();p.setLayout(new BoxLayout(p,BoxLayout.Y_AXIS));p.add(p4);p.add(Box.createRigidArea(new Dimension(width,75)));p.add(p5);f.add(p);f.add(Box.createRigidArea(new Dimension(width,50)));

Page 2: 26714384 Hostel Management System Source Code in JAVA by B Vinod Kumar

f.add(p1);f.add(Box.createRigidArea(new Dimension(width,15)));f.add(p2);f.add(Box.createRigidArea(new Dimension(width,30)));f.add(p3);

f.setVisible(true); f.setSize(d);

f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);f.setResizable(false);

b1.addActionListener(this); b2.addActionListener(this);

b3.addActionListener(this); } public void actionPerformed(ActionEvent ae) { if(ae.getSource()==b1) { try { String username = tf1.getText();

String password=String.copyValueOf(tf2.getPassword()if(username.equals("") || password.equals("")){

JOptionPane.showMessageDialog(null,"Required}else{

if(login(username,password)){

Main m1=new Main();f.dispose();

}else{

JOptionPane.showMessageDialog(f,"Inctf1.setText("");tf2.setText("");

}}

} catch(Exception e){} } if(ae.getSource()==b2) { try { tf1.setText(""); tf2.setText(""); } catch(Exception e){} }

if(ae.getSource()==b3){

System.exit(0);}

} public boolean login(String username,String password) { try {

Page 3: 26714384 Hostel Management System Source Code in JAVA by B Vinod Kumar

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");Connection con =DriverManager.getConnection("jdbc:odbc:MydatStatement s=con.createStatement();String sq1="Select username, password from admin where usernResultSet rs=s.executeQuery(sq1);if(rs.next()){

return true; }

rs.close(); s.close(); con.close();

} catch(Exception p) { System.out.println(p.toString()); } return false; } public static void main(String args[])throws Exception { Project l=new Project(); }}class Main implements ActionListener{

JButton b1,b2,b3,b4;JLabel l;JFrame f1; JPanel p;Main(){

l=new JLabel("Click on any one of the required buttons");l.setFont(new Font(Font.SANS_SERIF,Font.BOLD,25));l.setForeground(Color.RED);b1=new JButton("Student");b2=new JButton("Accounts");b3=new JButton("Exit");b1.setFont(new Font("ARIAL",Font.PLAIN,20));b2.setFont(new Font("ARIAL",Font.PLAIN,20));b3.setFont(new Font("ARIAL",Font.PLAIN,20));p=new JPanel();Dimension d=Toolkit.getDefaultToolkit().getScreenSize();int width=(int)d.getWidth();f1=new JFrame("Main page");f1.setLayout(new FlowLayout());f1.setBackground(Color.YELLOW);f1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);f1.setSize(d);f1.setVisible(true);p.setLayout(new BoxLayout(p,BoxLayout.X_AXIS));p.add(b1);p.add(Box.createHorizontalStrut(30));p.add(b2);f1.add(Box.createRigidArea(new Dimension(width,25)));f1.add(l);f1.add(Box.createRigidArea(new Dimension(width,100)));f1.add(p);f1.add(Box.createRigidArea(new Dimension(width,25)));f1.add(b3);

Page 4: 26714384 Hostel Management System Source Code in JAVA by B Vinod Kumar

b1.addActionListener(this); b2.addActionListener(this);

b3.addActionListener(this);}public void actionPerformed(ActionEvent e){

if(e.getSource()==b1){

Stud s1=new Stud();f1.dispose();

}if(e.getSource()==b2){

Accounts ac=new Accounts();f1.dispose();

}if(e.getSource()==b3){

System.exit(0);}

}}class Stud implements ActionListener{

JFrame f2;JRadioButton b1,b2,b3,b4,b6;JButton b5;ButtonGroup bg;JLabel l;Stud(){

bg=new ButtonGroup();f2=new JFrame("Student");l=new JLabel("Select one of the following");l.setForeground(Color.MAGENTA);l.setFont(new Font(Font.SANS_SERIF,Font.BOLD,25));b1=new JRadioButton("Add Students ",false);b1.setFont(new Font("ARIAL",Font.PLAIN,20));b2=new JRadioButton("Student Details ",false);b2.setFont(new Font("ARIAL",Font.PLAIN,20));b3=new JRadioButton("Remove Student",false);b3.setFont(new Font("ARIAL",Font.PLAIN,20));b4=new JRadioButton("Update Student ",false);b4.setFont(new Font("ARIAL",Font.PLAIN,20));b5=new JButton("Go to Main Page");b5.setFont(new Font("ARIAL",Font.PLAIN,20));Dimension d=Toolkit.getDefaultToolkit().getScreenSize();int width=(int)d.getWidth();f2.setLayout(new FlowLayout());f2.setBackground(Color.RED);f2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);f2.setSize(Toolkit.getDefaultToolkit().getScreenSize());f2.setVisible(true);f2.add(Box.createRigidArea(new Dimension(width,20)));f2.add(l);f2.add(Box.createRigidArea(new Dimension(width,100)));f2.add(b2);f2.add(Box.createRigidArea(new Dimension(width,5)));f2.add(b1);f2.add(Box.createRigidArea(new Dimension(width,5)));

Page 5: 26714384 Hostel Management System Source Code in JAVA by B Vinod Kumar

f2.add(b3);f2.add(Box.createRigidArea(new Dimension(width,5)));f2.add(b4);f2.add(Box.createRigidArea(new Dimension(width,30)));f2.add(b5);b1.addActionListener(this);b2.addActionListener(this);b3.addActionListener(this);b4.addActionListener(this);b5.addActionListener(this);

}public void actionPerformed(ActionEvent e){

if(b1.isSelected()){

Addastudent a1=new Addastudent();f2.dispose();

}if(b2.isSelected()){

StudentDetails d=new StudentDetails();f2.dispose();

}if(b3.isSelected()){

RemoveStudent rs=new RemoveStudent();f2.dispose();

}if(b4.isSelected()){

UpdateStudent us=new UpdateStudent();f2.dispose();

}if(e.getSource()==b5){

Main m2=new Main();f2.dispose();

}}

}class StudentDetails implements ActionListener{

JFrame f4;JRadioButton b1,b2,b3,b6;JButton b4,b5;ButtonGroup bg;JLabel l;StudentDetails(){

f4=new JFrame("Student Detials");l=new JLabel("Select the required one");l.setFont(new Font(Font.SANS_SERIF,Font.BOLD,35));l.setForeground(Color.RED);b1=new JRadioButton("View according to roll no's ",false);b1.setFont(new Font("ARIAL",Font.PLAIN,20));b2=new JRadioButton("View as per the Name ",false);b2.setFont(new Font("ARIAL",Font.PLAIN,20));b3=new JRadioButton("View as per the year ",false);b3.setFont(new Font("ARIAL",Font.PLAIN,20));

Page 6: 26714384 Hostel Management System Source Code in JAVA by B Vinod Kumar

b6=new JRadioButton("View all students ",false);b6.setFont(new Font("ARIAL",Font.PLAIN,20));b4=new JButton("Back ");b4.setFont(new Font("ARIAL",Font.ITALIC,20));b5=new JButton("Go to Main Page ");b5.setFont(new Font("ARIAL",Font.ITALIC,20));Dimension d=Toolkit.getDefaultToolkit().getScreenSize();int width=(int)d.getWidth();f4.setLayout(new FlowLayout());f4.setBackground(Color.YELLOW);f4.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);f4.setSize(Toolkit.getDefaultToolkit().getScreenSize());f4.setVisible(true);f4.add(Box.createRigidArea(new Dimension(width,20)));f4.add(l);f4.add(Box.createRigidArea(new Dimension(width,100)));f4.add(b6);f4.add(Box.createRigidArea(new Dimension(width,5)));f4.add(b2);f4.add(Box.createRigidArea(new Dimension(width,5)));f4.add(b1);f4.add(Box.createRigidArea(new Dimension(width,5)));f4.add(b3);f4.add(Box.createRigidArea(new Dimension(width,40)));f4.add(b4);f4.add(Box.createRigidArea(new Dimension(width,5)));f4.add(b5);b1.addActionListener(this);b2.addActionListener(this);b3.addActionListener(this);b4.addActionListener(this);b5.addActionListener(this);b6.addActionListener(this);

}public void actionPerformed(ActionEvent e){

if(e.getSource()==b1){

Roll r=new Roll();f4.dispose();

}if(e.getSource()==b2){

Name n=new Name();f4.dispose();

}if(e.getSource()==b3){

Year y=new Year();f4.dispose();

}if(e.getSource()==b4){

Stud s=new Stud();f4.dispose();

}if(e.getSource()==b5){

Main m=new Main();f4.dispose();

Page 7: 26714384 Hostel Management System Source Code in JAVA by B Vinod Kumar

}if(e.getSource()==b6){

All a=new All();f4.dispose();

}}

}class All implements ActionListener{

JFrame f7;JScrollPane p;JTable tab;JButton b;String[] columnNames = {"Roll Number","Name","Mess Number","Address","Branch","Year"Object[][] data=new Object[100][100];All(){

try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");Connection con = DriverManager.getConnection("jdbc:odbc:Mydatabase",Statement st=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResString s="select * from student";ResultSet rs=st.executeQuery(s);if(!rs.next()){

JOptionPane.showMessageDialog(null,"No One exists with the g}else{

rs.previous();int i=0,j=0;String s2="",s3="";while(rs.next()){

data[i][j]=rs.getString(1);j++;data[i][j]=rs.getString(2);j++;data[i][j]=rs.getString(3);j++;data[i][j]=rs.getString(4);j++;data[i][j]=rs.getString(5);j++;int in=Integer.parseInt(rs.getString(6));switch(in){

case 1:s2="1st year,B.TECH";break;case 2:s2="2nd year,B.TECH";break;case 3:s2="3rd year,B.TECH";break;case 4:s2="4th year,B.TECH";break;

}char ch=rs.getString(7).charAt(0);switch(ch){

case 'n':s3="Non-Veg";break;case 'v':s3="Veg";break;

}data[i][j]=s2;j++;data[i][j]=s3;j++;j=0;i++;

}b=new JButton("Back");tab= new JTable(data, columnNames);

Page 8: 26714384 Hostel Management System Source Code in JAVA by B Vinod Kumar

TableColumn column = null;for (i = 0; i < 7; i++){

column = tab.getColumnModel().getColumn(i);if (i==1)

column.setMinWidth(50); else if(i==0)

column.setMinWidth(25); else if(i==3)

column.setMinWidth(500);else if(i==2)

column.setMinWidth(11);else if(i==4)

column.setMinWidth(6);else if(i==5)

column.setMinWidth(16);else if(i==6)

column.setMinWidth(8); }p=new JScrollPane(tab);f7=new JFrame("All Student Details ");f7.setSize(Toolkit.getDefaultToolkit().getScreenSize());f7.setVisible(true);f7.add(b,BorderLayout.NORTH);f7.add(p,BorderLayout.CENTER);f7.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);b.addActionListener(this);

}}catch(Exception e){

System.out.println(e.toString());}

}public void actionPerformed(ActionEvent e1){

StudentDetails sd=new StudentDetails();f7.dispose();

}}class Name implements ActionListener{

JLabel l,l1;public JTextField t;JButton b1,b2;JFrame f6;JPanel p1,p2;Name(){

l=new JLabel("Please Enter Name and click View");l.setFont(new Font(Font.SANS_SERIF,Font.BOLD,25));l.setForeground(Color.BLUE);

l1=new JLabel("Enter Name here:");t=new JTextField(15);b1=new JButton("View");b2=new JButton("Cancel");f6=new JFrame("Name Wise student Details");f6.setLayout(new FlowLayout());f6.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

Page 9: 26714384 Hostel Management System Source Code in JAVA by B Vinod Kumar

f6.setSize(Toolkit.getDefaultToolkit().getScreenSize());f6.setVisible(true);

Dimension d=Toolkit.getDefaultToolkit().getScreenSize();int width=(int)d.getWidth();

p1=new JPanel();p2=new JPanel();p1.add(l1);p1.add(t);p2.add(b1);p2.add(b2);f6.add(Box.createRigidArea(new Dimension(width,20)));f6.add(l);f6.add(Box.createRigidArea(new Dimension(width,30)));f6.add(p1);f6.add(Box.createRigidArea(new Dimension(width,20)));f6.add(p2);b1.addActionListener(this);b2.addActionListener(this);t.requestFocus(true);

}public void actionPerformed(ActionEvent e){

try{

if(e.getSource()==b1){

String s=t.getText().toUpperCase();if(s.equals("")){

JOptionPane.showMessageDialog(null,"Please specify tt.requestFocus(true);

}else{

SName sn=new SName(s);t.setText(null);

}}if(e.getSource()==b2){

StudentDetails d2=new StudentDetails();f6.dispose();

}}catch(Exception e1){

System.out.println(e1.toString());}

}}class SName implements ActionListener{

JFrame f7;JScrollPane p;JTable tab;JButton b;

Page 10: 26714384 Hostel Management System Source Code in JAVA by B Vinod Kumar

String[] columnNames = {"Roll Number","Name","Mess Number","Address","Branch","Year"Object[][] data=new Object[100][100];SName(String s1){

try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");Connection con = DriverManager.getConnection("jdbc:odbc:Mydatabase",Statement st=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResString s="select * from student where name like '%"+s1+"%'";ResultSet rs=st.executeQuery(s);if(!rs.next()){

JOptionPane.showMessageDialog(null,"No One exists with the g}else{

rs.previous();int i=0,j=0;String s2="",s3="";while(rs.next()){

data[i][j]=rs.getString(1);j++;data[i][j]=rs.getString(2);j++;data[i][j]=rs.getString(3);j++;data[i][j]=rs.getString(4);j++;data[i][j]=rs.getString(5);j++;int in=Integer.parseInt(rs.getString(6));switch(in){

case 1:s2="1st year,B.TECH";break;case 2:s2="2nd year,B.TECH";break;case 3:s2="3rd year,B.TECH";break;case 4:s2="4th year,B.TECH";break;

}char ch=rs.getString(7).charAt(0);switch(ch){

case 'n':s3="Non-Veg";break;case 'v':s3="Veg";break;

}data[i][j]=s2;j++;data[i][j]=s3;j++;j=0;i++;

}b=new JButton("View another");tab= new JTable(data, columnNames);TableColumn column = null;for (i = 0; i < 7; i++){

column = tab.getColumnModel().getColumn(i);if (i==1)

column.setMinWidth(50); else if(i==0)

column.setMinWidth(25); else if(i==3)

column.setMinWidth(500);else if(i==2)

column.setMinWidth(11);else if(i==4)

column.setMinWidth(6);

Page 11: 26714384 Hostel Management System Source Code in JAVA by B Vinod Kumar

else if(i==5)column.setMinWidth(16);

else if(i==6)column.setMinWidth(8);

}p=new JScrollPane(tab);f7=new JFrame("Student Details having name "+s1);f7.setSize(Toolkit.getDefaultToolkit().getScreenSize());f7.setVisible(true);f7.add(b,BorderLayout.NORTH);f7.add(p,BorderLayout.CENTER);f7.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);b.addActionListener(this);

}}catch(Exception e){

System.out.println(e.toString());}

}public void actionPerformed(ActionEvent e1){

f7.dispose();}

}class Roll implements ActionListener{

JFrame f5;JLabel la1,la2;JTextField t;JButton b1,b2;JPanel p1,p2;Roll(){

f5=new JFrame("Roll Number Wise Student details");la1=new JLabel("Enter the roll number and click view");la1.setFont(new Font(Font.SANS_SERIF,Font.BOLD,25));la1.setForeground(Color.BLUE);

la2=new JLabel("Enter roll number here:");b1=new JButton("View");b1.setFont(new Font(Font.SANS_SERIF,Font.PLAIN,15));b2=new JButton("Cancel");b2.setFont(new Font(Font.SANS_SERIF,Font.PLAIN,15));

t=new JTextField(15);p1=new JPanel();p2=new JPanel();p1.add(la2);p1.add(t);p2.add(b1);p2.add(b2);f5.setLayout(new FlowLayout());f5.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);f5.setSize(Toolkit.getDefaultToolkit().getScreenSize());f5.setVisible(true);

Dimension d=Toolkit.getDefaultToolkit().getScreenSize();int width=(int)d.getWidth();

Page 12: 26714384 Hostel Management System Source Code in JAVA by B Vinod Kumar

f5.add(Box.createRigidArea(new Dimension(width,30)));f5.add(la1);f5.add(Box.createRigidArea(new Dimension(width,30)));f5.add(p1);f5.add(Box.createRigidArea(new Dimension(width,30)));f5.add(p2);t.requestFocus(true);b1.addActionListener(this);b2.addActionListener(this);

}public void actionPerformed(ActionEvent e){

if(e.getSource()==b1){

String s1=t.getText().toUpperCase();if(s1.equals("")){

JOptionPane.showMessageDialog(null,"Please specify tt.requestFocus(true);

}else{

Roll1 r1=new Roll1(s1);f5.dispose();

}}if(e.getSource()==b2){

StudentDetails d2=new StudentDetails();f5.dispose();

}}

}class Roll1 implements ActionListener{

JFrame f;JLabel l1,l2,l3,l4,l5,l6,l7;JTextField t1,t2,t3;JTextArea t4;JTextField t5,t6,t7;JButton b1,b2,b3;JPanel p,p1,p2,p3,p4,p5,p6,p7;Roll1(String s){

f=new JFrame("Student Details with roll number "+s);l1=new JLabel("Roll Number :");l2=new JLabel("Name :");l3=new JLabel("Mess No :");l4=new JLabel("Address :");l5=new JLabel("Branch :");l6=new JLabel("Year :");l7=new JLabel("Type :");b1=new JButton("View Another");b2=new JButton("Cancel");b3=new JButton("Go to Main Page");t1=new JTextField(15);t2=new JTextField(15);t3=new JTextField(15);t4=new JTextArea(10,20);t5=new JTextField(15);

Page 13: 26714384 Hostel Management System Source Code in JAVA by B Vinod Kumar

t6=new JTextField(15);t7=new JTextField(15);t1.setEditable(false);t2.setEditable(false);t3.setEditable(false);t4.setEditable(false);t5.setEditable(false);t6.setEditable(false);t7.setEditable(false);p=new JPanel();p1=new JPanel();p2=new JPanel();p3=new JPanel();p4=new JPanel();p5=new JPanel();p6=new JPanel();p7=new JPanel();p1.add(l1);p1.add(t1);p2.add(l2);p2.add(t2);p3.add(l3);p3.add(t3);p4.add(l4);p4.add(t4);p5.add(l5);p5.add(t5);p6.add(l6);p6.add(t6);p7.add(l7);p7.add(t7);p.add(b1);p.add(b2);p.add(b3);f.setLayout(new FlowLayout());f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);f.setSize(Toolkit.getDefaultToolkit().getScreenSize());f.setVisible(true);Dimension d=Toolkit.getDefaultToolkit().getScreenSize();int width=(int)d.getWidth();f.add(Box.createRigidArea(new Dimension(width,10)));f.add(p1);f.add(Box.createRigidArea(new Dimension(width,10)));f.add(p2);f.add(Box.createRigidArea(new Dimension(width,10)));f.add(p3);f.add(Box.createRigidArea(new Dimension(width,10)));f.add(p4);f.add(Box.createRigidArea(new Dimension(width,10)));f.add(p5);f.add(Box.createRigidArea(new Dimension(width,10)));f.add(p6);f.add(Box.createRigidArea(new Dimension(width,10)));f.add(p7);f.add(Box.createRigidArea(new Dimension(width,10)));f.add(p);b1.addActionListener(this);b2.addActionListener(this);b3.addActionListener(this);try

Page 14: 26714384 Hostel Management System Source Code in JAVA by B Vinod Kumar

{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");Connection con = DriverManager.getConnection("jdbc:odbc:Mydatabase",Statement st=con.createStatement();String s1="select * from student where rno='"+s+"'";ResultSet rs=st.executeQuery(s1);if(rs.next()){

t1.setText(rs.getString(1));t2.setText(rs.getString(2));t3.setText(rs.getString(3));t4.setText(rs.getString(4));t5.setText(rs.getString(5));int i=Integer.parseInt(rs.getString(6));switch(i){

case 1:t6.setText("1st year,B.TECH");break;case 2:t6.setText("2nd year,B.TECH");break;case 3:t6.setText("3rd year,B.TECH");break;case 4:t6.setText("4th year,B.TECH");break;

}char ch=rs.getString(7).charAt(0);switch(ch){

case 'n':t7.setText("Non-Veg");break;case 'v':t7.setText("Veg");break;

}}else{

f.dispose();JOptionPane.showMessageDialog(null,"The roll number is invalRoll rt=new Roll();

}}catch(Exception e1){

System.out.println(e1.toString());}

}public void actionPerformed(ActionEvent e){

if(e.getSource()==b1){

Roll re=new Roll();f.dispose();

}if(e.getSource()==b2){

Stud sd=new Stud();f.dispose();

}if(e.getSource()==b3){

Main me=new Main();f.dispose();

}}

}class Year implements ActionListener

Page 15: 26714384 Hostel Management System Source Code in JAVA by B Vinod Kumar

{JComboBox c1,c2;JLabel l,l1,l2;JButton b1,b2;JFrame f8;JPanel p1,p2,p3;Year(){

f8=new JFrame("Year Wise Student details");

String y[]={"<Select>","1","2","3","4"};String ty[]={"<Select>","View All","Branch Wise","Mess Number Wise"};c1=new JComboBox(y);c2=new JComboBox(ty);l=new JLabel("Please select year , type and then Click 'view'");l.setFont(new Font(Font.SANS_SERIF,Font.BOLD,25));l.setForeground(Color.BLUE);l1=new JLabel("Year:");l1.setFont(new Font(Font.SANS_SERIF,Font.BOLD,15));l2=new JLabel("Type:");l2.setFont(new Font(Font.SANS_SERIF,Font.BOLD,15));

b1=new JButton("View");b1.setFont(new Font(Font.SANS_SERIF,Font.BOLD,15));

b2=new JButton("Back");b2.setFont(new Font(Font.SANS_SERIF,Font.BOLD,15));p1=new JPanel();p2=new JPanel();p3=new JPanel();Dimension d=Toolkit.getDefaultToolkit().getScreenSize();int width=(int)d.getWidth();

p1.add(l1);p1.add(c1);p2.add(l2);p2.add(c2);p3.add(b1);p3.add(b2);

f8.setLayout(new FlowLayout());f8.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);f8.setSize(Toolkit.getDefaultToolkit().getScreenSize());f8.setVisible(true);f8.add(Box.createRigidArea(new Dimension(width,20)));f8.add(l);f8.add(Box.createRigidArea(new Dimension(width,35)));f8.add(p1);f8.add(Box.createRigidArea(new Dimension(width,15)));f8.add(p2);f8.add(Box.createRigidArea(new Dimension(width,30)));f8.add(p3);b1.addActionListener(this);b2.addActionListener(this);

}public void actionPerformed(ActionEvent e){

if(e.getSource()==b1){

int i1=c1.getSelectedIndex();

Page 16: 26714384 Hostel Management System Source Code in JAVA by B Vinod Kumar

int i2=c2.getSelectedIndex();if(i1==0||i2==0)

JOptionPane.showMessageDialog(null,"Please Select both");else{

if(i2==1){

ViewAll v=new ViewAll(i1);c1.setSelectedIndex(0);c2.setSelectedIndex(0);

}else if(i2==2){

Branch b=new Branch(i1);f8.dispose();

}else if(i2==3){

Mess m=new Mess(i1);f8.dispose();

}}

}if(e.getSource()==b2){

StudentDetails s=new StudentDetails();f8.dispose();

}}

}class ViewAll implements ActionListener{

JFrame f9;JScrollPane p;JTable tab;JButton b;String[] columnNames = {"Roll Number","Name","Mess Number","Address","Branch","Year"Object[][] data=new Object[100][100];String s1;ViewAll(int i1){

switch(i1){

case 1:s1="select * from student where year="+1+"";break;case 2:s1="select * from student where year="+2+"";break;case 3:s1="select * from student where year="+3+"";break;case 4:s1="select * from student where year="+4+"";break;

}try{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");Connection con = DriverManager.getConnection("jdbc:odbc:Mydatabase",Statement st=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResResultSet rs=st.executeQuery(s1);if(!rs.next()){

JOptionPane.showMessageDialog(null,"No One exists with the g}else{

Page 17: 26714384 Hostel Management System Source Code in JAVA by B Vinod Kumar

rs.previous();int i=0,j=0;String s2="",s3="";while(rs.next()){

data[i][j]=rs.getString(1);j++;data[i][j]=rs.getString(2);j++;data[i][j]=rs.getString(3);j++;data[i][j]=rs.getString(4);j++;data[i][j]=rs.getString(5);j++;int in=Integer.parseInt(rs.getString(6));switch(in){

case 1:s2="1st year,B.TECH";break;case 2:s2="2nd year,B.TECH";break;case 3:s2="3rd year,B.TECH";break;case 4:s2="4th year,B.TECH";break;

}char ch=rs.getString(7).charAt(0);switch(ch){

case 'n':s3="Non-Veg";break;case 'v':s3="Veg";break;

}data[i][j]=s2;j++;data[i][j]=s3;j++;j=0;i++;

}f9=new JFrame("Details of all Students..Year Wise");b=new JButton("Click me to close this");tab= new JTable(data, columnNames);TableColumn column = null;for (i = 0; i < 7; i++){

column = tab.getColumnModel().getColumn(i);if (i==1)

column.setMinWidth(50); else if(i==0)

column.setMinWidth(25); else if(i==3)

column.setMinWidth(500);else if(i==2)

column.setMinWidth(11);else if(i==4)

column.setMinWidth(6);else if(i==5)

column.setMinWidth(16);else if(i==6)

column.setMinWidth(8); }p=new JScrollPane(tab);f9.setSize(Toolkit.getDefaultToolkit().getScreenSize());f9.setVisible(true);f9.add(b,BorderLayout.NORTH);f9.add(p,BorderLayout.CENTER);f9.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);b.addActionListener(this);

}}catch(Exception e)

Page 18: 26714384 Hostel Management System Source Code in JAVA by B Vinod Kumar

{System.out.println(e.toString());

}}public void actionPerformed(ActionEvent e1){

f9.dispose();}

}class Branch implements ActionListener{

JFrame f10;JLabel l1,l2;JComboBox c;JButton b1,b2,b3;JScrollPane sp;JPanel p1,p2;JTable t;String[] columnNames = {"Roll Number","Name","Mess Number","Address","Branch","Year"Object[][] data=new Object[100][100];String s1;Branch(int i1){

f10=new JFrame("Branch Wise student Details of Year : "+i1);l1=new JLabel("Please Select Branch and Click 'view'");l1.setForeground(Color.BLUE);l1.setFont(new Font(Font.SANS_SERIF,Font.BOLD,25));l2=new JLabel("Branch:");String branch[]={"<Select>","CIVIL","EEE","MECH","ECE","CSE","MET"};c=new JComboBox(branch);b1=new JButton("View");b2=new JButton("Reset");b3=new JButton("Back");p1=new JPanel();p2=new JPanel();p1.add(l2);p1.add(c);p2.add(b1);p2.add(b2);p2.add(b3);f10.setSize(Toolkit.getDefaultToolkit().getScreenSize());f10.setVisible(true);f10.setLayout(new FlowLayout());Dimension d=Toolkit.getDefaultToolkit().getScreenSize();int width=(int)d.getWidth();f10.add(Box.createRigidArea(new Dimension(width,10)));f10.add(l1);f10.add(Box.createRigidArea(new Dimension(width,30)));f10.add(p1);f10.add(Box.createRigidArea(new Dimension(width,20)));f10.add(p2);

f10.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);b1.addActionListener(this);b2.addActionListener(this);b3.addActionListener(this);b1.setActionCommand(i1+"");

}public void actionPerformed(ActionEvent e)

Page 19: 26714384 Hostel Management System Source Code in JAVA by B Vinod Kumar

{if(e.getSource()==b1){

final JFrame f11=new JFrame("Student Details Branch Wise");JButton jb=new JButton("View Another");int i2=c.getSelectedIndex();final int i1=Integer.parseInt(b1.getActionCommand());String br="";switch(i2){

case 1:br="CIV";break;case 2:br="EEE";break;case 3:br="MEC";break;case 4:br="ECE";break;case 5:br="CSE";break;case 6:br="MET";break;

}s1="select * from student where year="+i1+" and branch='"+br+"'";try{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");Connection con = DriverManager.getConnection("jdbc:odbc:MydaStatement st=con.createStatement(ResultSet.TYPE_SCROLL_SENSIResultSet rs=st.executeQuery(s1);if(!rs.next()){

JOptionPane.showMessageDialog(null,"No One exists wi}else{

rs.previous();int i=0,j=0;String s2="",s3="";while(rs.next()){

data[i][j]=rs.getString(1);j++;data[i][j]=rs.getString(2);j++;data[i][j]=rs.getString(3);j++;data[i][j]=rs.getString(4);j++;data[i][j]=rs.getString(5);j++;int in=Integer.parseInt(rs.getString(6));switch(in){

case 1:s2="1st year,B.TECH";break;case 2:s2="2nd year,B.TECH";break;case 3:s2="3rd year,B.TECH";break;case 4:s2="4th year,B.TECH";break;

}char ch=rs.getString(7).charAt(0);switch(ch){

case 'n':s3="Non-Veg";break;case 'v':s3="Veg";break;

}data[i][j]=s2;j++;data[i][j]=s3;j++;j=0;i++;

}t= new JTable(data, columnNames);TableColumn column = null;

Page 20: 26714384 Hostel Management System Source Code in JAVA by B Vinod Kumar

for (i = 0; i < 7; i++){

column = t.getColumnModel().getColumn(i);if (i==1)

column.setMinWidth(50); else if(i==0)

column.setMinWidth(25); else if(i==3)

column.setMinWidth(500);else if(i==2)

column.setMinWidth(11);else if(i==4)

column.setMinWidth(6);else if(i==5)

column.setMinWidth(16);else if(i==6)

column.setMinWidth(8); }sp=new JScrollPane(t);f11.setSize(Toolkit.getDefaultToolkit().getScreenSizf11.setVisible(true);f11.add(jb,BorderLayout.NORTH);f11.add(sp,BorderLayout.CENTER);f10.dispose();jb.addActionListener(new ActionListener(){public voi

}}catch(Exception e1){

System.out.println(e.toString());}

}if(e.getSource()==b2){

c.setSelectedIndex(0);}if(e.getSource()==b3){

Year y=new Year();f10.dispose();

}}

}class Mess implements ActionListener{

JFrame f12;JLabel la1,la2,l1,l2,l3,l4,l5,l6,l7;JTextField t,t1,t2,t3;JTextArea t4;JTextField t5,t6,t7;JButton b1,b2,b3;JPanel p,p1,p2,p3,p4,p5,p6,p7,p8;Mess(int i1){

f12=new JFrame("Mess number Wise Student details");l1=new JLabel("Roll Number :");l2=new JLabel("Name :");l3=new JLabel("Mess No :");l4=new JLabel("Address :");l5=new JLabel("Branch :");

Page 21: 26714384 Hostel Management System Source Code in JAVA by B Vinod Kumar

l6=new JLabel("Year :");l7=new JLabel("Type :");la1=new JLabel("Enter the Mess number and click 'view'");la1.setFont(new Font(Font.SANS_SERIF,Font.BOLD,25));la1.setForeground(Color.BLUE);la2=new JLabel("Enter Mess number here:");b1=new JButton("View");b2=new JButton("View Another");b3=new JButton("Back");t=new JTextField(15);t1=new JTextField(15);t2=new JTextField(15);t3=new JTextField(15);t4=new JTextArea(10,20);t5=new JTextField(15);t6=new JTextField(15);t7=new JTextField(15);t1.setEditable(false);t2.setEditable(false);t3.setEditable(false);t4.setEditable(false);t5.setEditable(false);t6.setEditable(false);t7.setEditable(false);p=new JPanel();p1=new JPanel();p2=new JPanel();p3=new JPanel();p4=new JPanel();p5=new JPanel();p6=new JPanel();p7=new JPanel();p8=new JPanel();p.add(la2);p.add(t);p.add(b1);p1.add(l1);p1.add(t1);p2.add(l2);p2.add(t2);p3.add(l3);p3.add(t3);p4.add(l4);p4.add(t4);p5.add(l5);p5.add(t5);p6.add(l6);p6.add(t6);p7.add(l7);p7.add(t7);p8.add(b2);p8.add(b3);f12.setLayout(new FlowLayout());f12.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);f12.setSize(Toolkit.getDefaultToolkit().getScreenSize());f12.setVisible(true);

Dimension d=Toolkit.getDefaultToolkit().getScreenSize();int width=(int)d.getWidth();f12.add(Box.createRigidArea(new Dimension(width,20)));

Page 22: 26714384 Hostel Management System Source Code in JAVA by B Vinod Kumar

f12.add(la1);f12.add(Box.createRigidArea(new Dimension(width,10)));f12.add(p);f12.add(Box.createRigidArea(new Dimension(width,10)));f12.add(p1);f12.add(Box.createRigidArea(new Dimension(width,10)));f12.add(p2);f12.add(Box.createRigidArea(new Dimension(width,10)));f12.add(p3);f12.add(Box.createRigidArea(new Dimension(width,10)));f12.add(p4);f12.add(Box.createRigidArea(new Dimension(width,10)));f12.add(p5);f12.add(Box.createRigidArea(new Dimension(width,10)));f12.add(p6);f12.add(Box.createRigidArea(new Dimension(width,10)));f12.add(p7);f12.add(Box.createRigidArea(new Dimension(width,10)));f12.add(p8);b1.addActionListener(this);b2.addActionListener(this);b3.addActionListener(this);b2.setActionCommand(i1+"");b1.setActionCommand(i1+"");

}public void actionPerformed(ActionEvent e){

if(e.getSource()==b1){

try{

String s1=t.getText();int i1=Integer.parseInt(b1.getActionCommand());if(s1.equals(""))

JOptionPane.showMessageDialog(null,"Please specify Melse{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");Connection con = DriverManager.getConnection("jdbc:oStatement st=con.createStatement();int i2=Integer.parseInt(s1);String s="select * from student where year="+i1+" anResultSet rs=st.executeQuery(s);if(rs.next()){

t1.setText(rs.getString(1));t2.setText(rs.getString(2));t3.setText(rs.getString(3));t4.setText(rs.getString(4));t5.setText(rs.getString(5));int i=Integer.parseInt(rs.getString(6));switch(i){

case 1:t6.setText("1st year,B.TECH")case 2:t6.setText("2nd year,B.TECH")case 3:t6.setText("3rd year,B.TECH")case 4:t6.setText("4th year,B.TECH")

}char ch=rs.getString(7).charAt(0);switch(ch)

Page 23: 26714384 Hostel Management System Source Code in JAVA by B Vinod Kumar

{case 'n':t7.setText("Non-Veg");breakcase 'v':t7.setText("Veg");break;

}}else{

JOptionPane.showMessageDialog(null,"The Messt.setText("");t1.setText("");t2.setText("");t3.setText("");t4.setText("");t5.setText("");t6.setText("");t7.setText("");

}}

}catch(Exception e1){System.out.println(e1.toString());}

}if(e.getSource()==b2){

Mess m=new Mess(Integer.parseInt(b2.getActionCommand()));f12.dispose();

}if(e.getSource()==b3){

Year y=new Year();f12.dispose();

}}

}class Addastudent implements ActionListener{

JButton b1,b2,b3;JLabel l,l1,l2,l3,l4,l5,l6,l7;JTextField t1,t2,t3;JTextArea t4;JComboBox c1,c2;JRadioButton r1,r2;ButtonGroup bg;//Scrollbar sb;JPanel p,p1,p2,p3,p4,p5,p6,p7,p8;JFrame f3;Addastudent(){

f3=new JFrame("Add A Student");

//sb=new Scrollbar(Scrollbar.HORIZONTAL);

b1=new JButton("Add");b2=new JButton("Reset");b3=new JButton("Cancel");l=new JLabel("fill the following details");l.setFont(new Font(Font.SANS_SERIF,Font.BOLD,25));l1=new JLabel("Roll Number :");

Page 24: 26714384 Hostel Management System Source Code in JAVA by B Vinod Kumar

l2=new JLabel("Name :");l3=new JLabel("Mess No :");l4=new JLabel("Address :");l5=new JLabel("Branch :");l6=new JLabel("Year :");l7=new JLabel("Type :");t1=new JTextField(15);t2=new JTextField(15);t3=new JTextField(15);t4=new JTextArea(7,20);

String branch[]={"<Select>","CIVIL","EEE","MECH","ECE","CSE","MET"};String year[]={"<Select>","1","2","3","4"};c1=new JComboBox(branch);c2=new JComboBox(year);r1=new JRadioButton("Veg");r2=new JRadioButton("Non-veg",true);bg=new ButtonGroup();bg.add(r1);bg.add(r2);p=new JPanel();p1=new JPanel();p2=new JPanel();p3=new JPanel();p4=new JPanel();p5=new JPanel();p6=new JPanel();p7=new JPanel();p8=new JPanel();p.add(l);p1.add(l1);p1.add(t1);p2.add(l2);p2.add(t2);p3.add(l3);p3.add(t3);p4.add(l4);p4.add(t4);//p4.add(sb);p5.add(l5);p5.add(c1);p6.add(l6);p6.add(c2);p7.add(l7);p7.add(r1);p7.add(r2);p8.add(b1);p8.add(b2);p8.add(b3);f3.setLayout(new FlowLayout());f3.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);f3.setSize(Toolkit.getDefaultToolkit().getScreenSize());f3.setVisible(true);

Dimension d=Toolkit.getDefaultToolkit().getScreenSize();int width=(int)d.getWidth();

f3.add(Box.createRigidArea(new Dimension(width,10)));f3.add(p);

f3.add(Box.createRigidArea(new Dimension(width,20)));

Page 25: 26714384 Hostel Management System Source Code in JAVA by B Vinod Kumar

f3.add(p1);f3.add(Box.createRigidArea(new Dimension(width,10)));f3.add(p2);f3.add(Box.createRigidArea(new Dimension(width,10)));f3.add(p3);f3.add(Box.createRigidArea(new Dimension(width,10)));f3.add(p4);f3.add(Box.createRigidArea(new Dimension(width,10)));f3.add(p5);f3.add(Box.createRigidArea(new Dimension(width,10)));f3.add(p6);f3.add(Box.createRigidArea(new Dimension(width,10)));f3.add(p7);

f3.add(Box.createRigidArea(new Dimension(width,10)));f3.add(p8);b1.addActionListener(this);

b2.addActionListener(this);b3.addActionListener(this);t1.requestFocus(true);

}public void actionPerformed(ActionEvent e){

if(e.getSource()==b1){

try{

String s1,s2,s3,s4,s5=null,s6,s7;int i1,i2=0,i3,i4;s1=t1.getText().toUpperCase();s2=t2.getText().toUpperCase();s3=t3.getText();s4=t4.getText();i3=c1.getSelectedIndex();i4=c2.getSelectedIndex();boolean b=r1.isSelected();char type;if(s1.equals("")||s2.equals("")||s3.equals("")||s4.equals(""{

JOptionPane.showMessageDialog(null,"Please fill in a}else{

switch(i3){

case 1: s5="CIV"; break;case 2: s5="EEE"; break;case 3: s5="MEC"; break;case 4: s5="ECE"; break;case 5: s5="CSE"; break;case 6: s5="MET"; break;

}switch(i4){

case 1:i2=1; break;case 2:i2=2;break;case 3:i2=3;break;case 4:i2=4;break;

}if(b)

Page 26: 26714384 Hostel Management System Source Code in JAVA by B Vinod Kumar

type='v';else

type='n';i1=Integer.parseInt(s3);Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");Connection con = DriverManager.getConnection("jdbc:oStatement st=con.createStatement();String s="insert into student values('"+s1+"','"+s2+st.execute(s);JOptionPane.showMessageDialog(null,"Student added su

}t1.setText(null);t2.setText(null);t3.setText(null);t4.setText(null);c1.setSelectedIndex(0);c2.setSelectedIndex(0);r2.setSelected(true);t1.requestFocus(true);

}catch(Exception e1){

JOptionPane.showMessageDialog(null,"Given roll number alreadt1.setText(null);t2.setText(null);t3.setText(null);t4.setText(null);c1.setSelectedIndex(0);c2.setSelectedIndex(0);r2.setSelected(true);t1.requestFocus(true);

}}if(e.getSource()==b2){

t1.setText(null);t2.setText(null);t3.setText(null);t4.setText(null);c1.setSelectedIndex(0);c2.setSelectedIndex(0);r2.setSelected(true);t1.requestFocus(true);

}if(e.getSource()==b3){

Stud s2=new Stud();f3.dispose();

}}

}class RemoveStudent implements ActionListener{

JFrame f;JLabel l1,l2;JTextField t;JButton b1,b2;RemoveStudent(){

f=new JFrame("Remove Student");

Page 27: 26714384 Hostel Management System Source Code in JAVA by B Vinod Kumar

l1=new JLabel("Please enter the roll number and click 'Remove' button");l1.setFont(new Font(Font.SANS_SERIF,Font.BOLD,25));l1.setForeground(Color.RED);l2=new JLabel("Enter the roll number here:");t=new JTextField(15);b1=new JButton("Remove");b1.setFont(new Font(Font.SANS_SERIF,Font.BOLD,15));b2=new JButton("Cancel");b2.setFont(new Font(Font.SANS_SERIF,Font.BOLD,15));f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);f.setSize(Toolkit.getDefaultToolkit().getScreenSize());f.setVisible(true);f.setLayout(new FlowLayout());

Dimension d=Toolkit.getDefaultToolkit().getScreenSize();int width=(int)d.getWidth();

f.add(Box.createRigidArea(new Dimension(width,30)));f.add(l1);f.add(Box.createRigidArea(new Dimension(width,50))); f.add(l2);f.add(t);f.add(Box.createRigidArea(new Dimension(width,30)));f.add(b1);f.add(b2);b1.addActionListener(this);

b2.addActionListener(this);}public void actionPerformed(ActionEvent e){

if(e.getSource()==b1){

String s=t.getText().toUpperCase();if(s.equals(""))

JOptionPane.showMessageDialog(null,"Please Enter Roll Numberelse{

try{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");Connection con = DriverManager.getConnection("jdbc:oStatement st=con.createStatement();String s1="select * from student where rno='"+s+"'";ResultSet rs=st.executeQuery(s1);if(rs.next()){

s1="delete from student where rno='"+s+"'";st.execute(s1);JOptionPane.showMessageDialog(null,"Student

}else

JOptionPane.showMessageDialog(null,"The rollt.setText("");

}catch(Exception e1){

JOptionPane.showMessageDialog(null,"Please enter valt.setText("");

}}

Page 28: 26714384 Hostel Management System Source Code in JAVA by B Vinod Kumar

}if(e.getSource()==b2){

Stud s=new Stud();f.dispose();

}}

}class UpdateStudent implements ActionListener{

JFrame f5;JLabel la1,la2;JTextField t;JButton b1,b2;JPanel p1,p2;UpdateStudent(){

f5=new JFrame("Updating Student details");la1=new JLabel("Enter the roll number and click 'GO' ");la1.setFont(new Font(Font.SANS_SERIF,Font.BOLD,25));la1.setForeground(Color.RED);la2=new JLabel("Enter roll number here:");b1=new JButton("Go");b2=new JButton("Cancel");t=new JTextField(15);p1=new JPanel();p2=new JPanel();p1.add(la2);p1.add(t);p2.add(b1);p2.add(Box.createHorizontalStrut(20));p2.add(b2);f5.setLayout(new FlowLayout());f5.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);f5.setSize(Toolkit.getDefaultToolkit().getScreenSize());f5.setVisible(true);

Dimension d=Toolkit.getDefaultToolkit().getScreenSize();int width=(int)d.getWidth();f5.add(Box.createRigidArea(new Dimension(width,50)));f5.add(la1);f5.add(Box.createRigidArea(new Dimension(width,30)));f5.add(p1);f5.add(Box.createRigidArea(new Dimension(width,30)));f5.add(p2);t.requestFocus(true);b1.addActionListener(this);b2.addActionListener(this);

}public void actionPerformed(ActionEvent e){

if(e.getSource()==b1){

String s1=t.getText().toUpperCase();if(s1.equals("")){

JOptionPane.showMessageDialog(null,"Please specify the roll t.requestFocus(true);

Page 29: 26714384 Hostel Management System Source Code in JAVA by B Vinod Kumar

}else{

UpdateStudent1 us1=new UpdateStudent1(s1);f5.dispose();

}}if(e.getSource()==b2){

Stud sw=new Stud();f5.dispose();

}}

}class UpdateStudent1 implements ActionListener{

JFrame f;JLabel l1,l2,l3,l4,l5,l6,l7;JTextField t1,t2,t3;JTextArea t4;JComboBox c1,c2,c3;JButton b1,b2,b3;JPanel p,p1,p2,p3,p4,p5,p6,p7;UpdateStudent1(String s){

f=new JFrame("Updating Stedent Details with roll number "+s);String branch[]={"<Select>","CIVIL","EEE","MECH","ECE","CSE","MET"};String year[]={"<Select>","1","2","3","4"};String type[]={"<select>","Veg","Non-veg"};c1=new JComboBox(branch);c2=new JComboBox(year);c3=new JComboBox(type);l1=new JLabel("Roll Number :");l2=new JLabel("Name :");l3=new JLabel("Mess No :");l4=new JLabel("Address :");l5=new JLabel("Branch :");l6=new JLabel("Year :");l7=new JLabel("Type :");b1=new JButton("Update");b2=new JButton("Cancel");b3=new JButton("Go to Main Page");t1=new JTextField(15);t2=new JTextField(15);t3=new JTextField(15);t4=new JTextArea(10,20);t1.setEditable(false);p=new JPanel();p1=new JPanel();p2=new JPanel();p3=new JPanel();p4=new JPanel();p5=new JPanel();p6=new JPanel();p7=new JPanel();p1.add(l1);p1.add(t1);p2.add(l2);p2.add(t2);p3.add(l3);

Page 30: 26714384 Hostel Management System Source Code in JAVA by B Vinod Kumar

p3.add(t3);p4.add(l4);p4.add(t4);p5.add(l5);p5.add(c1);p6.add(l6);p6.add(c2);p7.add(l7);p7.add(c3);p.add(b1);p.add(b2);p.add(b3);f.setLayout(new FlowLayout());f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);f.setSize(Toolkit.getDefaultToolkit().getScreenSize());f.setVisible(true);f.add(p1);f.add(p2);f.add(p3);f.add(p4);f.add(p5);f.add(p6);f.add(p7);f.add(p);b1.addActionListener(this);b1.setActionCommand(s);b2.addActionListener(this);b3.addActionListener(this);try{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");Connection con = DriverManager.getConnection("jdbc:odbc:Mydatabase",Statement st=con.createStatement();String s1="select * from student where rno='"+s+"'";ResultSet rs=st.executeQuery(s1);if(rs.next()){

t1.setText(rs.getString(1));t2.setText(rs.getString(2));t3.setText(rs.getString(3));t4.setText(rs.getString(4));c1.setSelectedItem(rs.getString(5));c2.setSelectedItem(rs.getString(6));char ch=rs.getString(7).charAt(0);switch(ch){

case 'n':c3.setSelectedIndex(2);break;case 'v':c3.setSelectedIndex(1);break;

}}else{

f.dispose();JOptionPane.showMessageDialog(null,"The roll number is invalUpdateStudent us=new UpdateStudent();

}}catch(Exception e1){

System.out.println(e1.toString());

Page 31: 26714384 Hostel Management System Source Code in JAVA by B Vinod Kumar

}}public void actionPerformed(ActionEvent e){

if(e.getSource()==b1){

String s1=b1.getActionCommand();try{

String s2,s3,s4,s5=null;int i,i2=0;s2=t2.getText().toUpperCase();s3=t3.getText();i=Integer.parseInt(s3);s4=t4.getText();int i5=c1.getSelectedIndex();int i6=c2.getSelectedIndex();switch(i5){

case 1: s5="CIV"; break;case 2: s5="EEE"; break;case 3: s5="MEC"; break;case 4: s5="ECE"; break;case 5: s5="CSE"; break;case 6: s5="MET"; break;

}switch(i6){

case 1:i2=1; break;case 2:i2=2;break;case 3:i2=3;break;case 4:i2=4;break;

}char ca=' ';int i7=c3.getSelectedIndex();switch(i7){

case 1: ca='n';case 2: ca='v';

}if(s2.equals("")||s3.equals("")||s4.equals("")||c1.getSelect{

JOptionPane.showMessageDialog(null,"Please fill in a}else{

i=Integer.parseInt(s3);Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");Connection con = DriverManager.getConnection("jdbc:oStatement st=con.createStatement();String s="delete from student where rno='"+s1+"'";st.execute(s);String str="insert into student values('"+s1+"','"+sst.execute(str);JOptionPane.showMessageDialog(null,"Student details Stud sg=new Stud();f.dispose();

}}catch(Exception e1)

Page 32: 26714384 Hostel Management System Source Code in JAVA by B Vinod Kumar

{JOptionPane.showMessageDialog(null,"Some error occured...Ple

}}if(e.getSource()==b2){

Stud sd=new Stud();f.dispose();

}if(e.getSource()==b3){

Main me=new Main();f.dispose();

}}

}class Accounts implements ActionListener{

JFrame f;JLabel l;JRadioButton b1,b2,b3,b4;ButtonGroup bg;JButton b5;Accounts(){

f=new JFrame("Accounts");l=new JLabel("Click on the required button");l.setFont(new Font(Font.SANS_SERIF,Font.PLAIN,25));b1=new JRadioButton("Store Details ",false);b1.setFont(new Font("ARIAL",Font.PLAIN,20));b2=new JRadioButton("Show Details ",false);b2.setFont(new Font("ARIAL",Font.PLAIN,20));b3=new JRadioButton("Get the due ",false);b3.setFont(new Font("ARIAL",Font.PLAIN,20));b4=new JRadioButton("Display monthly bills",false);b4.setFont(new Font("ARIAL",Font.PLAIN,20));b5=new JButton("Go to Main Page");b5.setFont(new Font("ARIAL",Font.PLAIN,20));f.setLayout(new FlowLayout());f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);f.setSize(Toolkit.getDefaultToolkit().getScreenSize());f.setVisible(true);Dimension d=Toolkit.getDefaultToolkit().getScreenSize();int width=(int)d.getWidth();f.setSize(d);f.add(Box.createRigidArea(new Dimension(width,20)));f.add(l);f.add(Box.createRigidArea(new Dimension(width,100)));f.add(b2);f.add(Box.createRigidArea(new Dimension(width,5)));f.add(b1);f.add(Box.createRigidArea(new Dimension(width,5)));f.add(b3);f.add(Box.createRigidArea(new Dimension(width,5)));f.add(b4);f.add(Box.createRigidArea(new Dimension(width,30)));f.add(b5);b1.addActionListener(this);b2.addActionListener(this);b3.addActionListener(this);

Page 33: 26714384 Hostel Management System Source Code in JAVA by B Vinod Kumar

b4.addActionListener(this);b5.addActionListener(this);

}public void actionPerformed(ActionEvent e){

if(b1.isSelected()){

StoreDetails sd=new StoreDetails();f.dispose();

}if(b2.isSelected()){

ShowDetails sd1=new ShowDetails();f.dispose();

}if(b3.isSelected()){

Due d=new Due();f.dispose();

}if(b4.isSelected()){

Display ds=new Display();f.dispose();

}if(e.getSource()==b5){

Main m2=new Main();f.dispose();

}}

}

class ShowDetails implements ActionListener{

JFrame f;JLabel l,l1;JTextField t;JButton b1,b2;JPanel p1,p2;ShowDetails(){

f=new JFrame("Student Account Details");l=new JLabel("Please Enter the roll number and click view");l.setForeground(Color.RED);l.setFont(new Font(Font.SANS_SERIF,Font.PLAIN,25));l1=new JLabel("Enter the roll number here:");l1.setFont(new Font(Font.SANS_SERIF,Font.PLAIN,20));t=new JTextField(15);b1=new JButton("View");b1.setFont(new Font("ARIAL",Font.PLAIN,18));b2=new JButton("Cancel");b2.setFont(new Font("ARIAL",Font.PLAIN,18));p1=new JPanel();p2=new JPanel();p1.add(l1);p1.add(t);p2.add(b1);p2.add(Box.createHorizontalStrut(20));p2.add(b2);

Page 34: 26714384 Hostel Management System Source Code in JAVA by B Vinod Kumar

Dimension d=Toolkit.getDefaultToolkit().getScreenSize();int width=(int)d.getWidth();f.setSize(d);f.setLayout(new FlowLayout());f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);f.add(Box.createRigidArea(new Dimension(width,20)));f.add(l);f.add(Box.createRigidArea(new Dimension(width,20)));f.add(p1);f.add(Box.createRigidArea(new Dimension(width,20)));f.add(p2);f.setVisible(true);b1.addActionListener(this);

b2.addActionListener(this);}public void actionPerformed(ActionEvent e){

if(e.getSource()==b1){

String s1=t.getText().toUpperCase();if(s1.equals(""))

JOptionPane.showMessageDialog(null,"Please specify the roll else{

try{

String[] columnNames = {"Month","No.of Days","Total Object[][] data=new Object[100][100];Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");Connection con = DriverManager.getConnection("jdbc:oStatement st=con.createStatement(ResultSet.TYPE_SCROString s="select *from bill where rno='"+s1+"'";ResultSet rs=st.executeQuery(s);if(!rs.next()){

JOptionPane.showMessageDialog(null,"No One et.setText("");

}else{

rs.previous();int i=0,j=0;while(rs.next()){

data[i][j]=rs.getString(2);j++;data[i][j]=rs.getString(3);j++;data[i][j]=rs.getString(4);j++;data[i][j]=rs.getString(5);j++;data[i][j]=rs.getString(6);j++;j=0;i++;

}JLabel l2,l3,l4;JTextField t1,t2,t3;JPanel p;l2=new JLabel("Roll Number");l3=new JLabel("Name:");l4=new JLabel("Mess Number:");t1=new JTextField(15);t2=new JTextField(30);t3=new JTextField(5);

Page 35: 26714384 Hostel Management System Source Code in JAVA by B Vinod Kumar

t1.setEditable(false);t2.setEditable(false);t3.setEditable(false);JButton b=new JButton("Close");s="select rno,name,messno from student wherers=st.executeQuery(s);if(rs.next()){

t1.setText(rs.getString(1));t2.setText(rs.getString(2));t3.setText(rs.getString(3));

}p=new JPanel();p.add(l2);p.add(t1);p.add(l3);p.add(t2);p.add(l4);p.add(t3);p.add(b);JTable tab= new JTable(data, columnNames);JScrollPane sp=new JScrollPane(tab);final JFrame f1=new JFrame("Student Account f1.setSize(Toolkit.getDefaultToolkit().getScf1.setVisible(true);f1.add(p,BorderLayout.NORTH);f1.add(sp,BorderLayout.CENTER);f1.setDefaultCloseOperation(JFrame.EXIT_ON_Cb.addActionListener(new ActionListener(){pubf.dispose();

}}catch(Exception e1){

System.out.println(e.toString());}

}}if(e.getSource()==b2){

Accounts ac=new Accounts();f.dispose();

}}

}

class StoreDetails implements ActionListener{

JFrame f;JRadioButton b1,b2;JButton b;StoreDetails(){

f=new JFrame("Storing student account details");b1=new JRadioButton("Store Bill Details ");b2=new JRadioButton("Store Payment deatils");b1.setFont(new Font("ARIAL",Font.PLAIN,20));b2.setFont(new Font("ARIAL",Font.PLAIN,20));b=new JButton("Back");b.setFont(new Font("ARIAL",Font.PLAIN,18));

Page 36: 26714384 Hostel Management System Source Code in JAVA by B Vinod Kumar

Dimension d=Toolkit.getDefaultToolkit().getScreenSize();int width=(int)d.getWidth();f.setSize(d);f.setLayout(new FlowLayout());f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);f.add(Box.createRigidArea(new Dimension(width,200)));f.add(b1);f.add(Box.createRigidArea(new Dimension(width,5)));f.add(b2);f.add(Box.createRigidArea(new Dimension(width,40)));f.add(b);f.setVisible(true);b1.addActionListener(this);b2.addActionListener(this);b.addActionListener(this);

}public void actionPerformed(ActionEvent e){

if(b1.isSelected()){

final JFrame f1=new JFrame("Storing bill details");JLabel l,l1,l2,l3,l4;final JTextField t1,t2,t3,t4;JButton b1,b2,b3;JPanel p,p1,p2,p3,p4;l=new JLabel("Please fill in all details and click Store");l.setFont(new Font(Font.SANS_SERIF,Font.PLAIN,25));l1=new JLabel("Roll number:");l1.setFont(new Font(Font.SANS_SERIF,Font.PLAIN,18));l2=new JLabel("Month(mm/yyyy):");l2.setFont(new Font(Font.SANS_SERIF,Font.PLAIN,18));l3=new JLabel("No. of days attended:");l3.setFont(new Font(Font.SANS_SERIF,Font.PLAIN,18));l4=new JLabel("Bill for this month:");l4.setFont(new Font(Font.SANS_SERIF,Font.PLAIN,18));t1=new JTextField(15);t2=new JTextField(15);t3=new JTextField(15);t4=new JTextField(15);b1=new JButton("Store");b2=new JButton("Reset");b3=new JButton("Cancel");p=new JPanel();p1=new JPanel();p2=new JPanel();p3=new JPanel();p4=new JPanel();p.add(b1);p.add(Box.createHorizontalStrut(20));p.add(b2);p.add(Box.createHorizontalStrut(20));p.add(b3);p1.add(l1);p1.add(t1);p2.add(l2);p2.add(t2);p3.add(l3);p3.add(t3);p4.add(l4);p4.add(t4);

Page 37: 26714384 Hostel Management System Source Code in JAVA by B Vinod Kumar

Dimension d=Toolkit.getDefaultToolkit().getScreenSize();int width=(int)d.getWidth();f1.setSize(d);f1.setLayout(new FlowLayout());f1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);f1.add(Box.createRigidArea(new Dimension(width,20)));f1.add(l);f1.add(Box.createRigidArea(new Dimension(width,100)));f1.add(p1);f1.add(Box.createRigidArea(new Dimension(width,5)));f1.add(p2);f1.add(Box.createRigidArea(new Dimension(width,5)));f1.add(p3);f1.add(Box.createRigidArea(new Dimension(width,5)));f1.add(p4);f1.add(Box.createRigidArea(new Dimension(width,30)));f1.add(p);f1.setVisible(true);f.dispose();b1.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e1){try{

String s1=t1.getText().toUpperCase();String s2=t2.getText();String s3=t3.getText();String s4=t4.getText();if(s1.equals("")||s2.equals("")||s3.equals("

JOptionPane.showMessageDialog(null,"else{

int i1=Integer.parseInt(s3);int i2=Integer.parseInt(s4);Class.forName("sun.jdbc.odbc.JdbcOdbConnection con =DriverManager.getConStatement s=con.createStatement();String sq1="insert into bill (rno,mos.execute(sq1);JOptionPane.showMessageDialog(null,"t1.setText("");t2.setText("");t3.setText("");t4.setText("");

}}catch(Exception e2){

System.out.println(e2.toString());}

}});b2.addActionListener(new ActionListener(){public void actionPerforme {

t1.setText("");t2.setText("");t3.setText("");t4.setText("");

}});b3.addActionListener(new ActionListener(){public void actionPerforme {

Accounts ac=new Accounts();

Page 38: 26714384 Hostel Management System Source Code in JAVA by B Vinod Kumar

f1.dispose(); }});

}if(b2.isSelected()){

final JFrame f2=new JFrame("Storing payment details");JLabel l,l1,l2,l3,l4;final JTextField t1,t2,t3;final JTextArea t4;JButton b1,b2,b3;JPanel p,p1,p2,p3,p4;l=new JLabel("Please fill in all details and click Store");l.setFont(new Font(Font.SANS_SERIF,Font.PLAIN,25));l1=new JLabel("Roll number:");l1.setFont(new Font(Font.SANS_SERIF,Font.PLAIN,18));l2=new JLabel("Month(mm/yyyy):");l2.setFont(new Font(Font.SANS_SERIF,Font.PLAIN,18));l3=new JLabel("Paid Amount:");l3.setFont(new Font(Font.SANS_SERIF,Font.PLAIN,18));l4=new JLabel("Payment Details:");l4.setFont(new Font(Font.SANS_SERIF,Font.PLAIN,18));t1=new JTextField(15);t2=new JTextField(15);t3=new JTextField(15);t4=new JTextArea(15,15);b1=new JButton("Store");b2=new JButton("Reset");b3=new JButton("Cancel");p=new JPanel();p1=new JPanel();p2=new JPanel();p3=new JPanel();p4=new JPanel();p.add(b1);p.add(Box.createHorizontalStrut(20));p.add(b2);p.add(Box.createHorizontalStrut(20));p.add(b3);p1.add(l1);p1.add(t1);p2.add(l2);p2.add(t2);p3.add(l3);p3.add(t3);p4.add(l4);p4.add(t4);Dimension d=Toolkit.getDefaultToolkit().getScreenSize();int width=(int)d.getWidth();f2.setSize(d);f2.setLayout(new FlowLayout());f2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);f2.add(Box.createRigidArea(new Dimension(width,20)));f2.add(l);f2.add(Box.createRigidArea(new Dimension(width,100)));f2.add(p1);f2.add(Box.createRigidArea(new Dimension(width,5)));f2.add(p2);f2.add(Box.createRigidArea(new Dimension(width,5)));f2.add(p3);f2.add(Box.createRigidArea(new Dimension(width,5)));

Page 39: 26714384 Hostel Management System Source Code in JAVA by B Vinod Kumar

f2.add(p4);f2.add(Box.createRigidArea(new Dimension(width,30)));f2.add(p);f2.setVisible(true);f.dispose();b1.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e1){try{

String s1=t1.getText().toUpperCase();String s2=t2.getText();String s3=t3.getText();String s4=t4.getText();if(s1.equals("")||s2.equals("")||s3.equals("

JOptionPane.showMessageDialog(null,"else{

int i1=Integer.parseInt(s3);Class.forName("sun.jdbc.odbc.JdbcOdbConnection con =DriverManager.getConStatement s=con.createStatement();String sq1="update bill set payment=s.execute(sq1);JOptionPane.showMessageDialog(null,"t1.setText("");t2.setText("");t3.setText("");t4.setText("");

}}catch(Exception e2){

System.out.println(e2.toString());}

}});b2.addActionListener(new ActionListener(){public void actionPerforme {

t1.setText("");t2.setText("");t3.setText("");t4.setText("");

}});b3.addActionListener(new ActionListener(){public void actionPerforme {

Accounts ac=new Accounts();f2.dispose();

}});}if(e.getSource()==b){

Accounts ac=new Accounts();f.dispose();

}}

}

class Due implements ActionListener{

JFrame f;JLabel l,l1,l2;

Page 40: 26714384 Hostel Management System Source Code in JAVA by B Vinod Kumar

JTextField t1,t2;JButton b1,b2;JPanel p;Due(){

f=new JFrame("Getting the Mess due of a student");l=new JLabel("Please Enter the roll number and click GO");l.setFont(new Font(Font.SANS_SERIF,Font.PLAIN,25));l1=new JLabel("Enter the roll number here:");l1.setFont(new Font(Font.SANS_SERIF,Font.PLAIN,20));l2=new JLabel("Mess Due is:");l2.setFont(new Font(Font.SANS_SERIF,Font.PLAIN,20));t1=new JTextField(15);t2=new JTextField(10);t2.setEditable(false);b1=new JButton(" Go ");b1.setFont(new Font(Font.SANS_SERIF,Font.PLAIN,18));b2=new JButton("Cancel");b2.setFont(new Font(Font.SANS_SERIF,Font.PLAIN,18));p=new JPanel();p.add(l1);p.add(t1);p.add(Box.createHorizontalStrut(20));p.add(b1);f.setLayout(new FlowLayout());f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);f.setSize(Toolkit.getDefaultToolkit().getScreenSize());Dimension d=Toolkit.getDefaultToolkit().getScreenSize();int width=(int)d.getWidth();f.setSize(d);f.add(l);f.add(Box.createRigidArea(new Dimension(width,35)));f.add(p);f.add(Box.createRigidArea(new Dimension(width,20)));f.add(l2);f.add(t2);f.add(Box.createRigidArea(new Dimension(width,35)));f.add(b2);f.setVisible(true);b1.addActionListener(this);b2.addActionListener(this);

}public void actionPerformed(ActionEvent e){

if(e.getSource()==b1){

String s=t1.getText().toUpperCase();if(s.equals(""))

JOptionPane.showMessageDialog(null,"Please specify the roll else{

try{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");Connection con =DriverManager.getConnection("jdbc:odStatement st=con.createStatement();String sq1="select * from bill where rno='"+s+"'";ResultSet rs=st.executeQuery(sq1);if(rs.next()){

Page 41: 26714384 Hostel Management System Source Code in JAVA by B Vinod Kumar

sq1="select sum(bill)-sum(payment) from billrs=st.executeQuery(sq1);if(rs.next())

t2.setText(rs.getString(1));}else{

JOptionPane.showMessageDialog(null,"Invalid t1.setText("");

}/* sq1="select sum(payment) from bill where rno='"+s+"'

rs=st.executeQuery(sq1);if(rs.next()){

i2=(int)(rs.getLong(1));}else{

JOptionPane.showMessageDialog(null,"Invalid }int due=i1-i2;t2.setText(due+"");*/

}catch(Exception e1){

System.out.println(e1.toString());}

}}if(e.getSource()==b2){

Accounts ac=new Accounts();f.dispose();

}}

}

class Display implements ActionListener{

JFrame f;JLabel l,l1,l2;JTextField t;JComboBox cb;JButton b1,b2;JPanel p1,p2;Display(){

f=new JFrame("Displaying monthly bills");l=new JLabel("Enter the month and select year and click GO");l.setFont(new Font(Font.SANS_SERIF,Font.PLAIN,25));l1=new JLabel("Month (mm/yyyy):");l1.setFont(new Font(Font.SANS_SERIF,Font.PLAIN,20));l2=new JLabel("Year:");l2.setFont(new Font(Font.SANS_SERIF,Font.PLAIN,20));t=new JTextField(10);String year[]={"<Select>","1st B.TECH","2nd B.TECH","3rd B.TECH","4th B.TECHcb=new JComboBox(year);b1=new JButton(" Go ");b1.setFont(new Font(Font.SANS_SERIF,Font.PLAIN,18));b2=new JButton("Cancel");

Page 42: 26714384 Hostel Management System Source Code in JAVA by B Vinod Kumar

b2.setFont(new Font(Font.SANS_SERIF,Font.PLAIN,18));p1=new JPanel();p2=new JPanel();p1.add(l1);p1.add(t);p1.add(Box.createHorizontalStrut(20));p1.add(l2);p1.add(cb);p2.add(b1);p2.add(Box.createHorizontalStrut(20));p2.add(b2);f.setLayout(new FlowLayout());f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);Dimension d=Toolkit.getDefaultToolkit().getScreenSize();int width=(int)d.getWidth();f.setSize(d);f.add(l);f.add(Box.createRigidArea(new Dimension(width,60)));f.add(p1);f.add(Box.createRigidArea(new Dimension(width,30)));f.add(p2);f.setVisible(true);b1.addActionListener(this);b2.addActionListener(this);

}public void actionPerformed(ActionEvent e){

if(e.getSource()==b1){

String s=t.getText();int i=cb.getSelectedIndex();if(s.equals("")||i==0){

JOptionPane.showMessageDialog(null,"Please specify both requ}else{

try{

String[] columnNames = {"Mess Number","Roll Number",Object[][] data=new Object[100][100];Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");Connection con = DriverManager.getConnection("jdbc:oStatement st=con.createStatement(ResultSet.TYPE_SCROString str="select s.messno,s.rno,s.name,b.nodays,b.ResultSet rs=st.executeQuery(str);System.out.println("Query executed successfully");if(!rs.next()){

JOptionPane.showMessageDialog(null,"No One et.setText("");

}else{

rs.previous();int j=0;i=0;while(rs.next()){

data[i][j]=rs.getString(1);j++;

Page 43: 26714384 Hostel Management System Source Code in JAVA by B Vinod Kumar

data[i][j]=rs.getString(2);j++;data[i][j]=rs.getString(3);j++;data[i][j]=rs.getString(4);j++;data[i][j]=rs.getString(5);j++;j=0;i++;

}JButton b=new JButton("Close me to close thiJTable tab= new JTable(data, columnNames);JScrollPane sp=new JScrollPane(tab);final JFrame f1=new JFrame("Displaying Mess f1.setSize(Toolkit.getDefaultToolkit().getScf1.add(b,BorderLayout.NORTH);f1.add(sp,BorderLayout.CENTER);f1.setVisible(true);f1.setDefaultCloseOperation(JFrame.EXIT_ON_Cb.addActionListener(new ActionListener(){pubf.dispose();

}}catch(Exception e1){

System.out.println(e.toString());}

}}if(e.getSource()==b2){

Accounts ac=new Accounts();f.dispose();

}}

}