0% found this document useful (0 votes)
10 views

Advanced Java Lab

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

Advanced Java Lab

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

DEPARTMENT OF COMPUTER APPLICATIONS

SRM UNIVERSITY
MC0617 – ADVANCEDJAVA - LABMANUAL
LAB LESSON PLAN

S.No. List of Exercises Batch – I Batch –II

SWING
1. Login form 31/1/2011 6/1/2011
2. Biodata 3/1/2011 13/1/2011
3. SRM Organization structure using 10/1/2011 20/1/2011
JTree
4. JTabbedPane(Loginform,Registration,.) 17/1/2011& 24/2/2011 27/1/2011&3/2/2011
RMI
5. Banking Application 7/2/2011 10/2/2011
6. Banking Application using JFRAME 14/2/2011 17/2/2011
JDBC
7. Inventory Control 21/2/2011&28/2/2011 24/2/2011
SERVLET
8 Simple programs 17//2011 3/3/2011
SessionTracking 7/3/2011 10/3/2011
9 Employee Information with JDBC 14/3/2011&21/3/2011 17/3/2011&24/3/2011
JSP
10. Simple Programs 28/3/2011 31/3/2011
11 Student Mark List 4/4/2011&11/4/2011 7/4/2011&14/4/2011
BEANS
12 Simple Program 18/4/2011 21/4/2011
13 Custom Bean 18/4/2011 21/4/2011
Model Exam 25/4/2011 28/4/2011

Staff In-charge(s) HOD/MCA

1. Mrs.M.Uma
2. Mr S.Paul Prabakaran
1. LOGIN FORM

Program:-

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import javax.swing.border.*;

class logindemo1 extends JFrame implements ActionListener


{
JButton b1,b2;
JPanel p,p1,p2;
JLabel l1,l2,l3,l4,l5,l6,l7,l8;
final JTextField t1,t2;
Container c;
Border panel,label;

logindemo1()
{
c=getContentPane();
c.setLayout(null);
Font f=new Font("Book Antiqua",Font.BOLD,40);
Font f1=new Font("Times New Roman",Font.BOLD,16);
label=new
EtchedBorder(EtchedBorder.RAISED,Color.black,Color.pink);

Toolkit tk=this.getToolkit();
Dimension wz=tk.getScreenSize();
int w=wz.width-100;
int h=wz.height-50;

ImageIcon im=new ImageIcon("aa.jpg");


ImageIcon ii=new ImageIcon("logo.gif");
ImageIcon ib=new ImageIcon("book6.png");
ImageIcon ic=new ImageIcon("book6.png");

p=new JPanel();
p1=new JPanel();

p1.setOpaque(false);
p.setOpaque(false);
c.add(p);
p.setLayout(null);
c.add(p1);
p1.setLayout(null);

l1=new JLabel();
l1.setFont(f1);
l1.setText("Login ID");
l1.setForeground(Color.black);
t1=new JTextField(15);
l2=new JLabel();
l2.setText("Password");
l2.setFont(f1);
l2.setForeground(Color.black);
t2=new JPasswordField(15);
l3=new JLabel("LOGIN FORM",JLabel.CENTER);
l3.setForeground(Color.black);
l3.setFont(f);

b1=new JButton("LOG IN");


b1.setForeground(Color.black);

b2=new JButton("EXIT");
b2.setForeground(Color.black);

l5=new JLabel(" ",im,JLabel.CENTER);


l6=new JLabel(" ",ii,JLabel.CENTER);
l7=new JLabel(" ",ib,JLabel.CENTER);
l8=new JLabel(" ",ic,JLabel.CENTER);

p1.setBounds(0,0,(w+100),h);
l5.setBounds(0,0,(w+100),h);
l6.setBounds(380,100,500,220);

p.setBounds(400,300,450,280);

l1.setBounds(50,50,100,30);
l2.setBounds(50,100,100,30);
t1.setBounds(200,50,200,30);
t2.setBounds(200,100,200,30);
l3.setBounds(10,30,1250,50);
l7.setBounds(10,100,350,450);
l8.setBounds(930,100,300,450);

b1.setBounds(120,180,100,30);
b2.setBounds(250,180,100,30);

p.add(l1);
p.add(t1);
p.add(l2);
p.add(t2);
p.add(b1);
p.add(b2);

p1.add(l3);

p1.add(l6);
p1.add(l7);
p1.add(l8);
p1.add(l5);

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

c.setBackground(new Color(224,144,175));
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
}

public void actionPerformed(ActionEvent ae)


{
if(ae.getSource()==b1)
{
if(t1.getText().equals("anima")&&t2.getText().equals("mca"))
{
JOptionPane.showMessageDialog(null,"Login
Successful");
}
else
{
JOptionPane.showMessageDialog(null,"Incorrect
Username and Password");
}
}
if(ae.getSource()==b2)
{
dispose();
}
}

public static void main(String arg[])


{
try
{
logindemo1 frame=new logindemo1();
frame.setSize(1280,720);
frame.setVisible(true);
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,e.getMessage());
}
}
}

Output :-
2. REGISTRATION FORM

Program:-

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import javax.swing.border.*;

class reglib1 extends JFrame implements ActionListener,FocusListener


{
JButton b1,b2,b3,b4,b5;
JPanel p,p1,p2,p3,p4,p5,p6,p7,p8,pa,pb,pc;
JTextField t1,t2,t3,t4,t5,t8;
JComboBox c,c1,c2,c3,c4,c5,c6,d1,d2,d3,d4,d5,d6;
JLabel l1,l2,l3,l4,l5,l6,l7,l8,l9,l10,l11,l12,l13,l14,l15,pl;
String s1[]={"MCA","MBA","EC","CS"};
String s2[]={"MCA","MBA","MSC","MTECH","MA"};
String s3[]={"BCA","BBA","BSC","BTECH","BA"};
String s4[]={"--","IT","Medical","Business"};
Container cn;
String s,ss,t;
JTextArea ta;
ResultSet rs;
Border head,label,panel1,panel2,panel3,panel4,panel5;

reglib1()
{

try
{
head=new
EtchedBorder(EtchedBorder.RAISED,Color.black,Color.pink);
panel1=new TitledBorder(new
LineBorder(Color.red),"",TitledBorder.DEFAULT_JUSTIFICATION,TitledBorde
r.CENTER,new Font("Book Antiqua",Font.BOLD,16),Color.black);
panel2=new TitledBorder(new LineBorder(Color.red)," Qualification
",TitledBorder.DEFAULT_JUSTIFICATION,TitledBorder.CENTER,new
Font("Book Antiqua",Font.BOLD,16),Color.black);
panel3=new TitledBorder(new LineBorder(Color.red)," Experience
",TitledBorder.DEFAULT_JUSTIFICATION,TitledBorder.CENTER,new
Font("Book Antiqua",Font.BOLD,16),Color.black);
panel4=new TitledBorder(new LineBorder(Color.red)," Research
",TitledBorder.DEFAULT_JUSTIFICATION,TitledBorder.CENTER,new
Font("Book Antiqua",Font.BOLD,16),Color.black);
panel5=new TitledBorder(new LineBorder(Color.red)," Paper
Presentation
",TitledBorder.DEFAULT_JUSTIFICATION,TitledBorder.CENTER,new
Font("Book Antiqua",Font.BOLD,16),Color.black);

Font f=new Font("Book Antiqua",Font.BOLD,40);

cn=this.getContentPane();
cn.setLayout(null);
cn.setBackground(new Color(110,208,228));

ImageIcon im=new ImageIcon("aa.jpg");

Toolkit tk=this.getToolkit();
Dimension wz=tk.getScreenSize();
int w=wz.width-100;
int h=wz.height-50;

p=new JPanel();
p.setBackground(new Color(110,208,228));

p1=new JPanel();
p2=new JPanel();
p3=new JPanel();
p4=new JPanel();
p5=new JPanel();
p6=new JPanel();
p7=new JPanel();

cn.add(p);
p.setLayout(null);
p1.setLayout(null);
p2.setLayout(null);
p3.setLayout(null);
p4.setLayout(null);
p5.setLayout(null);
p6.setLayout(null);
p7.setLayout(null);

p.setOpaque(false);
p1.setOpaque(false);
p2.setOpaque(false);
p3.setOpaque(false);
p4.setOpaque(false);
p5.setOpaque(false);
p6.setOpaque(false);
p7.setOpaque(false);
p1.setBorder(head);
p2.setBorder(panel1);
p3.setBorder(panel2);
p4.setBorder(panel3);
p5.setBorder(panel4);
p6.setBorder(panel5);
p7.setBorder(head);

l15=new JLabel("REGISTRATION FORM",JLabel.CENTER);


l15.setForeground(Color.black);
l15.setFont(f);

l1=new JLabel("Staff ID");


l1.setFont(new Font("Book Antiqua",Font.BOLD,16));
t1=new JTextField(15);

l2=new JLabel("Staff Name");


l2.setFont(new Font("Book Antiqua",Font.BOLD,16));
t2=new JTextField(15);

l3=new JLabel("Date of Birth");


l3.setFont(new Font("Book Antiqua",Font.BOLD,16));
d1=new JComboBox();

for(int i=1;i<=9;i++)
{
d1.addItem("0"+Integer.toString(i));
}
for(int i=10;i<=31;i++)
{
d1.addItem(Integer.toString(i));
}

d2=new JComboBox();

for(int i=1;i<=9;i++)
{
d2.addItem("0"+Integer.toString(i));
}
for(int i=10;i<=12;i++)
{
d2.addItem(Integer.toString(i));
}

d3=new JComboBox();
for(int i=1980;i<2011;i++)
{
d3.addItem(Integer.toString(i));
}

l4=new JLabel("Date of Joining");


l4.setFont(new Font("Book Antiqua",Font.BOLD,16));

d4=new JComboBox();
for(int i=1;i<=9;i++)
{
d4.addItem("0"+Integer.toString(i));
}
for(int i=10;i<=31;i++)
{
d4.addItem(Integer.toString(i));
}

d5=new JComboBox();
for(int i=1;i<=9;i++)
{
d5.addItem("0"+Integer.toString(i));
}
for(int i=10;i<=12;i++)
{
d5.addItem(Integer.toString(i));
}

d6=new JComboBox();
for(int i=1980;i<2011;i++)
{
d6.addItem(Integer.toString(i));
}

l5=new JLabel("Department");
l5.setFont(new Font("Book Antiqua",Font.BOLD,16));
c1=new JComboBox(s1);

l6=new JLabel("PG ");


l6.setFont(new Font("Book Antiqua",Font.BOLD,16));
c2=new JComboBox(s2);

l7=new JLabel("UG ");


l7.setFont(new Font("Book Antiqua",Font.BOLD,16));
c3=new JComboBox(s3);
l8=new JLabel("Technical Exp.");
l8.setFont(new Font("Book Antiqua",Font.BOLD,16));
c4=new JComboBox();
for(int i=0;i<10;i++)
{
c4.addItem(Integer.toString(i));
}

l9=new JLabel("University/College");
l9.setFont(new Font("Book Antiqua",Font.BOLD,16));
t4=new JTextField(15);

l10=new JLabel("Industry Exp.");


l10.setFont(new Font("Book Antiqua",Font.BOLD,16));
c5=new JComboBox();
for(int i=0;i<10;i++)
{
c5.addItem(Integer.toString(i));
}

l11=new JLabel("Organisation Name");


l11.setFont(new Font("Book Antiqua",Font.BOLD,16));
t5=new JTextField(15);

l12=new JLabel("Title");
l12.setFont(new Font("Book Antiqua",Font.BOLD,16));
ta=new JTextArea("",4,15);
ta.setBorder(BorderFactory.createTitledBorder(""));

l13=new JLabel("Research Field");


l13.setFont(new Font("Book Antiqua",Font.BOLD,16));
c6=new JComboBox(s4);

l14=new JLabel("Place");
l14.setFont(new Font("Book Antiqua",Font.BOLD,16));
t8=new JTextField(15);

b1=new JButton("SUBMIT");
b5=new JButton("CLEAR");
b4=new JButton("EXIT");

pl=new JLabel(" ",im,JLabel.CENTER);

p1.setBounds(200,70,900,540);

p2.setBounds(20,10,860,130);
p3.setBounds(20,150,860,65);
p4.setBounds(20,225,860,105);
p5.setBounds(20,340,860,65);
p6.setBounds(20,415,860,110);
p7.setBounds(200,620,900,60);

p.setBounds(0,0,(w+100),h);
pl.setBounds(0,0,(w+100),h);

l15.setBounds(10,10,1250,40);

l1.setBounds(40,10,150,30);
t1.setBounds(195,10,200,30);

l2.setBounds(460,10,150,30);
t2.setBounds(615,10,200,30);

l3.setBounds(40,50,150,30);
d1.setBounds(195,50,60,30);
d2.setBounds(265,50,60,30);
d3.setBounds(335,50,60,30);

l4.setBounds(460,50,150,30);
d4.setBounds(615,50,60,30);
d5.setBounds(685,50,60,30);
d6.setBounds(755,50,60,30);

l5.setBounds(40,90,150,30);
c1.setBounds(195,90,200,30);

l6.setBounds(40,20,150,30);
c2.setBounds(195,20,200,30);

l7.setBounds(460,20,150,30);
c3.setBounds(615,20,200,30);

l8.setBounds(40,20,150,30);
c4.setBounds(195,20,200,30);

l9.setBounds(460,20,150,30);
t4.setBounds(615,20,200,30);

l10.setBounds(40,60,150,30);
c5.setBounds(195,60,200,30);

l11.setBounds(460,60,150,30);
t5.setBounds(615,60,200,30);
l13.setBounds(40,20,150,30);
c6.setBounds(195,20,200,30);

l14.setBounds(460,20,150,30);
t8.setBounds(615,20,200,30);

l12.setBounds(40,20,150,30);
ta.setBounds(195,20,620,70);

b1.setBounds(250,15,100,30);
b5.setBounds(370,15,100,30);
b4.setBounds(490,15,100,30);

p1.add(p2);
p1.add(p3);
p1.add(p4);
p1.add(p5);
p1.add(p6);

p2.add(l1);
p2.add(t1);
p2.add(l2);
p2.add(t2);
p2.add(l3);
p2.add(d1);
p2.add(d2);
p2.add(d3);
p2.add(l4);
p2.add(d4);
p2.add(d5);
p2.add(d6);
p2.add(l5);
p2.add(c1);

p3.add(l6);
p3.add(c2);
p3.add(l7);
p3.add(c3);

p4.add(l8);
p4.add(c4);
p4.add(l9);
p4.add(t4);
p4.add(l10);
p4.add(c5);
p4.add(l11);
p4.add(t5);
p5.add(l13);
p5.add(c6);
p5.add(l14);
p5.add(t8);

p6.add(l12);
p6.add(ta);

p7.add(b1);
p7.add(b4);
p7.add(b5);

p.add(p1);
p.add(l15);
p.add(p7);

p.add(pl);

t1.addFocusListener(this);
b1.addActionListener(this);
b4.addActionListener(this);
b5.addActionListener(this);
c1.addActionListener(this);
c2.addActionListener(this);
c3.addActionListener(this);
c4.addActionListener(this);
c5.addActionListener(this);
d1.addActionListener(this);
d2.addActionListener(this);
d3.addActionListener(this);
d4.addActionListener(this);
d5.addActionListener(this);
d6.addActionListener(this);
}
catch(Exception e)
{
System.out.println(e);
}

setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CL
OSE);

addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
dispose();
System.exit(0);
}
});

public void actionPerformed(ActionEvent ae)


{
if(ae.getSource()==b1)
{
JOptionPane.showMessageDialog(null,"Record Submitted");
}

if(ae.getSource()==b4)
{
dispose();
}

if(ae.getSource()==b5)
{
t2.setText("");
t4.setText("");
t5.setText("");
ta.setText("");
t8.setText("");
d1.setSelectedItem("01");
d2.setSelectedItem("01");
d3.setSelectedItem("1980");
d4.setSelectedItem("01");
d5.setSelectedItem("01");
d6.setSelectedItem("1980");
c1.setSelectedItem("MCA");
c2.setSelectedItem("MCA");
c3.setSelectedItem("BCA");
c4.setSelectedItem("0");
c5.setSelectedItem("0");
c6.setSelectedItem("IT");

}
public static void main(String arg[])
{
try
{
reglib1 frame=new reglib1();
frame.setSize(1280,720);
frame.setVisible(true);
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,e.getMessage());
}
}

public void focusGained(FocusEvent e)


{
if(e.getSource()==t1)
t1.setText(t);
}

public void focusLost(FocusEvent e)


{
}

Output :-
3. ELECTRICITY BILL

Program:-

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

class elec extends JFrame implements ActionListener


{
JLabel l1,l2,l3,l4,l5,l6,l7,l8;
JTextField t1,t2,t3,t4,t5,t6;
JComboBox c1,c2;
String
s1[]={"Jan","Feb","March","April","May","June","July","Aug","Sep","Oct","
Nov","Dec"};
String s2[]={"Home","Business"};
JPanel p1,p2;
JButton b1,b2,b3;
JTable table;
JScrollPane jsp;
Container c;

elec()
{
p1=new JPanel();
p1.setLayout(new GridLayout(9,2));
p1.setBackground(new Color(255,255,200));

p2=new JPanel();
p2.setLayout(new FlowLayout());
p2.setBackground(new Color(255,255,200));

c=getContentPane();
c.setBackground(new Color(255,255,200));
c.setForeground(new Color(255,255,200));

l1=new JLabel("Customer Name");


l1.setFont(new Font("Bookman Old Style",Font.PLAIN,20));
l1.setForeground(new Color(150,0,0));
l2=new JLabel("Customer Id");
l2.setFont(new Font("Bookman Old Style",Font.PLAIN,20));
l2.setForeground(new Color(150,0,0));

l3=new JLabel("Month");
l3.setFont(new Font("Bookman Old Style",Font.PLAIN,20));
l3.setForeground(new Color(150,0,0));

l4=new JLabel("Purpose");
l4.setFont(new Font("Bookman Old Style",Font.PLAIN,20));
l4.setForeground(new Color(150,0,0));

l5=new JLabel("Previous Reading");


l5.setFont(new Font("Bookman Old Style",Font.PLAIN,20));
l5.setForeground(new Color(150,0,0));

l6=new JLabel("Current Reading");


l6.setFont(new Font("Bookman Old Style",Font.PLAIN,20));
l6.setForeground(new Color(150,0,0));

l7=new JLabel("Unit Consumed");


l7.setFont(new Font("Bookman Old Style",Font.PLAIN,20));
l7.setForeground(new Color(150,0,0));

l8=new JLabel("Total Amount");


l8.setFont(new Font("Bookman Old Style",Font.PLAIN,20));
l8.setForeground(new Color(150,0,0));

t1=new JTextField(15);
t2=new JTextField(15);
t3=new JTextField(15);
t4=new JTextField(15);
t5=new JTextField(15);
t6=new JTextField(15);

t1.setToolTipText("Enter a valid name");


t2.setToolTipText("Enter the numeric value only");
t3.setToolTipText("Enter the reading in numbers");
t4.setToolTipText("Enter the reading in numbers");

c1=new JComboBox(s1);
c1.setBackground(new Color(255,255,255));

c2=new JComboBox(s2);
c2.setBackground(new Color(255,255,255));

b1=new JButton("Submit");
b1.setBackground(new Color(250,220,170));
b1.setFont(new Font("Bookman Old Style",Font.BOLD,16));

b2=new JButton("Reset");
b2.setBackground(new Color(250,220,170));
b2.setFont(new Font("Bookman Old Style",Font.BOLD,16));

b3=new JButton("Display");
b3.setBackground(new Color(250,220,170));
b3.setFont(new Font("Bookman Old Style",Font.BOLD,16));

t5.setEditable(false);
t6.setEditable(false);

b3.setEnabled(false);

c1.addActionListener(this);
c2.addActionListener(this);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);

p1.add(l1);
p1.add(t1);

p1.add(l2);
p1.add(t2);

p1.add(l3);
p1.add(c1);

p1.add(l4);
p1.add(c2);

p1.add(l5);
p1.add(t3);

p1.add(l6);
p1.add(t4);

p1.add(l7);
p1.add(t5);

p1.add(l8);
p1.add(t6);

p1.add(new JLabel(" "));


p1.add(new JLabel(" "));
p2.add(b1);
p2.add(b2);
p2.add(b3);

c.add(p1,BorderLayout.CENTER);
c.add(p2,BorderLayout.SOUTH);
setBounds(200,100,600,200);
setTitle("Electricity Bill");

setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CL
OSE);
setResizable(false);

public void actionPerformed(ActionEvent ae)


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

if(t1.getText().equals("")||t2.getText().equals("")||t3.getText().equals("")||t4.
getText().equals(""))
{
JOptionPane.showMessageDialog(null,"Please
Fill the full detail");

else
{
double p,c,unit,amt;
p=Integer.parseInt(t3.getText());
c=Integer.parseInt(t4.getText());
unit=c-p;

if(p>c)
{

JOptionPane.showMessageDialog(null,"The current Reading must be


greater than or equal to the Previous Reading");
}
else
{
t5.setText(Double.toString(unit));
if(c2.getSelectedItem()=="Home")
{
if(unit>=1 && unit<=50)
amt=unit*.75;

else if(unit>50 && unit<=100)


amt=(50*.75)+((unit-50)*1);

else if(unit>100 && unit<=250)

amt=(50*.75)+(50*1)+((unit-100)*2);

else

amt=(50*.75)+(50*1)+(150*2)+((unit-250)*3);

t6.setText(Double.toString(amt));
}

if(c2.getSelectedItem()=="Business")
{
if(unit>=1 && unit<=50)
amt=unit*2;

else if(unit>50 && unit<=100)


amt=(50*2)+((unit-50)*3);

else if(unit>100 && unit<=250)


amt=(50*2)+(50*3)+((unit-
100)*4);

else

amt=(50*2)+(50*3)+(150*4)+((unit-250)*5);

t6.setText(Double.toString(amt));
}

JOptionPane.showMessageDialog(this,"Submitted Successfully");
b3.setEnabled(true);
b1.setEnabled(false);
}
}

else if(ae.getSource()==b3)
{
String a1,a2,a3,a4,a5,a6,a7,a8;
a1=t1.getText();
a2=t2.getText();

a3=(String)c1.getSelectedItem();
a4=(String)c2.getSelectedItem();

a5=t3.getText();
a6=t4.getText();
a7=t5.getText();
a8=t6.getText();
final String[]
head={"Name","Id","Month","Purpose","P.read","C.read","Unit","Amount"};
final String[][] data={{a1,a2,a3,a4,a5,a6,a7,a8}};
table=new JTable(data,head);
table.getTableHeader().setBackground(new
Color(250,220,170));
table.getTableHeader().setFont(new Font("Book
Antiqua",Font.BOLD,14));
int
v=ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
int
h=ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
jsp=new JScrollPane(table,v,h);
b3.setEnabled(false);
b1.setEnabled(false);

next page=new next();


page.setVisible(true);
page.getContentPane().add(jsp);

else if(ae.getSource()==b2)
{
t1.setText("");
t2.setText("");
t3.setText("");
t4.setText("");
t5.setText("");
t6.setText("");

jsp.setVisible(false);
b1.setEnabled(true);
}

public Insets getInsets()


{
setBackground(new Color(255,255,200));
return new Insets(40,20,20,20);
}

class next extends JFrame


{
next()
{
setTitle("Report");

setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CL
OSE);
setSize(600,200);

}
}

class elecdemoframe
{
public static void main(String arg[])
{
try
{
elec fr=new elec();
fr.setVisible(true);
fr.setSize(600,600);
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,e.getMessage());
}
}
}

Output :-
4. BANKING APPLICATION

Program:-

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class bankdemonew extends JFrame implements ActionListener


{
JLabel l1,l2,l3,l4;
JTextField t1,t2,t3;
JComboBox c1,c2;
String s1[]={"Saving","Current"};
JPanel p,p1,p2,p3;
JButton b[];
JButton b1,b2,b3;
JTable table;
JScrollPane jsp;
Container c;
int balance;

public bankdemonew(String title)


{
super(title);
c=getContentPane();

p=new JPanel(new BorderLayout());

p1=new JPanel();
p1.setLayout(new GridLayout(5,2));

l1=new JLabel("Customer Name");


l2=new JLabel("Account Type");
l3=new JLabel("Account Number");
l4=new JLabel("Amount");

t1=new JTextField(15);
t2=new JTextField(10);
t3=new JTextField(15);

c1=new JComboBox(s1);

p1.add(l1);
p1.add(t1);
p1.add(l2);
p1.add(c1);
p1.add(l3);
p1.add(t2);
p1.add(l4);
p1.add(t3);
p1.add(new JLabel(""));
p1.add(new JLabel(""));

p=new JPanel(new BorderLayout());

p2=new JPanel();
p2.setLayout(new FlowLayout());

b=new JButton[10];

p3=new JPanel();
p3.setLayout(new GridLayout(2,5));

for(int i=0;i<10;i++)
{
b[i]=new JButton(String.valueOf(i));
p3.add(b[i]);
b[i].addActionListener(this);
}

b1=new JButton("Deposit");
b2=new JButton("Withdraw");
b3=new JButton("Balance");

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

p2.add(b1);
p2.add(b2);
p2.add(b3);

c.add(p1,BorderLayout.NORTH);
c.add(p3,BorderLayout.SOUTH);
c.add(p2,BorderLayout.CENTER);

t2.setToolTipText("Enter 10 digits account number");


setVisible(true);
setSize(600,400);
setTitle("Bank");

setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CL
OSE);

JOptionPane.showMessageDialog(null,"You have no deposit in your


account.plz deposit some amount");
t1.requestFocus();
b2.setEnabled(false);

public void actionPerformed(ActionEvent ae)


{
for(int i=0;i<10;i++)
{
if(ae.getSource()==b[i])
{
if(t2.getText().length()!=10)
{
t2.setText(t2.getText()+b[i].getText());
}
else
t3.setText(t3.getText()+b[i].getText());

}
}
if(ae.getSource()==b1)
{
balance=balance+Integer.parseInt(t3.getText());
b2.setEnabled(true);
int i=JOptionPane.showConfirmDialog(null,"Do you
want another transaction in the same account");
if(i==0)
{
t3.setText("");
t3.requestFocus();
}

}
else if(ae.getSource()==b2)
{
if((balance-Integer.parseInt(t3.getText()))<500)
{
JOptionPane.showMessageDialog(null,"You
dont have sufficient amount to withdraw");
t3.setText("");
}
else
{
balance=balance-Integer.parseInt(t3.getText());
}

int i=JOptionPane.showConfirmDialog(null,"Do you


want another transaction in the same account");
if(i==0)
{
t3.setText("");
t3.requestFocus();
}

}
else if(ae.getSource()==b3)
{
String a1,a2,a3,a4;
a1=t1.getText();
a2=(String)c1.getSelectedItem();
a3=t2.getText();
a4=Integer.toString(balance);

final String[] head={"Customer Name","Account


Number","Account Type","Balance"};
final String[][] data={{a1,a2,a3,a4}};
table=new JTable(data,head);
table.getTableHeader().setBackground(new
Color(250,220,170));
table.getTableHeader().setFont(new Font("Book
Antiqua",Font.BOLD,14));

int
v=ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
int
h=ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
jsp=new JScrollPane(table,v,h);

next page=new next();


page.setVisible(true);
page.getContentPane().add(jsp);
}

public static void main(String arg[])


{
bankdemonew fr=new bankdemonew("Bank");
}

class WindowEventHandler extends WindowAdapter


{
public void windowClosing(WindowEvent evt)
{
System.exit(0);
}
}
}

class next extends JFrame


{
next()
{
setTitle("BALANCE");

setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CL
OSE);
setSize(600,200);

}
}
Output :-
6. LIBRARY MANAGEMENT SYSTEM

Program:-

a) HOME PAGE

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import javax.swing.border.*;

class choice1 extends JFrame implements ActionListener


{
JButton b1,b2,b3;
JPanel p,p1,p2;
Container c=null;
Font f;
Border head;
JLabel l1,l2,l3,l4,l5;

choice1()
{
c=this.getContentPane();
c.setLayout(null);

Toolkit tk=this.getToolkit();
Dimension wz=tk.getScreenSize();
int w=wz.width-100;
int h=wz.height-50;

f=new Font("Bookman Old Style",Font.BOLD,40);

p=new JPanel();
//p.setBackground(new Color(110,208,228));
p1=new JPanel();

//p1.setBackground(new Color(224,144,175));

c.add(p);
p.setLayout(null);
c.add(p1);
p1.setLayout(null);

p.setOpaque(false);
ImageIcon im=new ImageIcon("aa.jpg");
ImageIcon ii=new ImageIcon("logo.gif");
ImageIcon ib=new ImageIcon("book1.png");
ImageIcon ic=new ImageIcon("book1.png");

head=new
EtchedBorder(EtchedBorder.RAISED,Color.black,Color.pink);

l1=new JLabel("LIBRARY MANAGEMENT


SYSTEM",JLabel.CENTER);
l1.setFont(f);
l1.setForeground(Color.black);

l2=new JLabel(" ",im,JLabel.CENTER);


l3=new JLabel("",ii,JLabel.CENTER);
l4=new JLabel("",ib,JLabel.CENTER);
l5=new JLabel("",ic,JLabel.CENTER);

b1=new JButton("Admin Login");


b1.setFont(new Font("Bookman Old Style",Font.BOLD,14));

b2=new JButton("User Login");


b2.setFont(new Font("Bookman Old Style",Font.BOLD,14));

b3=new JButton("Registration");
b3.setFont(new Font("Bookman Old Style",Font.BOLD,14));

p.setBounds(440,250,410,400);
p1.setBounds(0,0,(w+100),h);

l1.setBounds(10,50,1250,30);
l3.setBounds(140,50,1000,400);
l4.setBounds(10,250,350,400);
l5.setBounds(930,250,300,400);
l2.setBounds(0,0,(w+100),h);

b1.setBounds(50,200,150,30);
b2.setBounds(230,200,150,30);
b3.setBounds(135,150,150,30);

p.add(b1);
p.add(b2);
p.add(b3);
p1.add(p);
p1.add(l1);
p1.add(l3);
p1.add(l4);
p1.add(l5);
p1.add(l2);

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

//c.setBackground(new Color(224,144,175));

setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CL
OSE);
}

public void actionPerformed(ActionEvent ae)


{
if(ae.getSource()==b1)
{
logindemo1 frame=new logindemo1("admin");
frame.setSize(1280,720);
frame.setVisible(true);
//setVisible(false);
}
if(ae.getSource()==b2)
{
logindemo1 frame=new logindemo1("user");
frame.setSize(1280,720);
frame.setVisible(true);
//setVisible(false);
}
if(ae.getSource()==b3)
{
logindemo1 frame=new logindemo1("create user");
frame.setSize(1280,720);
frame.setVisible(true);
//setVisible(false);
}
}
}

class choice
{
public static void main(String arg[])
{
try
{
choice1 frame=new choice1();
frame.setSize(1280,720);
frame.setVisible(true);
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,e.getMessage());
}
}
}

b) LOGIN FORM

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import javax.swing.border.*;

class logindemo1 extends JFrame implements ActionListener


{
JButton b1,b2;
JPanel p,p1,p2;
JLabel l1,l2,l3,l4,l5,l6,l7,l8;
final JTextField t1,t2;
ResultSet rs;
Container c;
Border panel,label;
String tit,ss;

logindemo1(String title)
{
super(title);
tit=title;
c=getContentPane();
c.setLayout(null);
Font f=new Font("Book Antiqua",Font.BOLD,40);
Font f1=new Font("Times New Roman",Font.BOLD,16);
label=new
EtchedBorder(EtchedBorder.RAISED,Color.black,Color.pink);

Toolkit tk=this.getToolkit();
Dimension wz=tk.getScreenSize();
int w=wz.width-100;
int h=wz.height-50;
ImageIcon im=new ImageIcon("aa.jpg");
ImageIcon ii=new ImageIcon("logo.gif");
ImageIcon ib=new ImageIcon("book6.png");
ImageIcon ic=new ImageIcon("book6.png");

p=new JPanel();
//p.setBackground(new Color(110,208,228));
p1=new JPanel();
//p1.setBackground(new Color(224,144,175));

p1.setOpaque(false);
p.setOpaque(false);

c.add(p);
p.setLayout(null);
c.add(p1);
p1.setLayout(null);

l1=new JLabel();
l1.setFont(f1);
l1.setText("Login ID");
l1.setForeground(Color.black);
t1=new JTextField(15);
l2=new JLabel();
l2.setText("Password");
l2.setFont(f1);
l2.setForeground(Color.black);
t2=new JPasswordField(15);
l3=new JLabel("ADMINISTRATOR LOGIN",JLabel.CENTER);
l3.setForeground(Color.black);
l3.setFont(f);

l4=new JLabel("USER LOGIN",JLabel.CENTER);


l4.setForeground(Color.black);
l4.setFont(f);

b1=new JButton("LOG IN");


b1.setForeground(Color.black);
//b1.setBackground(new Color(254,214,249));
//b1.setFont(new Font("Book Antiqua",Font.BOLD,16));

b2=new JButton("EXIT");
b2.setForeground(Color.black);
//b2.setBackground(new Color(254,214,249));
//b2.setFont(new Font("Book Antiqua",Font.BOLD,16));

l5=new JLabel(" ",im,JLabel.CENTER);


l6=new JLabel(" ",ii,JLabel.CENTER);
l7=new JLabel(" ",ib,JLabel.CENTER);
l8=new JLabel(" ",ic,JLabel.CENTER);

p1.setBounds(0,0,(w+100),h);
l5.setBounds(0,0,(w+100),h);
l6.setBounds(380,100,500,220);

p.setBounds(400,300,450,280);

l1.setBounds(50,50,100,30);
l2.setBounds(50,100,100,30);
t1.setBounds(200,50,200,30);
t2.setBounds(200,100,200,30);
l3.setBounds(10,30,1250,50);
l4.setBounds(10,30,1250,50);
l7.setBounds(10,100,350,450);
l8.setBounds(930,100,300,450);

b1.setBounds(120,180,100,30);
b2.setBounds(250,180,100,30);
//p.setBorder(label);

p.add(l1);
p.add(t1);
p.add(l2);
p.add(t2);
p.add(b1);
p.add(b2);

if(tit.equals("admin")||tit.equals("create_admin"))
{
p1.add(l3);

}
else
{
p1.add(l4);
}

p1.add(l6);
p1.add(l7);
p1.add(l8);
p1.add(l5);

b1.addActionListener(this);
b2.addActionListener(this);
c.setBackground(new Color(224,144,175));

setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CL
OSE);
}

public void actionPerformed(ActionEvent ae)


{
String v1=t1.getText();
String v2=t2.getText();
String ss="";
int flag=0;
boolean more;
if(ae.getSource()==b1)
{
if(t1.getText().equals("")||t2.getText().equals(""))
{
JOptionPane.showMessageDialog(null,"Please Enter the Login
ID and Password");
}
else
{
if(tit.equals("admin"))
{
ss="select * from admin_login";
try
{
conestablish1 co=new conestablish1();
rs=co.selectconDb(ss);
}
catch(Exception a)
{

JOptionPane.showMessageDialog(null,"select_con_error.........-
>"+a.toString());
}
try
{
more=rs.next();
while(more)
{

if(rs.getString("login_id").equalsIgnoreCase(v1)&&
rs.getString("pass").equalsIgnoreCase(v2))
{
JOptionPane.showMessageDialog(this,"Login Successfull");
flag=1;
}
more=rs.next();
}
if(flag==1)
{
userform r=new
userform("admin");
r.setVisible(true);
r.setSize(1280,720);
setVisible(false);
}
else
{

JOptionPane.showMessageDialog(this,"Wrong Login Id and Password");


t1.setText("");
t2.setText("");
}
}
catch(Exception e)
{
}

}
else if(tit.equals("user"))
{
ss="select * from user_login";
try
{
conestablish1 co=new conestablish1();
rs=co.selectconDb(ss);
}
catch(Exception a)
{

JOptionPane.showMessageDialog(null,"select_con_error.........-
>"+a.toString());
}
try
{
more=rs.next();
while(more)
{

if(rs.getString("login_id").equalsIgnoreCase(v1)&&
rs.getString("pass").equalsIgnoreCase(v2))
{

JOptionPane.showMessageDialog(this,"Login Successfull");
flag=1;
}
more=rs.next();
}
if(flag==1)
{
userform r=new
userform("user");
r.setVisible(true);
r.setSize(1280,720);
setVisible(false);
}
else
{

JOptionPane.showMessageDialog(this,"Wrong Login Id and Password");


t1.setText("");
t2.setText("");
}

}
catch(Exception e)
{
}

}
else if(tit.equals("create user"))
{
ss="select * from user_login";
try
{
conestablish1 co=new conestablish1();
rs=co.selectconDb(ss);
}
catch(Exception a)
{

JOptionPane.showMessageDialog(null,"select_con_error.........-
>"+a.toString());
}
try
{
more=rs.next();
while(more)
{
if(rs.getString("login_id").equalsIgnoreCase(v1))
{

JOptionPane.showMessageDialog(this,"Login ID already exist");


flag=1;
}
more=rs.next();
}

}
catch(Exception e)
{
}
if(flag==1)
{
t1.setText("");
t2.setText("");
}
else
{
String s="INSERT INTO user_login
VALUES('"+v1+"'";
s+=",'"+v2+"'";
s+=")";
try
{
conestablish1 ins=new
conestablish1();
ins.insertIntoDb(s);
}
catch(Exception a)
{

JOptionPane.showMessageDialog(null,"insert_con_error.........-
>"+a.toString());
}
reglib1 r=new reglib1(v1,"");
r.setVisible(true);
r.setSize(1280,720);
setVisible(false);
}
}
else if(tit.equals("create_admin"))
{
ss="select * from admin_login";
try
{
conestablish1 co=new conestablish1();
rs=co.selectconDb(ss);
}
catch(Exception a)
{

JOptionPane.showMessageDialog(null,"select_con_error.........-
>"+a.toString());
}
try
{
more=rs.next();
while(more)
{

if(rs.getString("login_id").equalsIgnoreCase(v1))
{

JOptionPane.showMessageDialog(this,"Login ID already exist");


flag=1;
}
more=rs.next();
}

}
catch(Exception e)
{
}
if(flag==1)
{
t1.setText("");
t2.setText("");
}
else
{
String s="INSERT INTO admin_login
VALUES('"+v1+"'";
s+=",'"+v2+"'";
s+=")";
try
{
conestablish1 ins=new
conestablish1();
ins.insertIntoDb(s);
}
catch(Exception a)
{

JOptionPane.showMessageDialog(null,"insert_con_error.........-
>"+a.toString());
}

JOptionPane.showMessageDialog(this,"Administrator Login created");


setVisible(false);
}
}
}
}
if(ae.getSource()==b2)
{
dispose();
}
}

public static void main(String arg[])


{
try
{
logindemo1 frame=new logindemo1("");
frame.setSize(1280,720);
frame.setVisible(true);
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,e.getMessage());
}
}
}

c) REGISTRATION FORM

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import javax.swing.border.*;

class reglib1 extends JFrame implements ActionListener,FocusListener


{
JButton b1,b2,b3,b4,b5;
JPanel p,p1,p2,p3,p4,p5,p6,p7,p8,pa,pb,pc;
JTextField t1,t2,t3,t4,t5,t8;
JComboBox c,c1,c2,c3,c4,c5,c6,d1,d2,d3,d4,d5,d6;
JLabel l1,l2,l3,l4,l5,l6,l7,l8,l9,l10,l11,l12,l13,l14,l15,pl;
String s1[]={"MCA","MBA","EC","CS"};
String s2[]={"MCA","MBA","MSC","MTECH","MA"};
String s3[]={"BCA","BBA","BSC","BTECH","BA"};
String s4[]={"--","IT","Medical","Business"};
Container cn;
String s,ss,t;
JTextArea ta;
ResultSet rs;
Border head,label,panel1,panel2,panel3,panel4,panel5;

reglib1(String title,String title1)


{

try
{
t=title;
s=title1;

head=new
EtchedBorder(EtchedBorder.RAISED,Color.black,Color.pink);
panel1=new TitledBorder(new
LineBorder(Color.red),"",TitledBorder.DEFAULT_JUSTIFICATION,TitledBorde
r.CENTER,new Font("Book Antiqua",Font.BOLD,16),Color.black);
panel2=new TitledBorder(new LineBorder(Color.red)," Qualification
",TitledBorder.DEFAULT_JUSTIFICATION,TitledBorder.CENTER,new
Font("Book Antiqua",Font.BOLD,16),Color.black);
panel3=new TitledBorder(new LineBorder(Color.red)," Experience
",TitledBorder.DEFAULT_JUSTIFICATION,TitledBorder.CENTER,new
Font("Book Antiqua",Font.BOLD,16),Color.black);
panel4=new TitledBorder(new LineBorder(Color.red)," Research
",TitledBorder.DEFAULT_JUSTIFICATION,TitledBorder.CENTER,new
Font("Book Antiqua",Font.BOLD,16),Color.black);
panel5=new TitledBorder(new LineBorder(Color.red)," Paper
Presentation
",TitledBorder.DEFAULT_JUSTIFICATION,TitledBorder.CENTER,new
Font("Book Antiqua",Font.BOLD,16),Color.black);

Font f=new Font("Book Antiqua",Font.BOLD,40);

cn=this.getContentPane();
cn.setLayout(null);
cn.setBackground(new Color(110,208,228));

ImageIcon im=new ImageIcon("aa.jpg");

Toolkit tk=this.getToolkit();
Dimension wz=tk.getScreenSize();
int w=wz.width-100;
int h=wz.height-50;

p=new JPanel();
p.setBackground(new Color(110,208,228));
p1=new JPanel();
//p1.setBackground(new Color(110,208,228));
p2=new JPanel();
//p2.setBackground(new Color(110,208,228));
p3=new JPanel();
//p3.setBackground(new Color(110,208,228));
p4=new JPanel();
//p4.setBackground(new Color(110,208,228));
p5=new JPanel();
//p5.setBackground(new Color(110,208,228));
p6=new JPanel();
//p6.setBackground(new Color(110,208,228));
p7=new JPanel();

cn.add(p);
p.setLayout(null);
p1.setLayout(null);
p2.setLayout(null);
p3.setLayout(null);
p4.setLayout(null);
p5.setLayout(null);
p6.setLayout(null);
p7.setLayout(null);

p.setOpaque(false);
p1.setOpaque(false);
p2.setOpaque(false);
p3.setOpaque(false);
p4.setOpaque(false);
p5.setOpaque(false);
p6.setOpaque(false);
p7.setOpaque(false);

p1.setBorder(head);
p2.setBorder(panel1);
p3.setBorder(panel2);
p4.setBorder(panel3);
p5.setBorder(panel4);
p6.setBorder(panel5);
p7.setBorder(head);

l15=new JLabel("REGISTRATION FORM",JLabel.CENTER);


l15.setForeground(Color.black);
l15.setFont(f);
l1=new JLabel("Staff ID");
l1.setFont(new Font("Book Antiqua",Font.BOLD,16));
t1=new JTextField(15);

/*c=new JComboBox();

for(int i=1;i<10;i++)
{
c.addItem("mca0"+Integer.toString(i));
}*/

//t1.setEnabled(false);

l2=new JLabel("Staff Name");


l2.setFont(new Font("Book Antiqua",Font.BOLD,16));
t2=new JTextField(15);

l3=new JLabel("Date of Birth");


l3.setFont(new Font("Book Antiqua",Font.BOLD,16));
d1=new JComboBox();

for(int i=1;i<=9;i++)
{
d1.addItem("0"+Integer.toString(i));
}
for(int i=10;i<=31;i++)
{
d1.addItem(Integer.toString(i));
}

d2=new JComboBox();

for(int i=1;i<=9;i++)
{
d2.addItem("0"+Integer.toString(i));
}
for(int i=10;i<=12;i++)
{
d2.addItem(Integer.toString(i));
}

d3=new JComboBox();
for(int i=1980;i<2011;i++)
{
d3.addItem(Integer.toString(i));
}

l4=new JLabel("Date of Joining");


l4.setFont(new Font("Book Antiqua",Font.BOLD,16));
d4=new JComboBox();
for(int i=1;i<=9;i++)
{
d4.addItem("0"+Integer.toString(i));
}
for(int i=10;i<=31;i++)
{
d4.addItem(Integer.toString(i));
}

d5=new JComboBox();
for(int i=1;i<=9;i++)
{
d5.addItem("0"+Integer.toString(i));
}
for(int i=10;i<=12;i++)
{
d5.addItem(Integer.toString(i));
}

d6=new JComboBox();
for(int i=1980;i<2011;i++)
{
d6.addItem(Integer.toString(i));
}

l5=new JLabel("Department");
l5.setFont(new Font("Book Antiqua",Font.BOLD,16));
c1=new JComboBox(s1);

l6=new JLabel("PG ");


l6.setFont(new Font("Book Antiqua",Font.BOLD,16));
c2=new JComboBox(s2);

l7=new JLabel("UG ");


l7.setFont(new Font("Book Antiqua",Font.BOLD,16));
c3=new JComboBox(s3);

l8=new JLabel("Technical Exp.");


l8.setFont(new Font("Book Antiqua",Font.BOLD,16));
c4=new JComboBox();
for(int i=0;i<10;i++)
{
c4.addItem(Integer.toString(i));
}
//t3=new JTextField(15);

l9=new JLabel("University/College");
l9.setFont(new Font("Book Antiqua",Font.BOLD,16));
t4=new JTextField(15);

l10=new JLabel("Industry Exp.");


l10.setFont(new Font("Book Antiqua",Font.BOLD,16));
c5=new JComboBox();
for(int i=0;i<10;i++)
{
c5.addItem(Integer.toString(i));
}

l11=new JLabel("Organisation Name");


l11.setFont(new Font("Book Antiqua",Font.BOLD,16));
t5=new JTextField(15);

l12=new JLabel("Title");
l12.setFont(new Font("Book Antiqua",Font.BOLD,16));
ta=new JTextArea("",4,15);
ta.setBorder(BorderFactory.createTitledBorder(""));

l13=new JLabel("Research Field");


l13.setFont(new Font("Book Antiqua",Font.BOLD,16));
c6=new JComboBox(s4);

l14=new JLabel("Place");
l14.setFont(new Font("Book Antiqua",Font.BOLD,16));
t8=new JTextField(15);

b1=new JButton("ADD");
b2=new JButton("MODIFY");
b5=new JButton("CLEAR");
b4=new JButton("EXIT");

pl=new JLabel(" ",im,JLabel.CENTER);

p1.setBounds(200,70,900,540);
//p.setBounds(10,10,1250,45);

p2.setBounds(20,10,860,130);
p3.setBounds(20,150,860,65);
p4.setBounds(20,225,860,105);
p5.setBounds(20,340,860,65);
p6.setBounds(20,415,860,110);
p7.setBounds(200,620,900,60);

p.setBounds(0,0,(w+100),h);
pl.setBounds(0,0,(w+100),h);

l15.setBounds(10,10,1250,40);

l1.setBounds(40,10,150,30);
t1.setBounds(195,10,200,30);

l2.setBounds(460,10,150,30);
t2.setBounds(615,10,200,30);

l3.setBounds(40,50,150,30);
d1.setBounds(195,50,60,30);
d2.setBounds(265,50,60,30);
d3.setBounds(335,50,60,30);

l4.setBounds(460,50,150,30);
d4.setBounds(615,50,60,30);
d5.setBounds(685,50,60,30);
d6.setBounds(755,50,60,30);

l5.setBounds(40,90,150,30);
c1.setBounds(195,90,200,30);

l6.setBounds(40,20,150,30);
c2.setBounds(195,20,200,30);

l7.setBounds(460,20,150,30);
c3.setBounds(615,20,200,30);

l8.setBounds(40,20,150,30);
c4.setBounds(195,20,200,30);

l9.setBounds(460,20,150,30);
t4.setBounds(615,20,200,30);

l10.setBounds(40,60,150,30);
c5.setBounds(195,60,200,30);

l11.setBounds(460,60,150,30);
t5.setBounds(615,60,200,30);

l13.setBounds(40,20,150,30);
c6.setBounds(195,20,200,30);

l14.setBounds(460,20,150,30);
t8.setBounds(615,20,200,30);

l12.setBounds(40,20,150,30);
ta.setBounds(195,20,620,70);

b1.setBounds(250,15,100,30);
b2.setBounds(370,15,100,30);
b5.setBounds(490,15,100,30);
b4.setBounds(610,15,100,30);

p1.add(p2);
p1.add(p3);
p1.add(p4);
p1.add(p5);
p1.add(p6);
//p1.add(p7);

p2.add(l1);
p2.add(t1);
p2.add(l2);
p2.add(t2);
p2.add(l3);
p2.add(d1);
p2.add(d2);
p2.add(d3);
p2.add(l4);
p2.add(d4);
p2.add(d5);
p2.add(d6);
p2.add(l5);
p2.add(c1);

p3.add(l6);
p3.add(c2);
p3.add(l7);
p3.add(c3);

p4.add(l8);
p4.add(c4);
p4.add(l9);
p4.add(t4);
p4.add(l10);
p4.add(c5);
p4.add(l11);
p4.add(t5);

p5.add(l13);
p5.add(c6);
p5.add(l14);
p5.add(t8);

p6.add(l12);
p6.add(ta);

p7.add(b1);
p7.add(b2);
p7.add(b4);
p7.add(b5);

p.add(p1);
p.add(l15);
p.add(p7);

p.add(pl);

t1.addFocusListener(this);
b1.addActionListener(this);
b2.addActionListener(this);
b4.addActionListener(this);
b5.addActionListener(this);
c1.addActionListener(this);
c2.addActionListener(this);
c3.addActionListener(this);
c4.addActionListener(this);
c5.addActionListener(this);
d1.addActionListener(this);
d2.addActionListener(this);
d3.addActionListener(this);
d4.addActionListener(this);
d5.addActionListener(this);
d6.addActionListener(this);
}
catch(Exception e)
{
System.out.println(e);
}

setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CL
OSE);

addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
dispose();
System.exit(0);
}
});

if(s.equals("up"))
{
b1.setEnabled(false);

ss="Select * from register";


try
{
conestablish1 ci=new conestablish1();
rs=ci.selectconDb(ss);
}
catch(Exception e2)
{

JOptionPane.showMessageDialog(null,e2.toString());
}
try
{
while(rs.next())
{
if(t.equals(rs.getString(1)))
{
t2.setText(rs.getString(2));

String db=rs.getString(3);
String dbd=db.substring(0,4);

String dbm=db.substring(5,7);

String dby=db.substring(8,10);

d1.setSelectedItem(dby);
d2.setSelectedItem(dbm);
d3.setSelectedItem(dbd);

String dj=rs.getString(4);
String djd=dj.substring(0,4);

String djm=dj.substring(5,7);

String djy=dj.substring(8,10);

d4.setSelectedItem(djy);
d5.setSelectedItem(djm);
d6.setSelectedItem(djd);
c1.setSelectedItem(rs.getString(5));

c2.setSelectedItem(rs.getString(6));

c3.setSelectedItem(rs.getString(7));

c4.setSelectedItem(rs.getString(8));
t4.setText(rs.getString(9));

c5.setSelectedItem(rs.getString(10));
t5.setText(rs.getString(11));

ta.setText(rs.getString(12));

c5.setSelectedItem(rs.getString(13));
t8.setText(rs.getString(14));
}
}

}
catch(Exception e2)
{

JOptionPane.showMessageDialog(null,"rs_next.........->"+e2.toString());
}

}
else
{
b2.setEnabled(false);
}
}

public void actionPerformed(ActionEvent ae)


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

String s="INSERT INTO register VALUES('"+t+"'";


s+=",'"+t2.getText()+"'";
s+=",'"+d2.getSelectedItem()+"-"+d1.getSelectedItem()+"-
"+d3.getSelectedItem()+"'";
s+=",'"+d5.getSelectedItem()+"-"+d4.getSelectedItem()+"-
"+d6.getSelectedItem()+"'";
s+=",'"+c1.getSelectedItem()+"'";
s+=",'"+c2.getSelectedItem()+"'";
s+=",'"+c3.getSelectedItem()+"'";
s+=",'"+c4.getSelectedItem()+"'";
s+=",'"+t4.getText()+"'";
s+=",'"+c5.getSelectedItem()+"'";
s+=",'"+t5.getText()+"'";
s+=",'"+ta.getText()+"'";
s+=",'"+c6.getSelectedItem()+"'";
s+=",'"+t8.getText()+"'";
s+=")";

try
{
conestablish1 ins=new conestablish1();
ins.insertIntoDb(s);
JOptionPane.showMessageDialog(null,"One Record
Added");
}
catch(Exception a)
{
JOptionPane.showMessageDialog(null,a.toString());
}
userform r=new userform("user");
r.setSize(1280,720);
r.setVisible(true);
setVisible(false);
}

if(ae.getSource()==b2)
{
String ss1="";
try
{
ss1+="UPDATE Register set ";
ss1+="staff_name='"+t2.getText()+"', ";
ss1+="dob='"+d1.getSelectedItem()+"-
"+d2.getSelectedItem()+"-"+d3.getSelectedItem()+"', ";
ss1+="doj='"+d4.getSelectedItem()+"-
"+d5.getSelectedItem()+"-"+d6.getSelectedItem()+"', ";
ss1+="dept='"+c1.getSelectedItem()+"', ";
ss1+="qual_pg='"+c2.getSelectedItem()+"', ";
ss1+="qual_ug='"+c3.getSelectedItem()+"', ";
ss1+="exp_tc='"+c4.getSelectedItem()+"',";
ss1+="univ='"+t4.getText()+"', ";
ss1+="exp_ind='"+c5.getSelectedItem()+"', ";
ss1+="org='"+t5.getText()+"', ";
ss1+="title='"+ta.getText()+"', ";
ss1+="res='"+c6.getSelectedItem()+"', ";
ss1+="place='"+t8.getText()+"' ";
ss1+=" WHERE staff_id='"+t1.getText()+"' ";

}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,"in sql.........-
>"+e.toString());
}

try
{
conestablish1 i=new conestablish1();
i.updateDb(ss1);
JOptionPane.showMessageDialog(null,"One Record
Updated");
setVisible(false);
}
catch(Exception e1)
{
JOptionPane.showMessageDialog(null,e1.toString());
}
}

/*if(ae.getSource()==b3)
{
try
{
String delete="DELETE FROM Register WHERE
staff_id='"+t1.getText()+"'";

int i=JOptionPane.showConfirmDialog(null,"Are you


sure you want to delete this record?");
if(i==0)
{
conestablish1 ins=new conestablish1();
ins.deleteconDb(delete);

}
String del="DELETE FROM user_login WHERE
login_id='"+t1.getText()+"'";
conestablish1 ins=new conestablish1();
ins.deleteconDb(del);
JOptionPane.showMessageDialog(null,"One Record
Deleted");
System.exit(1);
}
catch(Exception e1)
{
JOptionPane.showMessageDialog(null,e1.toString());
}
}*/

if(ae.getSource()==b4)
{
dispose();
}

if(ae.getSource()==b5)
{
t2.setText("");
t4.setText("");
t5.setText("");
ta.setText("");
t8.setText("");
d1.setSelectedItem("01");
d2.setSelectedItem("01");
d3.setSelectedItem("1980");
d4.setSelectedItem("01");
d5.setSelectedItem("01");
d6.setSelectedItem("1980");
c1.setSelectedItem("MCA");
c2.setSelectedItem("MCA");
c3.setSelectedItem("BCA");
c4.setSelectedItem("0");
c5.setSelectedItem("0");
c6.setSelectedItem("IT");

}
public static void main(String arg[])
{
try
{
reglib1 frame=new reglib1("","");
frame.setSize(1280,720);
frame.setVisible(true);
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,e.getMessage());
}
}
public void focusGained(FocusEvent e)
{
if(e.getSource()==t1)
t1.setText(t);
}

public void focusLost(FocusEvent e)


{
}

d) MAIN FORM

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.sql.*;
import javax.swing.border.*;
import java.util.Calendar;
import java.text.*;

class userform extends JFrame implements ActionListener,FocusListener


{
Container c=null;
JTabbedPane jtp;
JPanel p1,p2,p3,p4,p5,p6,p7,p8,plog;
JLabel logo,logo1;
JButton sxb6;
Font f,f1;
Border label;

//........stock
JLabel sl1,sl2,sl3,sl4,sl5,sl6,sl7,sl8,sl9,sh,sh1;
JTextField st1,st2,st3,st4,st5,st6,st7,st8;
JButton sb1,sb2,sb3,sb4,sb5,sb6;
JPanel sp1,sp2,sp3;
JComboBox c1,c2;
String []s={"Compartment","Department"};

//........issue
JLabel ish,li1,li2,li3,li4;
JTextField ti1,ti2,ti3,ti4;
JButton bi1,bi2;
JPanel pi1,pi2,pi3;

//........renewal
JLabel resh,lre1,lre2,lre3,lre4,lre5;
JTextField tre1,tre2,tre3,tre4,tre5;
JButton bre1,bre2;
JPanel pre1,pre2,pre3;
JComboBox cre1;

//........return
JLabel rtsh,lrt1,lrt2,lrt3,lrt4,lrt5;
JTextField trt1,trt2,trt3,trt4,trt5;
JButton brt1,brt2;
JPanel prt1,prt2,prt3;
JComboBox crt1;

//........staff
JLabel shss,lss1;
JTextField tss1;
JButton bss1,bss2;
JPanel pss1,pss2,pss3;

//.........search
JLabel shs,ls1;
JTextField ts1,ts2,ts3,ts4,ts5;
JButton bs1;
JPanel ps1,ps2,ps3;
JComboBox c3;
JRadioButton r1,r2,r3;
ButtonGroup bg;

//.........admin
JPanel pa1,pa2,pa3;
JLabel la1,sha,la2;
JTextField ta1;
JButton ba1;
JRadioButton ra1,ra2,ra3;
ButtonGroup bag;

Statement smt;
ResultSet rs,rt;
String sql2,t,date,date2,date3,strdate,strdate1,tit;

java.sql.Date d1,d2,dat,dat1,dat2;
Calendar cal;
long tim;

public userform(String title)


{
tit=title;
//...........................Date Calculation
DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
cal=Calendar.getInstance();
dat=new java.sql.Date(cal.getTime().getTime());
date=dateFormat.format(dat);

tim=System.currentTimeMillis();
cal.add(Calendar.MONTH,3);
dat1=new java.sql.Date(cal.getTime().getTime());
date3=dateFormat.format(dat1);

cal.add(Calendar.MONTH,3);
dat2=new java.sql.Date(cal.getTime().getTime());
date2=dateFormat.format(dat2);

//.......................................................

Toolkit tk=this.getToolkit();
Dimension wz=tk.getScreenSize();
int w=wz.width-100;
int h=wz.height-50;

f=new Font("Book Antiqua",Font.BOLD,30);


f1=new Font("Times New Roman",Font.BOLD,14);

label=new
EtchedBorder(EtchedBorder.RAISED,Color.black,Color.pink);

c=this.getContentPane();
c.setLayout(null);
//c.setBackground(new Color(110,208,228));

ImageIcon pimg=new ImageIcon("aa.jpg");


ImageIcon pimg1=new ImageIcon("book3.jpg");
ImageIcon pimg2=new ImageIcon("book5.jpg");

ImageIcon im=new ImageIcon("logo.gif");


logo=new JLabel(" ",im,JLabel.CENTER);

ImageIcon im1=new ImageIcon("logo.gif");


logo1=new JLabel(" ",im1,JLabel.CENTER);

jtp=new JTabbedPane();

//jtp.setBackground(new Color(180, 224, 247));

p1=new JPanel();
p2=new JPanel();
p3=new JPanel();
p4=new JPanel();
p5=new JPanel();
p6=new JPanel();
p7=new JPanel();
p8=new JPanel();

p1.setOpaque(false);
p2.setOpaque(false);
p3.setOpaque(false);
p4.setOpaque(false);
p5.setOpaque(false);
p6.setOpaque(false);
p7.setOpaque(false);
p8.setOpaque(false);
jtp.setOpaque(false);

//p1.setBackground(new Color(110,208,228));
//p2.setBackground(new Color(110,208,228));
//p3.setBackground(new Color(110,208,228));
//p4.setBackground(new Color(110,208,228));
//p5.setBackground(new Color(110,208,228));
//p6.setBackground(new Color(110,208,228));
//p7.setBackground(new Color(110,208,228));
//p8.setBackground(new Color(110,208,228));
//plog.setBackground(new Color(50,208,228));

if(tit.equals("user"))
{
jtp.addTab("Staff",p5);
jtp.addTab("Search",p6);
}
else
{
jtp.addTab("Stok Maintenance",p1);
jtp.addTab("Issue of Book",p2);
jtp.addTab("Renewal Book",p3);
jtp.addTab("Return Book",p4);
jtp.addTab("Staff",p5);
jtp.addTab("Admin",p8);
jtp.addTab("Search",p6);
}
c.add(jtp);
c.add(p7);
jtp.setBounds(0,0,(w+100),(h));
jtp.setBorder(label);
p1.setLayout(null);
p2.setLayout(null);
p3.setLayout(null);
p4.setLayout(null);
p5.setLayout(null);
p6.setLayout(null);
p7.setLayout(null);
p8.setLayout(null);

label=new
EtchedBorder(EtchedBorder.RAISED,Color.black,Color.pink);

//.................Exit Panel

p7.setBounds(10,50,1280,20);
sxb6=new JButton("EXIT");
sxb6.setBounds(1000,0,80,20);
p7.add(sxb6);
p7.setBorder(label);

//.........................Stock Maintenance

JLabel sl=new JLabel("",pimg,JLabel.CENTER);


JLabel s1=new JLabel("",pimg1,JLabel.CENTER);
JLabel s2=new JLabel("",pimg2,JLabel.CENTER);

sp1=new JPanel();
sp2=new JPanel();
sp3=new JPanel();

sp1.setLayout(null);
sp2.setLayout(null);
sp3.setLayout(null);

//sp1.setBackground(new Color(110,208,228));
//sp2.setBackground(new Color(110,208,228));
//sp3.setBackground(new Color(110,208,228));

sp1.setOpaque(false);
sp2.setOpaque(false);
sp3.setOpaque(false);

p1.setBounds(0,0,(w+100),(h));
sl.setBounds(0,0,(w+100),(h));
s1.setBounds(20,120,300,400);
s2.setBounds(950,100,300,440);

sp1.setBounds(350,50,600,50);
sp1.setBorder(label);

sp2.setBounds(350,110,600,440);
sp2.setBorder(label);

sp3.setBounds(350,560,600,50);
sp3.setBorder(label);

sh=new JLabel("STOCK MAINTENANCE",JLabel.CENTER);


sh.setFont(f);
sh.setForeground(Color.black);

sh1=new JLabel("Choose the Book Code");


c2=new JComboBox();

sl1=new JLabel("Acc No.");


sl2=new JLabel("Date of Arrival");
sl3=new JLabel("Book Code ");
sl4=new JLabel("Book Name");
sl5=new JLabel("Author");
sl6=new JLabel("Price");
sl7=new JLabel("Rack Number");
sl8=new JLabel("Book Type");

sh1.setFont(f1);
sl1.setFont(f1);
sl2.setFont(f1);
sl3.setFont(f1);
sl4.setFont(f1);
sl5.setFont(f1);
sl6.setFont(f1);
sl7.setFont(f1);
sl8.setFont(f1);

sh1.setForeground(Color.black);
sl1.setForeground(Color.black);
sl2.setForeground(Color.black);
sl3.setForeground(Color.black);
sl4.setForeground(Color.black);
sl5.setForeground(Color.black);
sl6.setForeground(Color.black);
sl7.setForeground(Color.black);
sl8.setForeground(Color.black);
st1=new JTextField(10);
st2=new JTextField(10);
st3=new JTextField(10);
st4=new JTextField(10);
st5=new JTextField(10);
st6=new JTextField(10);
st7=new JTextField(10);
c1=new JComboBox(s);

sb1=new JButton("ADD");
sb2=new JButton("VIEW");
sb3=new JButton("MODIFY");
sb4=new JButton("DELETE");
sb5=new JButton("CLEAR");
sb6=new JButton("OK");

sb1.setForeground(Color.black);
sb2.setForeground(Color.black);
sb3.setForeground(Color.black);
sb4.setForeground(Color.black);
sb5.setForeground(Color.black);
sb6.setForeground(Color.black);

sh.setBounds(20,10,540,30);

sh1.setBounds(50,150,200,30);
c2.setBounds(300,150,240,30);
sb6.setBounds(250,250,100,30);

sl1.setBounds(50,30,200,30);
st1.setBounds(300,30,240,30);
sl2.setBounds(50,80,200,30);
st2.setBounds(300,80,240,30);
sl3.setBounds(50,130,200,30);
st3.setBounds(300,130,240,30);
sl4.setBounds(50,180,200,30);
st4.setBounds(300,180,240,30);
sl5.setBounds(50,230,200,30);
st5.setBounds(300,230,240,30);
sl6.setBounds(50,280,200,30);
st6.setBounds(300,280,240,30);
sl7.setBounds(50,330,200,30);
st7.setBounds(300,330,240,30);
sl8.setBounds(50,380,200,30);
c1.setBounds(300,380,240,30);

sb1.setBounds(30,10,100,30);
sb2.setBounds(140,10,100,30);
sb3.setBounds(250,10,100,30);
sb4.setBounds(360,10,100,30);
sb5.setBounds(470,10,100,30);

p1.add(sp1);
p1.add(sp2);
p1.add(sp3);

sp1.add(sh);
sp2.add(sl1);
sp2.add(st1);
sp2.add(sl2);
sp2.add(st2);
sp2.add(sl3);
sp2.add(st3);
sp2.add(sl4);
sp2.add(st4);
sp2.add(sl5);
sp2.add(st5);
sp2.add(sl6);
sp2.add(st6);
sp2.add(sl7);
sp2.add(st7);
sp2.add(sl8);
sp2.add(c1);
sp2.add(sh1);
sp2.add(c2);
sp2.add(sb6);

sp3.add(sb1);
sp3.add(sb2);
sp3.add(sb3);
sp3.add(sb4);
sp3.add(sb5);
p1.add(s1);
p1.add(s2);
p1.add(sl);

sh1.setVisible(false);
c2.setVisible(false);
sb6.setVisible(false);
sb3.setEnabled(false);
sb4.setEnabled(false);

//.........................Book Issue

JLabel si=new JLabel("",pimg,JLabel.CENTER);


pi1=new JPanel();
pi2=new JPanel();
pi3=new JPanel();

pi1.setOpaque(false);
pi2.setOpaque(false);
pi3.setOpaque(false);

pi1.setLayout(null);
pi2.setLayout(null);
pi3.setLayout(null);

//pi1.setBackground(new Color(110,208,228));
//pi2.setBackground(new Color(110,208,228));
//pi3.setBackground(new Color(110,208,228));

p2.setBounds(0,0,(w+100),h);
si.setBounds(0,0,(w+100),h);

pi1.setBounds(300,50,600,50);
pi1.setBorder(label);

pi2.setBounds(300,110,600,260);
pi2.setBorder(label);

pi3.setBounds(300,380,600,50);
pi3.setBorder(label);

ish=new JLabel("BOOK ISSUE",JLabel.CENTER);


ish.setFont(f);
ish.setForeground(Color.black);

ish.setBounds(20,10,540,30);

li1=new JLabel("Staff ID");


li2=new JLabel("Book Code");
li3=new JLabel("Date of Issue");
li4=new JLabel("Date of Return");

li1.setFont(f1);
li2.setFont(f1);
li3.setFont(f1);
li4.setFont(f1);

li1.setForeground(Color.black);
li2.setForeground(Color.black);
li3.setForeground(Color.black);
li4.setForeground(Color.black);

ti1=new JTextField(10);
ti2=new JTextField(10);
ti3=new JTextField(10);
ti4=new JTextField(10);

bi1=new JButton("ISSUE");
bi2=new JButton("CLEAR");

bi1.setForeground(Color.black);
bi2.setForeground(Color.black);

li1.setBounds(50,30,200,30);
ti1.setBounds(300,30,240,30);
li2.setBounds(50,80,200,30);
ti2.setBounds(300,80,240,30);
li3.setBounds(50,130,200,30);
ti3.setBounds(300,130,240,30);
li4.setBounds(50,180,200,30);
ti4.setBounds(300,180,240,30);

bi1.setBounds(200,10,100,30);
bi2.setBounds(320,10,100,30);

p2.add(pi1);
p2.add(pi2);
p2.add(pi3);

pi1.add(ish);

pi2.add(li1);
pi2.add(ti1);
pi2.add(li2);
pi2.add(ti2);
pi2.add(li3);
pi2.add(ti3);
pi2.add(li4);
pi2.add(ti4);

pi3.add(bi1);
pi3.add(bi2);
p2.add(si);

//.........................Book Renewal

JLabel sre=new JLabel("",pimg,JLabel.CENTER);

pre1=new JPanel();
pre2=new JPanel();
pre3=new JPanel();

pre1.setLayout(null);
pre2.setLayout(null);
pre3.setLayout(null);

pre1.setOpaque(false);
pre2.setOpaque(false);
pre3.setOpaque(false);

//pre1.setBackground(new Color(110,208,228));
//pre2.setBackground(new Color(110,208,228));
//pre3.setBackground(new Color(110,208,228));

p3.setBounds(0,0,(w+100),(h));
sre.setBounds(0,0,(w+100),(h));

pre1.setBounds(300,50,600,50);
pre1.setBorder(label);

pre2.setBounds(300,110,600,300);
pre2.setBorder(label);

pre3.setBounds(300,420,600,50);
pre3.setBorder(label);

resh=new JLabel("BOOK RENEWAL",JLabel.CENTER);


resh.setFont(f);
resh.setForeground(Color.black);

resh.setBounds(20,10,540,30);

lre1=new JLabel("Staff ID");


lre2=new JLabel("Book Code");
lre3=new JLabel("Date of Renewal");
lre4=new JLabel("Date of Return");
lre5=new JLabel("Fine");

lre1.setFont(f1);
lre2.setFont(f1);
lre3.setFont(f1);
lre4.setFont(f1);
lre5.setFont(f1);

lre1.setForeground(Color.black);
lre2.setForeground(Color.black);
lre3.setForeground(Color.black);
lre4.setForeground(Color.black);
lre5.setForeground(Color.black);

tre1=new JTextField(10);
tre3=new JTextField(10);
tre4=new JTextField(10);
tre5=new JTextField(10);
cre1=new JComboBox();

bre1=new JButton("RENEWAL");
bre2=new JButton("CLEAR");

bre1.setForeground(Color.black);
bre2.setForeground(Color.black);

lre1.setBounds(50,30,200,30);
tre1.setBounds(300,30,240,30);
lre2.setBounds(50,80,200,30);
cre1.setBounds(300,80,240,30);
lre3.setBounds(50,130,200,30);
tre3.setBounds(300,130,240,30);
lre4.setBounds(50,180,200,30);
tre4.setBounds(300,180,240,30);
lre5.setBounds(50,230,200,30);
tre5.setBounds(300,230,240,30);

bre1.setBounds(200,10,100,30);
bre2.setBounds(320,10,100,30);

p3.add(pre1);
p3.add(pre2);
p3.add(pre3);

pre1.add(resh);

pre2.add(lre1);
pre2.add(tre1);
pre2.add(lre2);
pre2.add(cre1);
pre2.add(lre3);
pre2.add(tre3);
pre2.add(lre4);
pre2.add(tre4);
pre2.add(lre5);
pre2.add(tre5);

pre3.add(bre1);
pre3.add(bre2);
p3.add(sre);
//.........................Book Return

JLabel srt=new JLabel("",pimg,JLabel.CENTER);

prt1=new JPanel();
prt2=new JPanel();
prt3=new JPanel();

prt1.setLayout(null);
prt2.setLayout(null);
prt3.setLayout(null);

prt1.setOpaque(false);
prt2.setOpaque(false);
prt3.setOpaque(false);

//prt1.setBackground(new Color(110,208,228));
//prt2.setBackground(new Color(110,208,228));
//prt3.setBackground(new Color(110,208,228));

p4.setBounds(0,0,(w+100),(h));
srt.setBounds(0,0,(w+100),(h));

prt1.setBounds(300,50,600,50);
prt1.setBorder(label);

prt2.setBounds(300,110,600,300);
prt2.setBorder(label);

prt3.setBounds(300,420,600,50);
prt3.setBorder(label);

rtsh=new JLabel("BOOK RETURN",JLabel.CENTER);


rtsh.setFont(f);
rtsh.setForeground(Color.black);

rtsh.setBounds(20,10,540,30);

lrt1=new JLabel("Staff ID");


lrt2=new JLabel("Book Code");
lrt3=new JLabel("Date of Issue");
lrt4=new JLabel("Date of Return");
lrt5=new JLabel("Fine");

lrt1.setFont(f1);
lrt2.setFont(f1);
lrt3.setFont(f1);
lrt4.setFont(f1);
lrt5.setFont(f1);

lrt1.setForeground(Color.black);
lrt2.setForeground(Color.black);
lrt3.setForeground(Color.black);
lrt4.setForeground(Color.black);
lrt5.setForeground(Color.black);

trt1=new JTextField(10);
trt3=new JTextField(10);
trt4=new JTextField(10);
trt5=new JTextField(10);
crt1=new JComboBox();

brt1=new JButton("RETURN");
brt2=new JButton("CLEAR");

brt1.setForeground(Color.black);
brt2.setForeground(Color.black);

lrt1.setBounds(50,30,200,30);
trt1.setBounds(300,30,240,30);
lrt2.setBounds(50,80,200,30);
crt1.setBounds(300,80,240,30);
lrt3.setBounds(50,130,200,30);
trt3.setBounds(300,130,240,30);
lrt4.setBounds(50,180,200,30);
trt4.setBounds(300,180,240,30);
lrt5.setBounds(50,230,200,30);
trt5.setBounds(300,230,240,30);

brt1.setBounds(200,10,100,30);
brt2.setBounds(320,10,100,30);

p4.add(prt1);
p4.add(prt2);
p4.add(prt3);

prt1.add(rtsh);

prt2.add(lrt1);
prt2.add(trt1);
prt2.add(lrt2);
prt2.add(crt1);
prt2.add(lrt3);
prt2.add(trt3);
prt2.add(lrt4);
prt2.add(trt4);
prt2.add(lrt5);
prt2.add(trt5);

prt3.add(brt1);
prt3.add(brt2);
p4.add(srt);

//.........................Search

JLabel ss=new JLabel("",pimg,JLabel.CENTER);


ps1=new JPanel();
ps2=new JPanel();
ps3=new JPanel();

ps1.setLayout(null);
ps2.setLayout(null);
ps3.setLayout(null);

ps1.setOpaque(false);
ps2.setOpaque(false);
ps3.setOpaque(false);

//ps1.setBackground(new Color(110,208,228));
//ps2.setBackground(new Color(110,208,228));
//ps3.setBackground(new Color(110,208,228));

p6.setBounds(0,0,(w+100),(h));
ss.setBounds(0,0,(w+100),(h));

ps1.setBounds(300,50,600,50);
ps1.setBorder(label);

ps2.setBounds(300,110,600,300);
ps2.setBorder(label);

ps3.setBounds(300,420,600,50);
ps3.setBorder(label);

shs=new JLabel("SEARCH",JLabel.CENTER);
shs.setFont(f);
shs.setForeground(Color.black);

shs.setBounds(20,10,540,30);

ls1=new JLabel("Choose Option");

ls1.setFont(new Font("Times New Roman",Font.BOLD,18));


ls1.setForeground(Color.black);

ts1=new JTextField(15);
c3=new JComboBox();
r1=new JRadioButton("Book Title",true);
r2=new JRadioButton("Book Author");
r3=new JRadioButton("Book Code");
bg=new ButtonGroup();
bg.add(r1);
bg.add(r2);
bg.add(r3);

r1.setFont(f1);
r1.setForeground(Color.black);
r2.setFont(f1);
r2.setForeground(Color.black);
r3.setFont(f1);
r3.setForeground(Color.black);

bs1=new JButton("SEARCH");
bs1.setForeground(Color.black);

ls1.setBounds(50,30,200,30);
r1.setBounds(200,60,200,30);
r2.setBounds(200,110,200,30);
r3.setBounds(200,160,200,30);

r1.setOpaque(false);
r2.setOpaque(false);
r3.setOpaque(false);

//r1.setBackground(new Color(110,208,228));
//r2.setBackground(new Color(110,208,228));
//r3.setBackground(new Color(110,208,228));

ts1.setBounds(200,250,200,30);
c3.setBounds(200,250,200,30);

bs1.setBounds(250,10,100,30);

c3.setVisible(false);

p6.add(ps1);
p6.add(ps2);
p6.add(ps3);

ps1.add(shs);

ps2.add(ls1);
ps2.add(ts1);
ps2.add(r1);
ps2.add(r2);
ps2.add(r3);
ps2.add(c3);

ps3.add(bs1);
p6.add(ss);

//..........................Staff Modification

JLabel sss=new JLabel("",pimg,JLabel.CENTER);


pss1=new JPanel();
pss2=new JPanel();
pss3=new JPanel();

pss1.setLayout(null);
pss2.setLayout(null);
pss3.setLayout(null);

pss1.setOpaque(false);
pss2.setOpaque(false);
pss3.setOpaque(false);

//pss1.setBackground(new Color(110,208,228));
//pss2.setBackground(new Color(110,208,228));
//pss3.setBackground(new Color(110,208,228));

p5.setBounds(0,0,(w+100),(h));
sss.setBounds(0,0,(w+100),(h));

pss1.setBounds(300,50,600,50);
pss2.setBounds(300,110,600,160);
pss3.setBounds(300,280,600,50);
pss1.setBorder(label);

pss3.setBorder(label);
pss2.setBorder(label);

shss=new JLabel("STAFF MODIFICATION",JLabel.CENTER);


shss.setFont(f);
shss.setForeground(Color.black);

shss.setBounds(20,10,540,30);

lss1=new JLabel("Staff ID");


lss1.setFont(f1);
lss1.setForeground(Color.black);

tss1=new JTextField(15);
lss1.setBounds(50,60,200,30);
tss1.setBounds(200,60,200,30);

bss1=new JButton("DELETE");
bss1.setForeground(Color.black);

bss2=new JButton("MODIFY");
bss2.setForeground(Color.black);

if(tit.equals("user"))
{
bss1.setVisible(false);

}
else
{

bss2.setVisible(false);
}

bss1.setBounds(250,10,100,30);
bss2.setBounds(250,10,100,30);

p5.add(pss1);
p5.add(pss2);
p5.add(pss3);

pss1.add(shss);
pss2.add(lss1);
pss2.add(tss1);
pss3.add(bss1);
pss3.add(bss2);
p5.add(sss);

//..........................Admin Modification

JLabel sa=new JLabel("",pimg,JLabel.CENTER);


pa1=new JPanel();
pa2=new JPanel();
pa3=new JPanel();

pa1.setLayout(null);
pa2.setLayout(null);
pa3.setLayout(null);
pa1.setOpaque(false);
pa2.setOpaque(false);
pa3.setOpaque(false);

//pa1.setBackground(new Color(110,208,228));
//pa2.setBackground(new Color(110,208,228));
//pa3.setBackground(new Color(110,208,228));

p8.setBounds(0,0,(w+100),(h));
sa.setBounds(0,0,(w+100),(h));

pa1.setBounds(300,50,600,50);
pa1.setBorder(label);

pa2.setBounds(300,110,600,230);
pa2.setBorder(label);

pa3.setBounds(300,350,600,50);
pa3.setBorder(label);

sha=new JLabel("ADMIN MODIFICATION",JLabel.CENTER);


sha.setFont(f);
sha.setForeground(Color.black);

sha.setBounds(20,10,540,30);

la1=new JLabel("Choose Option");

la1.setFont(new Font("Times New Roman",Font.BOLD,18));


la1.setForeground(Color.black);

ra1=new JRadioButton("CREATE",true);
ra2=new JRadioButton("DELETE");
bag=new ButtonGroup();
bag.add(ra1);
bag.add(ra2);

ra1.setFont(f1);
ra1.setForeground(Color.black);
ra2.setFont(f1);
ra2.setForeground(Color.black);

la2=new JLabel("Enter Admin ID");


la2.setFont(f1);
ta1=new JTextField(15);
la2.setVisible(false);
ta1.setVisible(false);

ba1=new JButton("OK");
ba1.setForeground(Color.black);

la1.setBounds(50,30,200,30);
ra1.setBounds(200,60,200,30);
ra2.setBounds(200,110,200,30);

ra1.setOpaque(false);
ra2.setOpaque(false);

//ra1.setBackground(new Color(110,208,228));
//ra2.setBackground(new Color(110,208,228));

la2.setBounds(50,170,200,30);
ta1.setBounds(200,170,200,30);

ba1.setBounds(250,10,100,30);

p8.add(pa1);
p8.add(pa2);
p8.add(pa3);

pa1.add(sha);

pa2.add(la1);
pa2.add(la2);
pa2.add(ta1);
pa2.add(ra1);
pa2.add(ra2);

pa3.add(ba1);
p8.add(sa);

sb1.addActionListener(this);
sb2.addActionListener(this);
sb3.addActionListener(this);
sb4.addActionListener(this);
sb5.addActionListener(this);
sb6.addActionListener(this);

bi1.addActionListener(this);
bi2.addActionListener(this);
brt1.addActionListener(this);
brt2.addActionListener(this);
bre1.addActionListener(this);
bre2.addActionListener(this);
bs1.addActionListener(this);
bss1.addActionListener(this);
bss2.addActionListener(this);
ba1.addActionListener(this);

sxb6.addActionListener(this);

r1.addActionListener(this);
r2.addActionListener(this);
r3.addActionListener(this);
ra1.addActionListener(this);
ra2.addActionListener(this);

st1.addFocusListener(this);
st2.addFocusListener(this);
ti3.addFocusListener(this);
ti4.addFocusListener(this);
tre1.addFocusListener(this);
trt1.addFocusListener(this);
tre3.addFocusListener(this);
tre4.addFocusListener(this);
trt3.addFocusListener(this);
trt4.addFocusListener(this);
tre5.addFocusListener(this);
trt5.addFocusListener(this);

public void actionPerformed(ActionEvent ae)


{
//******************************************SEARCH
panel**********************

if(ae.getSource()==r3)
{
c3.removeAllItems();
c3.setVisible(true);
ts1.setVisible(false);

String st="Select * from stock";

conestablish1 ci=new conestablish1();


rt=ci.selectconDb(st);

try
{
boolean more=rt.next();
while(more)
{
c3.addItem(rt.getString(3));
more=rt.next();
}

}
catch(Exception e2)
{

JOptionPane.showMessageDialog(null,"rs_next.........->"+e2.toString());
}

}
if(ae.getSource()==r1||ae.getSource()==r2)
{
c3.setVisible(false);
ts1.setVisible(true);
}

if(ae.getSource()==bs1)
{
try
{
if(r3.isSelected())
{
String s="";
s="select * from stock where
isbn='"+c3.getSelectedItem()+"'";

conestablish1 cc=new conestablish1();


ResultSet rs=cc.selectconDb(s);
report re=new report(rs);
}
else
{
if(ts1.getText().equals(""))
JOptionPane.showMessageDialog(null,"Please
enter the Value.");

else
{
String s="";
if(r1.isSelected())
s="select * from stock where
b_name='"+ts1.getText()+"'";
if(r2.isSelected())
s="select * from stock where
author='"+ts1.getText()+"'";

conestablish1 cc=new conestablish1();


ResultSet rs=cc.selectconDb(s);
report re=new report(rs);
ts1.setText("");
}

}
}
catch(Exception e)
{

//***************************************************Staff
panel**********************************************

//.................................Delete Button

if(ae.getSource()==bss1)
{
String a=tss1.getText();
if(a.equals(""))
{
JOptionPane.showMessageDialog(null,"Please
enter the Value.");
}
else
{
String sr="Select * from register";
int f=0;
try
{
conestablish1 ci=new conestablish1();
rs=ci.selectconDb(sr);
}
catch(Exception e2)
{
JOptionPane.showMessageDialog(null,e2.toString());
}
try
{
while(rs.next())
{
if(a.equals(rs.getString(1)))
{
f=1;
}
}
}
catch(Exception e2)
{

JOptionPane.showMessageDialog(null,"rs_next.........->"+e2.toString());
}
if(f==1)
{
String at=tss1.getText();
String delete="DELETE FROM Register
WHERE staff_id='"+tss1.getText()+"'";
String del="DELETE FROM user_login
WHERE login_id='"+at+"'";

int
i=JOptionPane.showConfirmDialog(null,"Are you sure to delete this record?");

if(i==0)
{
conestablish1 ins=new
conestablish1();
ins.deleteconDb(delete);
conestablish1 ins1=new
conestablish1();
ins1.deleteconDb(del);

JOptionPane.showMessageDialog(null,"One Record Deleted");


tss1.setText("");

}
else
{

JOptionPane.showMessageDialog(null,"Wrong Staff ID");


tss1.setText("");
}
}

//...............................Ok Button

if(ae.getSource()==bss2)
{
if(tss1.getText().equals(""))
{
JOptionPane.showMessageDialog(null,"Please enter the
Value.");
}
else
{
String sr="Select * from register";
int f=0;
try
{
conestablish1 ci=new conestablish1();
rs=ci.selectconDb(sr);
}
catch(Exception e2)
{

JOptionPane.showMessageDialog(null,e2.toString());
}
try
{
while(rs.next())
{
if(tss1.getText().equals(rs.getString(1)))
{
f=1;
}
}
}
catch(Exception e2)
{

JOptionPane.showMessageDialog(null,"rs_next.........->"+e2.toString());
}
if(f==0)
{
JOptionPane.showMessageDialog(null,"Wrong
Staff ID");
tss1.setText("");
}
else
{

reglib1 frame=new
reglib1(tss1.getText(),"up");
frame.setSize(1280,720);
frame.setVisible(true);
tss1.setText("");

}
}

if(ae.getSource()==sxb6)
{
System.exit(1);
}

//************************************************Stock
Panel********************************************

//.....................................Add Button

if(ae.getSource()==sb1)
{
//.............All Fields data is filled or data

if(st1.getText().equals("")||st2.getText().equals("")||st3.getText().equals("")||s
t4.getText().equals("")||st5.getText().equals("")||st6.getText().equals("")||st7.getText
().equals(""))
{
JOptionPane.showMessageDialog(null,"Plz Fill the Full
Details");
}
else
{
//...........check ISBN No

String sv="Select * from stock";


int f=0;
try
{
conestablish1 ci=new conestablish1();
rs=ci.selectconDb(sv);
}
catch(Exception e2)
{
JOptionPane.showMessageDialog(null,e2.toString());
}
try
{
boolean more1=rs.next();
while(more1)
{
if(rs.getString(3).equals(st3.getText()))
{
f=1;
}
more1=rs.next();

}
if(f==1)
{

JOptionPane.showMessageDialog(null,"Duplicate Book Code");


}

}
catch(Exception e2)
{
JOptionPane.showMessageDialog(null,"rs_next.........-
>"+e2.toString());
}

//...........................insert record

if(f==0)
{
String s="INSERT INTO stock
VALUES('"+st1.getText()+"'";
s+=",'"+date+"'";
s+=",'"+st3.getText()+"'";
s+=",'"+st4.getText()+"'";
s+=",'"+st5.getText()+"'";
s+=",'"+st6.getText()+"'";
s+=",'"+st7.getText()+"'";
s+=",'"+c1.getSelectedItem()+"'";
s+=",'"+"not issue"+"'";
s+=")";

try
{
conestablish1 ins=new conestablish1();
ins.insertIntoDb(s);
JOptionPane.showMessageDialog(null,"1
Record Added");
}
catch(Exception a)
{

JOptionPane.showMessageDialog(null,"insert_con_error.........-
>"+a.toString());
}

//st1.setText(Integer.toString(Integer.parseInt(st1.getText())+1));
st1.setText("");
st2.setText("");
st3.setText("");
st4.setText("");
st5.setText("");
st6.setText("");
st7.setText("");
c1.setSelectedItem("Complement");
}
}
}

//......................................View Button

if(ae.getSource()==sb2)
{
c2.removeAllItems();
sh1.setVisible(true);
c2.setVisible(true);
sb6.setVisible(true);

sl1.setVisible(false);
sl2.setVisible(false);
sl3.setVisible(false);
sl4.setVisible(false);
sl5.setVisible(false);
sl6.setVisible(false);
sl7.setVisible(false);
sl8.setVisible(false);
st1.setVisible(false);
st2.setVisible(false);
st3.setVisible(false);
st4.setVisible(false);
st5.setVisible(false);
st6.setVisible(false);
st7.setVisible(false);
c1.setVisible(false);
sb1.setVisible(false);
sb2.setVisible(false);
sb3.setVisible(false);
sb4.setVisible(false);
sb5.setVisible(false);

String st="Select * from stock";


try
{
conestablish1 ci=new conestablish1();
rt=ci.selectconDb(st);
}
catch(Exception e2)
{
JOptionPane.showMessageDialog(null,e2.toString());
}
try
{
boolean more=rt.next();
while(more)
{
c2.addItem(rt.getString(3));
more=rt.next();
}

}
catch(Exception e2)
{
JOptionPane.showMessageDialog(null,"rs_next.........-
>"+e2.toString());
}
}

//............................................Ok Button

if(ae.getSource()==sb6)
{
t=(String)c2.getSelectedItem();
sh1.setVisible(false);
c2.setVisible(false);
sb6.setVisible(false);

sl1.setVisible(true);
sl2.setVisible(true);
sl3.setVisible(true);
sl4.setVisible(true);
sl5.setVisible(true);
sl6.setVisible(true);
sl7.setVisible(true);
sl8.setVisible(true);
st1.setVisible(true);
st2.setVisible(true);
st3.setVisible(true);
st4.setVisible(true);
st5.setVisible(true);
st6.setVisible(true);
st7.setVisible(true);
c1.setVisible(true);
sb1.setVisible(true);
sb2.setVisible(true);
sb3.setVisible(true);
sb4.setVisible(true);
sb5.setVisible(true);
sb3.setEnabled(true);
sb4.setEnabled(true);
sb1.setEnabled(false);
sb2.setEnabled(false);

String ss="Select * from stock";


try
{
conestablish1 ci=new conestablish1();
rs=ci.selectconDb(ss);
}
catch(Exception e2)
{

JOptionPane.showMessageDialog(null,"update_next.........->"+e2.toString());
}
try
{
while(rs.next())
{
if(t.equals(rs.getString(3)))
{
st1.setText(rs.getString(1));

d1=rs.getDate(2);

SimpleDateFormat sdfDestination
= new SimpleDateFormat("dd-MM-yyyy");
String strDate =
sdfDestination.format(d1);

st2.setText(strDate);
st3.setText(t);
st4.setText(rs.getString(4));

st5.setText(rs.getString(5));
st6.setText(rs.getString(6));
st7.setText(rs.getString(7));
c1.setSelectedItem(rs.getString(8));
}
}

}
catch(Exception e2)
{

JOptionPane.showMessageDialog(null,"rs_next.........->"+e2.toString());
}
}

//................................................Modify Button

if(ae.getSource()==sb3)
{
String r="";
try
{
r+="UPDATE stock set isbn='"+st3.getText()+"',
b_name='"+st4.getText()+"', author='"+st5.getText()+"', price="+st6.getText()+",
rack='"+st7.getText()+"', type='"+c1.getSelectedItem()+"' WHERE
acc_id="+st1.getText()+" ";
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,"in sql.........-
>"+e.toString());
}

try
{
conestablish1 i=new conestablish1();
i.updateDb(r);
JOptionPane.showMessageDialog(null,"Stock
Updated");
}
catch(Exception e1)
{

JOptionPane.showMessageDialog(null,"update_con.........->"+e1.toString());
}
}

//..........................................Delete Button

if(ae.getSource()==sb4)
{
try
{
String delete="DELETE FROM stock WHERE
acc_id="+st1.getText();

int i=JOptionPane.showConfirmDialog(null,"Are you


sure you want to delete this record?");
if(i==0)
{
conestablish1 ins=new conestablish1 ();
ins.deleteconDb(delete);
JOptionPane.showMessageDialog(null,"Stock
Deleted");
}

}
catch(Exception e1)
{
JOptionPane.showMessageDialog(null,"in
deletion_con...........:"+e1.toString());
}
st1.setText("");
st2.setText("");
st3.setText("");
st4.setText("");
st5.setText("");
st6.setText("");
st7.setText("");
}

//.................................clear Button

if(ae.getSource()==sb5)
{
st1.setText("");
st2.setText("");
st3.setText("");
st4.setText("");
st5.setText("");
st6.setText("");
st7.setText("");
sb1.setEnabled(true);
sb2.setEnabled(true);
sb3.setEnabled(false);
sb4.setEnabled(false);
}

//****************************************************Issue
Panel****************************************************
if(ae.getSource()==bi1)
{
//.............All Fields data is filled or data

if(ti1.getText().equals("")||ti2.getText().equals("")||ti3.getText().equals("")||ti
4.getText().equals(""))
{
JOptionPane.showMessageDialog(null,"Plz Fill the Full
Details");
}

else
{
//....................Staff Id Checking.................

int f=0;
String ss="Select * from register";

conestablish1 ci=new conestablish1();


rs=ci.selectconDb(ss);

try
{
while(rs.next())
{
if(ti1.getText().equals(rs.getString(1)))
f=1;
}
}
catch(Exception e2)
{

JOptionPane.showMessageDialog(null,e2.toString());
}

if(f==0)

JOptionPane.showMessageDialog(null,"Incorrect Staff ID");


else
{

//..............Book Code Checking......................

int f1=0;
String ss1="Select * from stock";
conestablish1 ci1=new conestablish1();
rt=ci1.selectconDb(ss1);

try
{
while(rt.next())
{

if(ti2.getText().equals(rt.getString(3))&& rt.getString(9).equals("not issue"))


f1=1;
}
}
catch(Exception e2)
{

JOptionPane.showMessageDialog(null,e2.toString());
}

if(f1==0)

JOptionPane.showMessageDialog(null,"Incorrect Book Code");

else
{
//..............No of Books Issued
Checking.......................

String sr="Select * from issue";


int count=0;
try
{
conestablish1 ci2=new
conestablish1();
rs=ci2.selectconDb(sr);
}
catch(Exception e2)
{

JOptionPane.showMessageDialog(null,e2.toString());
}
try
{
while(rs.next())
{

if(ti1.getText().equals(rs.getString(1)))
{
count++;
}
}
}
catch(Exception e2)
{

JOptionPane.showMessageDialog(null,"rs_next.........->"+e2.toString());
}

if(count<4)
{
String r="";

ss="Select * from stock";


try
{
conestablish1 ci3=new
conestablish1();
rs=ci3.selectconDb(ss);
}
catch(Exception e2)
{

JOptionPane.showMessageDialog(null,e2.toString());
}
try
{
String sel=ti2.getText();

while(rs.next())
{

if(ti2.getText().equals(rs.getString(3)) && rs.getString(9).equals("not


issue"))
{

r+="UPDATE stock set status='"+"issue"+"' WHERE


isbn='"+ti2.getText()+"' ";
try
{

conestablish1 i=new conestablish1();

i.updateDb(r);

catch(Exception e1)
{
JOptionPane.showMessageDialog(null,e1.toString());
}
String
p="INSERT INTO issue VALUES('"+ti1.getText()+"'";

p+=",'"+ti2.getText()+"'";

p+=",'"+date+"'";

p+=",'"+date2+"'";
p+=")";

try
{

conestablish1 ins=new conestablish1();

ins.insertIntoDb(p);

JOptionPane.showMessageDialog(null,"Book Issued");

ti1.setText("");

ti2.setText("");

ti3.setText("");

ti4.setText("");
}

catch(Exception a)
{

JOptionPane.showMessageDialog(null,a.toString());
}
}

}
catch(Exception e2)
{

JOptionPane.showMessageDialog(null,"rs_next.........->"+e2.toString());
}
}
else
{
JOptionPane.showMessageDialog(null,"You can't issued more books... You
alrady issued 4 books");
}
}
}
}
}

if(ae.getSource()==bi2)
{
ti1.setText("");
ti2.setText("");
ti3.setText("");
ti4.setText("");
}

//******************************************Return
panel**************************************

if(ae.getSource()==brt1)
{
//.............All Fields data is filled or data

if(trt1.getText().equals("")||trt3.getText().equals("")||trt4.getText().equals(""
)||trt5.getText().equals(""))
{
JOptionPane.showMessageDialog(null,"Plz Fill the Full
Details");
}
else
{
String sel=(String)crt1.getSelectedItem();
try
{
String delete="DELETE FROM issue WHERE
isbn='"+crt1.getSelectedItem()+"'";

conestablish1 ins=new conestablish1 ();


ins.deleteconDb(delete);

JOptionPane.showMessageDialog(null,"Book Returned");

}
catch(Exception e1)
{

JOptionPane.showMessageDialog(null,e1.toString());
}
String upd="UPDATE stock set status='"+"not
issue"+"' WHERE isbn='"+crt1.getSelectedItem()+"' ";;

try
{
conestablish1 i=new conestablish1();
i.updateDb(upd);

}
catch(Exception e1)
{

JOptionPane.showMessageDialog(null,e1.toString());
}
crt1.removeItem(sel);
trt3.setText("");
trt4.setText("");
trt5.setText("");
}
}

if(ae.getSource()==brt2)
{
trt1.setText("");
trt3.setText("");
trt4.setText("");
trt5.setText("");
trt1.requestFocus();
}

//************************************Renewal
Panel*****************************************

if(ae.getSource()==bre1)
{
//.............All Fields data is filled or data

if(tre1.getText().equals("")||tre3.getText().equals("")||tre4.getText().equals("
")||tre5.getText().equals(""))
{
JOptionPane.showMessageDialog(null,"Plz Fill the Full
Detail");
}
else
{
String updt="UPDATE issue set
issue_date='"+date+"',ret_date='"+date3+"' WHERE
isbn='"+cre1.getSelectedItem()+"' ";;
try
{
conestablish1 i=new conestablish1();
i.updateDb(updt);
JOptionPane.showMessageDialog(null,"Book
Renewed");
}
catch(Exception e1)
{

JOptionPane.showMessageDialog(null,e1.toString());
}
tre3.setText("");
tre4.setText("");
tre5.setText("");
}
}

if(ae.getSource()==bre2)
{
tre1.setText("");
tre3.setText("");
tre4.setText("");
tre5.setText("");
tre1.requestFocus();
}

//************************************Admin
Panel*****************************************

if(ae.getSource()==ra2)
{
la2.setVisible(true);
ta1.setVisible(true);
}

if(ae.getSource()==ra1)
{
la2.setVisible(false);
ta1.setVisible(false);
}

if(ae.getSource()==ba1)
{
if(ra1.isSelected())
{
logindemo1 frame=new logindemo1("");
frame.setSize(1280,720);
frame.setVisible(true);
}
else
{
String a=ta1.getText();
if(a.equals(""))
{
JOptionPane.showMessageDialog(null,"Please
enter the Value.");
}
else
{
String sr="Select * from admin_login";
int f=0;
try
{
conestablish1 ci1=new conestablish1();
rs=ci1.selectconDb(sr);
}
catch(Exception e2)
{

JOptionPane.showMessageDialog(null,e2.toString());
}
try
{
while(rs.next())
{
if(a.equals(rs.getString(1)))
{
f=1;
}
}
}
catch(Exception e2)
{

JOptionPane.showMessageDialog(null,"rs_next.........->"+e2.toString());
}
if(f==1)
{
String delete="DELETE FROM admin_login
WHERE login_id='"+ta1.getText()+"'";

int
i=JOptionPane.showConfirmDialog(null,"Are you sure to delete this record?");
if(i==0)
{
conestablish1 ins=new conestablish1();
ins.deleteconDb(delete);

JOptionPane.showMessageDialog(null,"One Record Deleted");


ta1.setText("");

}
}
else
{
JOptionPane.showMessageDialog(null,"Wrong
Admin ID");
ta1.setText("");
}
}
}
}
}

public void focusGained(FocusEvent e)


{

try
{
if(e.getSource()==st2)
{
st2.setText(date);
}

if(e.getSource()==st1)
{
int j=0;
String ss="Select * from stock";
try
{
conestablish1 ci=new conestablish1();
rs=ci.selectconDb(ss);
}
catch(Exception e2)
{

JOptionPane.showMessageDialog(null,"update_next.........->"+e2.toString());
}
try
{
boolean more=rs.next();
if(!more)
{
j=1;
}
else
{
while(more)
{
j=Integer.parseInt(rs.getString(1));
more=rs.next();
}
j=j+1;
}
st1.setText(Integer.toString(j));

}
catch(Exception e2)
{
JOptionPane.showMessageDialog(null,"rs_next.........-
>"+e2.toString());
}
}

}catch(Exception ee)
{
}
if(e.getSource()==ti3)
{
ti3.setText(date);
}
if(e.getSource()==ti4)
{
ti4.setText(date2);
}
if(e.getSource()==tre1)
{
cre1.removeAllItems();
}
if(e.getSource()==trt1)
{
crt1.removeAllItems();
}
if(e.getSource()==tre3)
{
tre3.setText(date);
}
if(e.getSource()==tre4)
{
tre4.setText(date3);
}

if(e.getSource()==trt3)
{
if(trt1.getText().equals(""))
{
//trt1.requestFocus();
}
else
{
int f=0;
String ss="Select * from register";

conestablish1 ci1=new conestablish1();


rs=ci1.selectconDb(ss);

try
{
while(rs.next())
{
if(trt1.getText().equals(rs.getString(1)))
f=1;
}
}
catch(Exception e2)
{

JOptionPane.showMessageDialog(null,e2.toString());
}

if(f==0)
{
}
else
{
String sr="Select * from issue";
conestablish1 ci=new conestablish1();
rs=ci.selectconDb(sr);

try
{
while(rs.next())
{

if(crt1.getSelectedItem().equals(rs.getString(2)))
{
d1=rs.getDate(3);
d2=rs.getDate(4);
SimpleDateFormat sdfDestination
= new SimpleDateFormat("dd-MM-yyyy");
strdate =
sdfDestination.format(d1);

strdate1 =
sdfDestination.format(d2);

trt3.setText(strdate);
}
}
}
catch(Exception e2)
{

JOptionPane.showMessageDialog(null,"rs_next.........->"+e2.toString());
}
}
}
}
if(e.getSource()==trt4)
{
if(trt1.getText().equals(""))
{
//trt1.requestFocus();
}
else
{
trt4.setText(strdate1);
}
}

//..............Fine field of Return

if(e.getSource()==trt5)
{
if(trt1.getText().equals(""))
{

}
else
{
int f=0;
String ss="Select * from register";

conestablish1 ci=new conestablish1();


rs=ci.selectconDb(ss);

try
{
while(rs.next())
{
if(trt1.getText().equals(rs.getString(1)))
f=1;
}
}
catch(Exception e2)
{

JOptionPane.showMessageDialog(null,e2.toString());
}

if(f==0)
{
}
else
{
long days=(tim-d2.getTime())/(1000*60*60*24);
long fine=0;
if(days>0)
{
fine=days*1;
trt5.setText(Long.toString(fine));
}
else
trt5.setText("0");
}
}
}
//...............Fine Field of Renewal

if(e.getSource()==tre5)
{
if(tre1.getText().equals(""))
{
//tre1.requestFocus();
}
else
{
int f=0;
String ss="Select * from register";

conestablish1 ci1=new conestablish1();


rs=ci1.selectconDb(ss);

try
{
while(rs.next())
{
if(tre1.getText().equals(rs.getString(1)))
f=1;
}
}
catch(Exception e2)
{

JOptionPane.showMessageDialog(null,e2.toString());
}

if(f==1)
{
String sr="Select * from issue";
conestablish1 ci=new conestablish1();
rs=ci.selectconDb(sr);

try
{
while(rs.next())
{

if(cre1.getSelectedItem().equals(rs.getString(2)))
{
d2=rs.getDate(4);
}
}
}
catch(Exception e2)
{

JOptionPane.showMessageDialog(null,"rs_next.........->"+e2.toString());
}

long days=(tim-d2.getTime())/(1000*60*60*24);
long fine=0;
if(days>0)
{
fine=days*1;
tre5.setText(Long.toString(fine));
}
else
tre5.setText("0");
}
}
}
}

public void focusLost(FocusEvent e)


{
if(e.getSource()==tre1)
{
if(tre1.getText().equals(""))
{

}
else
{
int f=0;
String ss="Select * from register";

conestablish1 ci=new conestablish1();


rs=ci.selectconDb(ss);

try
{
while(rs.next())
{
if(tre1.getText().equals(rs.getString(1)))
f=1;
}
}
catch(Exception e2)
{
JOptionPane.showMessageDialog(null,e2.toString());
}

if(f==0)
{
JOptionPane.showMessageDialog(null,"Incorrect Staff
ID");
tre1.setText("");
}

else
{

String sv="Select * from issue";

conestablish1 ci1=new conestablish1();


rs=ci1.selectconDb(sv);

try
{
while(rs.next())
{
if(rs.getString(1).equals(tre1.getText()))
cre1.addItem(rs.getString(2));
}

}
catch(Exception e2)
{

JOptionPane.showMessageDialog(null,"rs_next.........->"+e2.toString());
}
}
}
}

if(e.getSource()==trt1)
{
if(trt1.getText().equals(""))
{
//JOptionPane.showMessageDialog(null,"Enter Staff
ID");
}
else
{
int f=0;
String ss="Select * from register";

conestablish1 ci=new conestablish1();


rs=ci.selectconDb(ss);

try
{
while(rs.next())
{
if(trt1.getText().equals(rs.getString(1)))
f=1;
}
}
catch(Exception e2)
{
JOptionPane.showMessageDialog(null,e2.toString());
}

if(f==0)
{
JOptionPane.showMessageDialog(null,"Incorrect Staff
ID");
}
else
{

String sv="Select * from issue";


conestablish1 ci1=new conestablish1();
rs=ci1.selectconDb(sv);

try
{
while(rs.next())
{
if(rs.getString(1).equals(trt1.getText()))
crt1.addItem(rs.getString(2));
}
}
catch(Exception e2)
{

JOptionPane.showMessageDialog(null,"rs_next.........->"+e2.toString());
}
}
}
}
}

public static void main(String args[])


{

userform m=new userform("admin");


m.show();
m.setSize(1280,720);
m.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}

e) REPORT

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

public class report extends JFrame


{
JTable table;
JScrollPane jsp;
public report(ResultSet rs) throws SQLException
{

boolean moreRecords=rs.next();
if(!moreRecords)
{
JOptionPane.showMessageDialog(null,"Book Not Found.");

}
else
{
setVisible(true);
setSize(1280,720);

Vector col=new Vector();


Vector rows=new Vector();

try{
ResultSetMetaData rsmd=rs.getMetaData();
for(int i=1;i<=rsmd.getColumnCount();i++)
col.addElement(rsmd.getColumnName(i));

do{
rows.addElement(getNextRow(rs,rsmd));

}while(rs.next());

table=new JTable(rows,col);
jsp=new JScrollPane(table);
add(jsp);
}catch(SQLException e){}

private Vector getNextRow(ResultSet rs,ResultSetMetaData rsmd) throws


SQLException
{
Vector currentRow =new Vector();
for(int i=1;i<=rsmd.getColumnCount();++i)
{
currentRow.addElement(rs.getString(i));
}
return currentRow;
}
}

f) CONNECTION

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

class connection1
{
String url="jdbc:odbc:anilibrary";

Connection Con;
Statement stmt;
String username="",password="";

public connection1()
{

Statement FConnect()
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}

catch(Exception f)
{
JOptionPane.showMessageDialog(null,"class error.......");
}

try
{
Con=DriverManager.getConnection(url,username,password);
}

catch(Exception f1)
{
JOptionPane.showMessageDialog(null,"Connection error.......");
}
try
{

stmt=Con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultS
et.CONCUR_READ_ONLY);
}

catch(Exception e2)
{
JOptionPane.showMessageDialog(null,"Statement
error.......");
}

return stmt;
}

void Fdisconnect()
{

try
{
stmt.close();
Con.close();
}

catch(Exception e)
{
JOptionPane.showMessageDialog(null,"disconnect error......."
);
}
}
}

g) CONNECTION ESTABLISH

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

class conestablish1
{
Statement st;
connection1 con=new connection1();
ResultSet rs;
conestablish1()
{
st=con.FConnect();

public void insertIntoDb(String sql)


{
try
{
st.executeUpdate(sql);
//JOptionPane.showMessageDialog(null,"Insertion success.......");
con.Fdisconnect();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,"in insertion-
>"+e.toString());
}

public ResultSet selectconDb(String sql)


{
try
{
rs=st.executeQuery(sql);

}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,"in
selection............"+e.toString());
}
return(rs);

public void updateDb(String sql)


{
try
{
st.executeUpdate(sql);
//JOptionPane.showMessageDialog(null,"updation
success.......");
con.Fdisconnect();

}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,"in
updation............"+e.toString());
}
}

public void deleteconDb(String sql)


{
try
{
st.executeUpdate(sql);
//JOptionPane.showMessageDialog(null,"Deletion
success.......");
con.Fdisconnect();

}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,"in
deletion........"+e.toString());
}

}
}

Output :-
7. Creating Own Bean ( JAVA BEAN)

Program:-

a) Java Code

import java.awt.*;
import java.awt.event.*;

public class Color1 extends Canvas


{
private Color color;
private boolean rectangular;

public Color1()
{
addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent ae)
{
change();
}
});

rectangular=false;
setSize(400,400);
change();
}

public boolean getRectangular()


{
return rectangular;
}

public void setrectangular(boolean flag)


{
this.rectangular=flag;
repaint();
}

public void change()


{
color=randomColor();
repaint();
}

private Color randomColor()


{
int r=(int)(255*Math.random());
int g=(int)(255*Math.random());
int b=(int)(255*Math.random());
return new Color(r,g,b);
}

public void paint(Graphics g)


{
Dimension d=getSize();
int h=d.height;
int w=d.width;
g.setColor(color);

if(rectangular)
{
g.fillRect(0,0,w-1,h-1);
}
else
g.fillOval(0,0,w-1,h-1);
}
}

b) MFT Code

Name: Color1.java
Java-Bean: True
Output :-
8. GENERIC SERVLET

Program:-

a) HTML Code

<html>
<body>
<center>
<form name="Form1" method="Post"
action="http://localhost:8080/examples/servlet/employee">
<table>
<tr>
<td><b>Employee</td>
<td><input type=textbox name="EmployeeName" size"25">
</td>
</tr>

<tr>
<td><b>Phone No</td>
<td><input type=textbox name="Phone" size"25">
</td>
</tr>
</table>

<input type="submit" values="Submit">

</form>
</body>
</html>

b) JAVA Code

import java.io.*;
import java.util.*;
import javax.servlet.*;

public class employee extends GenericServlet


{
public void service(ServletRequest req,ServletResponse res)throws
ServletException,IOException
{
PrintWriter out=res.getWriter();
Enumeration e=req.getParameterNames();

while(e.hasMoreElements())
{
String pname=(String)e.nextElement();
out.println(pname+" = ");
String pvalue=req.getParameter(pname);
out.println(pvalue);
}
out.close();
}
}

Output :-
9. HTTP SERVLET

Program:-

a) HTML Code

<html>
<body>
<center>

<form name="Form1"
action="http://localhost:8080/examples/servlet/Colordemo">

<B>Color</B>

<select name="color" size="1">


<option value="Orange">Orange</option>
<option value="Rose">Rose</option>

</select>
<br><br>

<input type=submit value="submit">

</form>
</body>
</html>

b) JAVA Code

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class Colordemo extends HttpServlet


{
public void doGet(HttpServletRequest req,HttpServletResponse res)throws
ServletException,IOException
{
String cl=req.getParameter("color");
res.setContentType("text/html");
PrintWriter out=res.getWriter();
out.println("<B>The Selected Color is:");
out.println(cl);
out.close();
}
}

Output :-

You might also like