81
A Summer Training Project On Hospital Management Using Core Java and ACCESS Core Java BY SAURABH GUPTA Date of Submission: 10-08-2013 Under Guidence of Ms.Daya Mr.Nishesh NIIT, Model Town

Saurabh

Embed Size (px)

DESCRIPTION

java report

Citation preview

Page 1: Saurabh

A Summer Training Project

On

Hospital Management

Using Core Java and ACCESS

Core Java

BY

SAURABH GUPTA

Date of Submission: 10-08-2013

Under Guidence ofMs.Daya

Mr.NisheshNIIT, Model Town

ELECTRICITY BILL MANAGEMENT

Page 2: Saurabh

BATCH CODE:

START DATE: 23-06-2013

END DATE: 10-08-2013

NAME OF THE COORDINATOR: MS. DAYA

NAMES OF THE DEVELOPER: SAURABH GUPTA

DATE OF SUBMISSION: 10-08-2013

Page 3: Saurabh

THIS IS TO CERTIFY THAT THIS REPORT TITLED ELECTRICITY BILL

MANAGEMENT EMBODIES THE ORIGINAL WORK DONE BY

SAURABH GUPTA IN

FULFILLMENT OF THEIR COURSE REQUIRMENT AT NIIT .

COORDINATOR: MS.DAYA

Page 4: Saurabh

ACKNOWLEDGEMENT

WE PLACE ON RECORD OUR DEEP APPRECIATION AND GRATITUDE FOR

THE HELP AND COOPERATION RENDERED TO US BY NUMEROUS MEMBERS

OF FACULTY AND NUMEROUS FRIENDS FOR PLACING AT OUR DISPOSAL

VARIOUS MAGAZINES FOR THE COLLECTION OF STATISTICAL DATA

AND OTHER RELEVENT INFORMATION AND FOR RENDERING EVERY

POSSIBLE ASSISTANCE IN COMPLETING OUR PROJECT REPORT. BUT

FOR THEIR UNSTINTED COOPERATION AND SUPPORT, IT WOULD HAVE

NEVER BEEN POSSIBLE FOR US TO UNDERTAKE THIS TASK OF

EXPLORING AND ANALYZING THECOMMERCIAL ADS IN MAGAZINES AND

ACCOMPLISHING THE PROJECT SUCCESSFULLY.

WE ALSO OWE OUR GRATEFULNESS THANKS TO MS. DAYA,

MR. NISHESH WHO HELPED US IN VARIOUS WAYS TO

MAKE THIS STUDY A SUCCESS

Page 5: Saurabh

SYSTEM ANALYSIS

Scope

The scope of the project is the system on which the software is installed i.e. the Project is developed as a desktop application and it will work for a particular institute. But later on the Project can be modified to operate it online.

Features

Until recently, the common functions of a electricity bill management system are to support the maintenance of personal and study system are to support the maintenance of personal and study information related to:

Handling inquiries from prospective customer.

Enrolling new customer and editing option.

Maintaining records of reading and dates.

Maintaining bill records.

Generating bill.

Page 6: Saurabh

Overview

Electricity bill Management has following modules for its proper functioning:-

1.First module is manager which has right for change rate for various meter.

2. Second module is for employee, who can control customer deatils.

Each user will have a set of user ID and Password.

Characterstics of a proposed system

Page 7: Saurabh

User Friendly:The proposed system is a user friendly because the retrieval and storing of data is fast and data is maintained efficiently. Moreove the graphical user interface is provided in the proposed system, which provides user to deal with the system very easily.

Reports are easily generated:Reports can be easily generated in the proposed system so user can generate the report as per the requirement(monthly) or in the middle of the session. User can give the notice to the student, so that he/she become regular.

Very less paper work:The proposed system requires very less paper work. All the data is feted in the computer immediately and reports can be generated through computers. Moreover work become very easy because there is no need to keep the data on paper.

Computer operator control: Computer operator control will be there so no chance of errors. Moreover storing and retrieving of information is easy. So work can be done speedily and in time.

Configuration

Page 8: Saurabh

Hardware:PC compatible with Intel Dual CPU T2310, 1.46GHz,

790MHz, 896MB RAM

Operating System: Microsoft Windows 7.

Software:J2SDK 1.6.0

CLASSES USED IN PROJECTINTRO

Page 9: Saurabh

import java.sql.*;import java.lang.*;import javax.swing.*;import java.awt.*;import java.awt.event.*; class start implements ActionListener { Frame f; JButton lg,res,exi,enter; JLabel l1,l2,l3,l4; Font f1; start(){ enter =new JButton(new ImageIcon("hppy.jpg"));f= new Frame("PROJECT");l1=new JLabel(new ImageIcon("name.png"));l2=new JLabel(new ImageIcon("proj.png"));l3=new JLabel(new ImageIcon("logo.png"));l4=new JLabel(new ImageIcon("back.png"));f.add(l4);l4.setBounds(0,0,900,700);l3.setBounds(5,5,100,100);l4.add(l3); l4.addMouseListener(new MouseAdapter(){public void mouseClicked(MouseEvent e){ enter =new JButton(new ImageIcon("sad.jpg")); l4.add(enter); enter.setBounds(100,350,203,75); }});f1=new Font("Castellar",Font.BOLD,30);f.setLayout(null);l1.setBounds(350,450,500,250);l4.add(l1);l1.setFont(f1);l4.add(enter);enter.setBounds(100,350,200,75);l2.setBounds(0,50,900,250);l4.add(l2);l2.setFont(f1);enter.addActionListener(this);f.setSize(900,700);f.setResizable(false);f.setVisible(true);f.addWindowListener( new WindowAdapter()

Page 10: Saurabh

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

public void actionPerformed(ActionEvent e){ f.setVisible(false); login gtu=new login();}

public static void main(String s[]){ start l=new start();}

}

Page 11: Saurabh

MANAGER LOGIN

import java.sql.*;import java.lang.*;import javax.swing.*;import java.awt.*;import java.awt.event.*; class login implements ActionListener { Frame f; JButton lg,res,exi; JLabel l1,l2,l3; JLabel l4; JTextField t1; int type; JRadioButton em,man; JPasswordField t2; Font f1,f2; login(){ l4=new JLabel(new ImageIcon("backg.jpg"));f= new Frame("LOGIN");l1=new JLabel("USER ID");l2=new JLabel("PASSWORD");l3=new JLabel(new ImageIcon("logo.png"));t1=new JTextField("");t2=new JPasswordField("");lg=new JButton(new ImageIcon("log.png"));res=new JButton(new ImageIcon("res.png"));exi=new JButton(new ImageIcon("exi.png"));em=new JRadioButton("EMPLOYEE");man=new JRadioButton("MANAGER");

Page 12: Saurabh

ButtonGroup b=new ButtonGroup();b.add(em);b.add(man);l4.add(em);l4.add(man);em.setBounds(200,200,90,20);man.setBounds(400,200,90,20);em.addActionListener(this);man.addActionListener(this);f1=new Font("Castellar",Font.BOLD,30);f2=new Font("Algerian",Font.BOLD,15);f.setLayout(null);l4.setBounds(0,0,550,350);f.add(l4);l3.setBounds(2,10,100,100);l4.add(l3);l1.setBounds(100,100,150,20);l4.add(l1);l1.setForeground(new Color(180,24,31));l2.setForeground(new Color(180,24,31));l1.setFont(f1);l2.setBounds(100,150,300,20);l4.add(l2);l2.setFont(f1);t1.setBounds(350,100,150,20);l4.add(t1);t2.setBounds(350,150,150,20);l4.add(t2);lg.setBounds(200,250,90,30);l4.add(lg);lg.addActionListener(this);res.setBounds(400,250,90,30);l4.add(res);res.addActionListener(this);exi.setBounds(300,300,90,30);l4.add(exi);exi.addActionListener(this);//f.setBackground(new Color(222,250,2));f.setSize(550,350);f.setResizable(false);f.setVisible(true);f.addWindowListener( new WindowAdapter(){ public void windowClosing(WindowEvent s) { System.exit(0);}});}

Page 13: Saurabh

public void actionPerformed(ActionEvent e){ if(e.getSource()==em){ type =1;}else if(e.getSource()==man){type=2;}else if(e.getSource()==exi){ Object[] options = {"Yes", "No"}; int n=JOptionPane.showConfirmDialog( f, "ARE YOU SURE TO EXIT",null, JOptionPane.YES_NO_OPTION); if(n==0){System.exit(0);}}else if(e.getSource()==res){ t1.setText(""); t2.setText("");}else if(e.getSource()==lg){String s,s1;s=t1.getText();s1=t2.getText();if(s.length()==0||s1.length()==0){ JOptionPane.showMessageDialog(f, "USERID OR PASSWORD NOT ENTERED");}else{ if(type==1){try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");Connection c=DriverManager.getConnection("jdbc:odbc:fd");PreparedStatement st=c.prepareStatement("select userid ,password from login where userid=? and password=?");st.setString(1,t1.getText());st.setString(2,t2.getText());ResultSet rs=st.executeQuery();if(rs.next())

Page 14: Saurabh

{ mainframe m=new mainframe();f.setVisible(false);}elseJOptionPane.showMessageDialog(f, "incorrect id and password");}catch(SQLException p){ System.out.println("Exception"+p.getMessage());} catch(Exception p){ System.out.println("Exception"+p.getMessage());}} else if(type==2){try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");Connection c=DriverManager.getConnection("jdbc:odbc:fd");PreparedStatement st=c.prepareStatement("select userid ,password from manager where userid=? and password=?");st.setString(1,t1.getText());st.setString(2,t2.getText());ResultSet rs=st.executeQuery();if(rs.next()){ manager tf=new manager();f.setVisible(false);}elseJOptionPane.showMessageDialog(f, "incorrect id and password");}catch(SQLException p){ System.out.println("Exception"+p.getMessage());} catch(Exception p){ System.out.println("Exception"+p.getMessage());}}elseJOptionPane.showMessageDialog(f, "SELECT EITHER EMPLOYEE OR MANAGER");

}}}}

Page 15: Saurabh

EMPLOYEE LOGIN

import java.sql.*;import java.lang.*;import javax.swing.*;import java.awt.*;import java.awt.event.*; class login implements ActionListener { Frame f; JButton lg,res,exi; JLabel l1,l2,l3; JLabel l4; JTextField t1; int type; JRadioButton em,man; JPasswordField t2; Font f1,f2; login(){ l4=new JLabel(new ImageIcon("backg.jpg"));f= new Frame("LOGIN");l1=new JLabel("USER ID");l2=new JLabel("PASSWORD");

Page 16: Saurabh

l3=new JLabel(new ImageIcon("logo.png"));t1=new JTextField("");t2=new JPasswordField("");lg=new JButton(new ImageIcon("log.png"));res=new JButton(new ImageIcon("res.png"));exi=new JButton(new ImageIcon("exi.png"));em=new JRadioButton("EMPLOYEE");man=new JRadioButton("MANAGER");ButtonGroup b=new ButtonGroup();b.add(em);b.add(man);l4.add(em);l4.add(man);em.setBounds(200,200,90,20);man.setBounds(400,200,90,20);em.addActionListener(this);man.addActionListener(this);f1=new Font("Castellar",Font.BOLD,30);f2=new Font("Algerian",Font.BOLD,15);f.setLayout(null);l4.setBounds(0,0,550,350);f.add(l4);l3.setBounds(2,10,100,100);l4.add(l3);l1.setBounds(100,100,150,20);l4.add(l1);l1.setForeground(new Color(180,24,31));l2.setForeground(new Color(180,24,31));l1.setFont(f1);l2.setBounds(100,150,300,20);l4.add(l2);l2.setFont(f1);t1.setBounds(350,100,150,20);l4.add(t1);t2.setBounds(350,150,150,20);l4.add(t2);lg.setBounds(200,250,90,30);l4.add(lg);lg.addActionListener(this);res.setBounds(400,250,90,30);l4.add(res);res.addActionListener(this);exi.setBounds(300,300,90,30);l4.add(exi);exi.addActionListener(this);//f.setBackground(new Color(222,250,2));f.setSize(550,350);f.setResizable(false);

Page 17: Saurabh

f.setVisible(true);f.addWindowListener( new WindowAdapter(){ public void windowClosing(WindowEvent s) { System.exit(0);}});}

public void actionPerformed(ActionEvent e){ if(e.getSource()==em){ type =1;}else if(e.getSource()==man){type=2;}else if(e.getSource()==exi){ Object[] options = {"Yes", "No"}; int n=JOptionPane.showConfirmDialog( f, "ARE YOU SURE TO EXIT",null, JOptionPane.YES_NO_OPTION); if(n==0){System.exit(0);}}else if(e.getSource()==res){ t1.setText(""); t2.setText("");}else if(e.getSource()==lg){String s,s1;s=t1.getText();s1=t2.getText();if(s.length()==0||s1.length()==0){ JOptionPane.showMessageDialog(f, "USERID OR PASSWORD NOT ENTERED");}else{ if(type==1){try{

Page 18: Saurabh

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");Connection c=DriverManager.getConnection("jdbc:odbc:fd");PreparedStatement st=c.prepareStatement("select userid ,password from login where userid=? and password=?");st.setString(1,t1.getText());st.setString(2,t2.getText());ResultSet rs=st.executeQuery();if(rs.next()){ mainframe m=new mainframe();f.setVisible(false);}elseJOptionPane.showMessageDialog(f, "incorrect id and password");}catch(SQLException p){ System.out.println("Exception"+p.getMessage());} catch(Exception p){ System.out.println("Exception"+p.getMessage());}} else if(type==2){try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");Connection c=DriverManager.getConnection("jdbc:odbc:fd");PreparedStatement st=c.prepareStatement("select userid ,password from manager where userid=? and password=?");st.setString(1,t1.getText());st.setString(2,t2.getText());ResultSet rs=st.executeQuery();if(rs.next()){ manager tf=new manager();f.setVisible(false);}elseJOptionPane.showMessageDialog(f, "incorrect id and password");}catch(SQLException p){ System.out.println("Exception"+p.getMessage());} catch(Exception p){ System.out.println("Exception"+p.getMessage());}}elseJOptionPane.showMessageDialog(f, "SELECT EITHER EMPLOYEE OR MANAGER");

}}}}

Page 19: Saurabh

MANAGER

import java.sql.*;import java.lang.*;import javax.swing.*;import java.awt.*;import java.awt.event.*; class manager implements ActionListener { Frame f; JButton su,res,exi,b; JLabel l1,l2,l3,l5; JTextField t1; JComboBox t2; String sr; String sd[]={"COMMERCIAL","PRIVATE","AGRICULTURAL"}; Font f1; manager()

Page 20: Saurabh

{ l5=new JLabel(new ImageIcon("elect.jpg"));

f= new Frame("MANAGER");l1=new JLabel(new ImageIcon("logo.png"));l2=new JLabel("MODEL TYPE");t1=new JTextField("");f.add(l5);l5.setBounds(0,0,700,500); su=new JButton(new ImageIcon("sb.png"));res=new JButton(new ImageIcon("res.png"));exi=new JButton(new ImageIcon("exi.png"));b=new JButton(new ImageIcon("bck.png"));t2=new JComboBox(sd);l3=new JLabel("RATE/READING");f1=new Font("Castellar",Font.BOLD,18);f.setLayout(null);l1.setBounds(0,0,100,100);l5.add(l1);l2.setBounds(150,100,300,20);l5.add(l2);l5.add(l3);l5.add(t2);t2.setBounds(400,100,200,20);l3.setBounds(150,150,300,20);f.setBackground(new Color(100,234,231));l1.setFont(f1);l2.setFont(f1);l3.setFont(f1);t1.setBounds(400,150,200,20);l5.add(t1);su.setBounds(200,200,90,30);l5.add(su);su.setFont(f1);su.addActionListener(this);res.setBounds(400,200,90,30);l5.add(res);res.setFont(f1);res.addActionListener(this);exi.setBounds(400,250,90,30);l5.add(exi);exi.setFont(f1);exi.addActionListener(this);b.setBounds(200,250,90,30);l5.add(b);b.setFont(f1);b.addActionListener(this);f.setSize(700,500);f.setVisible(true);f.setResizable(false);

Page 21: Saurabh

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

public void actionPerformed(ActionEvent e){if(e.getSource()==t2) {JComboBox t2 = (JComboBox)e.getSource(); String sr = (String)t2.getSelectedItem(); }elseif(e.getSource()==b){ f.setVisible(false); login h=new login();} elseif(e.getSource()==exi){ Object[] options = {"Yes", "No"}; int n=JOptionPane.showConfirmDialog( f, "ARE YOU SURE TO EXIT",null, JOptionPane.YES_NO_OPTION); if(n==0){System.exit(0);}} else if(e.getSource()==res){ t1.setText("");}else if(e.getSource()==su){String s;s=t1.getText();if(s.length()==0){ JOptionPane.showMessageDialog(f, "RATE NOT ENTERED");}else

Page 22: Saurabh

{try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");Connection c=DriverManager.getConnection("jdbc:odbc:cust");PreparedStatement q=c.prepareStatement("select metertype from manager

where metertype=? "); String sr = (String)t2.getSelectedItem(); q.setString(1,sr); ResultSet res =q.executeQuery(); if(res.next()) {Double tg=Double.parseDouble(t1.getText()); PreparedStatement t=c.prepareStatement("update manager set rate=? where

metertype=? "); t.setDouble(1,tg); t.setString(2,sr); int rest=t.executeUpdate(); if(rest>0) { JOptionPane.showMessageDialog(f, "UPDATED"); } }else{JOptionPane.showMessageDialog(f, "WRONG NUMBER");}

}catch(SQLException p){System.out.println("Exception"+p.getMessage());} catch(Exception p){ String abc=p.getMessage(); String dfr[]=abc.split(":"); System.out.println(dfr); for(int i=0;i<2;i++) { abc =dfr[i];}JOptionPane.showMessageDialog(f, " THIS SHOULD BE A NUMBER"+abc);}}}}}}

Page 23: Saurabh

MAINFRAME

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

class mainframe implements ActionListener{ Frame f;JLabel l1,l2; JButton b1,b2,b3,b4,b5,b6; Font f1; mainframe(){ f=new Frame("MAIN MENU"); l2=new JLabel(new ImageIcon("electricity.jpg")); l1=new JLabel(new ImageIcon("logo.png"));

Page 24: Saurabh

f1=new Font("Castellar",Font.BOLD,12);f.add(l2);l2.setBounds(0,0,550,440);l2.add(l1);

f.addWindowListener( new WindowAdapter(){ public void windowClosing(WindowEvent s) { System.exit(0);}});l1.setBounds(5,10,100,100); b1=new JButton(new ImageIcon("cd.png"));l2.add(b1);b1.setBounds(100,100,200,43);b1.setFont(f1);b1.addActionListener(this);b2=new JButton(new ImageIcon("bg.png"));l2.add(b2);b2.setBounds(100,170,200,43);b2.setFont(f1);b2.addActionListener(this);b3=new JButton(new ImageIcon("ur.png"));l2.add(b3);b3.setBounds(100,240,200,43);b3.setFont(f1);b3.addActionListener(this);b5=new JButton(new ImageIcon("bck.png"));l2.add(b5);b5.setBounds(100,310,90,30);b5.setFont(f1);b5.addActionListener(this);b6=new JButton(new ImageIcon("exi.png"));l2.add(b6);b6.setBounds(210,310,90,30);b6.setFont(f1);b6.addActionListener(this);l2.setBackground(new Color(100,234,231));f.setLayout(null);l2.setForeground(Color.RED);f.setSize(500,440);f.setResizable(false);f.setVisible(true);}

public void actionPerformed(ActionEvent a){ if(a.getSource()==b6) { Object[] options = {"Yes", "No"};

Page 25: Saurabh

int n=JOptionPane.showConfirmDialog( f, "ARE YOU SURE TO EXIT",null, JOptionPane.YES_NO_OPTION); if(n==0){System.exit(0);}} else if(a.getSource()==b5) { f.setVisible(false);login l=new login(); } else if(a.getSource()==b3) { f.setVisible(false); updater f=new updater(); } else if(a.getSource()==b2) { f.setVisible(false); billg fd=new billg(); } else if(a.getSource()==b1){ f.setVisible(false); custom c=new custom(); }

}}

Page 26: Saurabh

CUSTOMER DETAILS

import java.sql.*;import java.lang.*;import javax.swing.*;import java.awt.*;import java.awt.event.*; class custom implements ActionListener { Frame f; JButton ac,dc,uc,s,exi,b; JLabel l1,l2; Font f1; custom()

Page 27: Saurabh

{ l2=new JLabel(new ImageIcon("electricity.jpg"));f= new Frame("CUSTOMER DETAILS");f1=new Font("Castellar",Font.BOLD,18);l1=new JLabel(new ImageIcon("logo.png"));f.add(l2);l2.setBounds(0,0,550,440);l2.add(l1);l1.setBounds(10,10,100,100); ac=new JButton(new ImageIcon("anc.png"));l2.add(ac);ac.setFont(f1);ac.setBounds(100,100,200,43); ac.addActionListener(this);dc=new JButton(new ImageIcon("dc.png"));l2.add(dc);dc.setFont(f1);dc.setBounds(100,160,200,43); dc.addActionListener(this);uc=new JButton(new ImageIcon("uc.png"));l2.add(uc);uc.setFont(f1);uc.setBounds(100,220,200,43); uc.addActionListener(this);s=new JButton(new ImageIcon("s.png"));l2.add(s);s.setFont(f1);s.setBounds(100,280,200,43); s.addActionListener(this);exi=new JButton(new ImageIcon("exi.png"));l2.add(exi);exi.setFont(f1);exi.setBounds(210,340,90,30); exi.addActionListener(this);b=new JButton(new ImageIcon("bck.png"));l2.add(b);b.setFont(f1);b.setBounds(100,340,90,30); b.addActionListener(this);f.addWindowListener( new WindowAdapter(){ public void windowClosing(WindowEvent s) { System.exit(0);}});f.setLayout(null);f.setBackground(new Color(100,234,231));f.setSize(550,440);f.setVisible(true);f.setResizable(false);}

Page 28: Saurabh

public void actionPerformed(ActionEvent e){if(e.getSource()==exi){ Object[] options = {"Yes", "No"}; int n=JOptionPane.showConfirmDialog( f, "ARE YOU SURE TO EXIT",null, JOptionPane.YES_NO_OPTION); if(n==0){System.exit(0);}} else if(e.getSource()==ac){f.setVisible(false); adcustom d=new adcustom();}else if(e.getSource()==dc){f.setVisible(false); delete f=new delete();

}else if(e.getSource()==uc){ f.setVisible(false);update f=new update(); }else if(e.getSource()==s){f.setVisible(false);search g=new search();}

else if(e.getSource()==b){ f.setVisible(false); mainframe m=new mainframe(); }}}

Page 29: Saurabh

ADDCUSTOMER

import java.util.Date.*;import java.sql.*;import java.lang.*;import javax.swing.*;import java.awt.*;import java.awt.event.*; class adcustom implements ActionListener { Frame f; JButton s,res,exi,lg,b; JLabel l1,l2,l3,l4,l5,l6,l7,l8,l9,l10,l11,l20; Scrollbar s1; JRadioButton ma,fe; String sex; String a,be,ce,d; String m[]={"COMMERCIAL","PRIVATE","AGRICULTURAL"}; String st[]={"Adarsh Nagar", "alipur","Anand Parbat","Anand Vihar","Ashok

Page 30: Saurabh

Vihar","Azadpur","AksharDham","Avantika","Badarpur","Badli","Burari","Barakhamba Road","Bhajanpura","Budh Nagar","Budh Vihar","Chanakya Puri","Chandni Chowk","Chhatarpur","Civil Lines","Connaught Place","Chawri

Bazar","Daryaganj","Defence Enclave","DhaulaKuan","Dilshad Garden","Dwarka","defence Colony","dwarka","friends colony","G T B Nagar","Geeta Colony","greater

Kailash","Green Park","Gujrawala Town","Gautam Nagar","Gazipur","Gol Market","Gulabi Bagh","Hauz Khas","Hazrat Nizamuddin","I T O","inderlok","Indraprastha Colony","Jahangir

Puri","janakpuri","Kalindi Colony","Kalindi Kunj","kalkaji","Kamla Nagar","Karol Bagh","Khan Market","Kirti Nagar","Karawal Nagar","Kashmiri Gate","Keshavpuram","Laxmi Nagar","Lajpat

nagar","Lawrence Road","Loni","Maharani Bagh","Malka Ganj","Malviya Nagar","Mandi House","Mangolpuri","Mayur Vihar","Mehrauli","Model Town","Moti Bagh","Moti

Nagar","Mukherjee Nagar","Mukundpur", "Mundka","Mayur Vihar","Najafgarh","Nangloi","Naraina","Narela","Pahar Ganj","Paschim Vihar","Patel Nagar","pitampura","Pragati

Maidan","Punjabi Bagh","pira Garhi","Pratap Vihar","Preet Vihar","R K Puram","Rajender Nagar","Rajouri Garden","Rohini","Rajendra Nagar", ",Rani Bagh","Rithala","Roop

Nagar","Sadar bazar","Safdarjung Enclave","Saket","Sarai Rohilla","Sarita Vihar","Sarojini Nagar","Shadipur","Shahdara","Shakti Nagar","Shalimar Bagh","Shastri Nagar","South

Extension Part 1","South Extension Part 2","Sultanpuri","Sant Nagar","Sarai Kale Khan","Savita Vihar","Shakarpur","Shastri Nagar","Shastri Park","Subhash Nagar","Sundar

Nagar","Timarpur","Tri Nagar","Tughlaqabad","Tagore Garden","Tis hazari","Uttam Nagar","Vaishali","Vasant Kunj","Vikas Puri","Vaishali","Wazirpur","Yamuna Vihar"}; JTextField t1,t2,t3,t4,t5,t7,t9; JComboBox t6,t8; Font f1; adcustom(){ l20=new JLabel(new ImageIcon("electsuper.jpg"));f= new Frame ("ADD CUSTOMER");f1=new Font("Castellar",Font.BOLD,18);s1=new Scrollbar(Scrollbar.VERTICAL,1,100,1,100);s1.setBackground(Color.RED);s1.setBounds(180,0,20,20);

Page 31: Saurabh

l1=new JLabel(new ImageIcon("logo.png"));f.add(l20);l20.setBounds(0,0,980,750);l20.add(l1);l1.setBounds(10,10,100,100); l2=new JLabel("C.NO");l20.add(l2);l2.setFont(f1);l2.setBounds(150,100,200,20); t1=new JTextField("");t1.setBounds(350,100,200,20);l20.add(t1);l3=new JLabel("NAME");l20.add(l3);l3.setFont(f1);l3.setBounds(150,150,200,20); t2=new JTextField("");t2.setBounds(350,150,200,20);l20.add(t2);l4=new JLabel("ADDRESS");l20.add(l4);l4.setFont(f1);l4.setBounds(150,200,200,20); t3=new JTextField("");t3.setBounds(350,200,200,50);l20.add(t3);l11=new JLabel("SEX");l11.setBounds(150,300,200,20);l20.add(l11);l11.setFont(f1);ma=new JRadioButton("MALE");l20.add(ma);ma.setBounds(350,300,100,20);fe=new JRadioButton("FEMALE");l20.add(fe);fe.setBounds(500,300,100,20);ButtonGroup bd=new ButtonGroup();bd.add(ma);ma.addActionListener(this);bd.add(fe);fe.addActionListener(this);l5=new JLabel("CONTACT NO.");l20.add(l5);l5.setFont(f1);l5.setBounds(150,350,200,20); t4=new JTextField("");t4.setBounds(350,350,200,20);l20.add(t4);l6=new JLabel("E MAIL");

Page 32: Saurabh

l20.add(l6);l6.setFont(f1);l6.setBounds(150,400,200,20); t5=new JTextField("");t5.setBounds(350,400,200,20);l20.add(t5);l7=new JLabel("METER TYPE");l20.add(l7);l7.setFont(f1);l7.setBounds(150,450,200,20); t6=new JComboBox(m);t6.setSelectedIndex(2);t6.addActionListener(this);t6.setBounds(350,450,200,20);l20.add(t6);l8=new JLabel("METER NO.");l20.add(l8);l8.setFont(f1);l8.setBounds(150,500,200,20); t7=new JTextField("");t7.setBounds(350,500,200,20);l20.add(t7);l9=new JLabel("CIRCLE/ZONE");l20.add(l9);l9.setFont(f1);l9.setBounds(150,550,200,20); t8=new JComboBox(st);t8.setSelectedIndex(4);t8.addActionListener(this);t8.setBounds(350,550,200,20);l20.add(t8);l10=new JLabel("LOAD");l20.add(l10);l10.setFont(f1);l10.setBounds(150,600,200,20); t9=new JTextField("");t9.setBounds(350,600,200,20);l20.add(t9);s=new JButton("SUBMIT");l20.add(s);s.setBounds(150,650,150,20);s.addActionListener(this);res=new JButton("RESET");l20.add(res);res.setBounds(400,650,150,20);res.addActionListener(this);exi=new JButton("EXIT");l20.add(exi);exi.setBounds(400,700,150,20);

Page 33: Saurabh

exi.addActionListener(this);lg=new JButton("LOGOUT");l20.add(lg);lg.setBounds(300,750,100,20);lg.addActionListener(this);b=new JButton("BACK");l20.add(b);b.setBounds(150,700,150,20);b.addActionListener(this);f.addWindowListener( new WindowAdapter(){ public void windowClosing(WindowEvent s) { System.exit(0);}});f.setLayout(null);f.setBackground(new Color(100,234,231));f.setSize(960,750);f.setVisible(true);f.setResizable(false);}

public void actionPerformed(ActionEvent e){ if(e.getSource()==ma) { sex="male"; }else if(e.getSource()==fe) {sex="female"; }elseif(e.getSource()==t6) {JComboBox t6 = (JComboBox)e.getSource(); String s5 = (String)t6.getSelectedItem(); }else if(e.getSource()==t8) {JComboBox t8 = (JComboBox)e.getSource(); String s7 = (String)t8.getSelectedItem();} else if(e.getSource()==lg){login h=new login(); f.setVisible(false);} else if(e.getSource()==b){custom r=new custom(); f.setVisible(false);} else if(e.getSource()==exi){ Object[] options = {"Yes", "No"};

Page 34: Saurabh

int n=JOptionPane.showConfirmDialog( f, "ARE YOU SURE TO EXIT",null, JOptionPane.YES_NO_OPTION); if(n==0){System.exit(0);}} else if(e.getSource()==res){ t1.setText(""); t2.setText(""); t3.setText(""); t4.setText(""); t5.setText(""); t7.setText(""); t9.setText("");}else if(e.getSource()==s){String s,s1,s2,s3,s4,s5,s6,s7,s8;s=t1.getText();s1=t2.getText();s2=t3.getText();s3=t4.getText();s4=t5.getText();s5=(String)t6.getSelectedItem();s6=t7.getText();s7=(String)t8.getSelectedItem();s8=t9.getText();if(s.length()==0||s1.length()==0||s2.length()==0||s3.length()==0||s4.length()==0||s6.length()==0||s8.length()==0){ JOptionPane.showMessageDialog(f, "SOME FIELD MISSING");

}else{try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");Connection c=DriverManager.getConnection("jdbc:odbc:cust");PreparedStatement q=c.prepareStatement("select cno from cus where cno=? ");q.setString(1,t1.getText());ResultSet res =q.executeQuery();if(res.next()) { JOptionPane.showMessageDialog(f, "ALREADY EXIST");}else{PreparedStatement st=c.prepareStatement("insert into cus values(?,?,?,?,?,?,?,?,?,?)");

Page 35: Saurabh

Long se=Long.parseLong(t1.getText());Long sp=Long.parseLong(t4.getText());Long sz=Long.parseLong(t7.getText());Long sd=Long.parseLong(t9.getText());a=""+se;st.setString(1,a);String sdc=t2.getText();if (!sdc.matches("^[a-z A-Z]+")){JOptionPane.showMessageDialog(f, "NAME SHOULD BE IN ALPHABETS");}else{st.setString(2,sdc);}st.setString(3,t3.getText());if(ma.isSelected()||fe.isSelected()){st.setString(4,sex);} else{JOptionPane.showMessageDialog(f, "EITHER SELECT MALE OR FEMALE");}be=""+sp;st.setString(5,be);String sdc1=t5.getText();if (!sdc1.matches("^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@"

+ "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$")){JOptionPane.showMessageDialog(f, "NOT A VALID E-MAIL ID");}else{st.setString(6,sdc1);}st.setString(7,s5);ce=""+sz;st.setString(8,ce);

st.setString(9,s7);

if((sd<=10)&&(sd>0)){d=""+sd;st.setString(10,d);}else{ JOptionPane.showMessageDialog(f, "IT CAN'T BE MORE THAN 10");}

int rs=st.executeUpdate();

Page 36: Saurabh

if(rs>0){ JOptionPane.showMessageDialog(f, " ENTERED");} }

}catch(SQLException p){System.out.println("Exception"+p.getMessage());} catch(Exception p){ String abc=p.getMessage(); String dfr[]=abc.split(":"); System.out.println(dfr); for(int i=0;i<2;i++) { abc =dfr[i];}JOptionPane.showMessageDialog(f, " THIS SHOULD BE IN NUMBERS"+abc);}

entry ase=new entry(a);}}} }

Page 37: Saurabh

DELETE CUSTOMER

import java.sql.*;import java.lang.*;import javax.swing.*;import java.awt.*;import java.awt.event.*; class delete implements ActionListener { Frame f; JButton del,res,exi,b; JLabel l1,l2,l10; JTextField t1; Font f1; delete(){ l10=new JLabel(new ImageIcon("elect.jpg"));f= new Frame("DELETE DATA");l1=new JLabel(new ImageIcon("logo.png"));l2=new JLabel("ENTER C.NO TO DELETE");t1=new JTextField("");f.add(l10);l10.setBounds(0,0,700,400);del=new JButton(new ImageIcon("sb.png"));res=new JButton(new ImageIcon("res.png"));exi=new JButton(new ImageIcon("exi.png"));b=new JButton(new ImageIcon("bck.png"));f1=new Font("Castellar",Font.BOLD,18);f.setLayout(null);l1.setBounds(5,10,100,100);l10.add(l1);l2.setBounds(150,100,600,20);l10.add(l2);f.setBackground(new Color(100,234,231));l1.setFont(f1);l2.setFont(f1);t1.setBounds(140,150,270,20);l10.add(t1);del.setBounds(140,200,90,30);l10.add(del);del.setFont(f1);del.addActionListener(this);res.setBounds(290,200,90,30);l10.add(res);res.setFont(f1);res.addActionListener(this);exi.setBounds(290,250,90,30);l10.add(exi);

Page 38: Saurabh

exi.setFont(f1);exi.addActionListener(this);b.setBounds(140,250,90,30);l10.add(b);b.setFont(f1);b.addActionListener(this);f.setSize(700,400);f.setResizable(false);f.setVisible(true);f.addWindowListener( new WindowAdapter(){ public void windowClosing(WindowEvent s) { System.exit(0);}});}

public void actionPerformed(ActionEvent e){if(e.getSource()==b){ f.setVisible(false); custom h=new custom();} elseif(e.getSource()==exi){ Object[] options = {"Yes", "No"}; int n=JOptionPane.showConfirmDialog( f, "ARE YOU SURE TO EXIT",null, JOptionPane.YES_NO_OPTION); if(n==0){System.exit(0);}} else if(e.getSource()==res){ t1.setText("");}else if(e.getSource()==del){String s;s=t1.getText();if(s.length()==0)

Page 39: Saurabh

{JOptionPane.showMessageDialog(f, "CUSTOMER NO. NOT ENTERED");}else{try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");Connection c=DriverManager.getConnection("jdbc:odbc:cust");PreparedStatement q=c.prepareStatement("select cno from cus where cno=? ");q.setString(1,t1.getText());ResultSet res =q.executeQuery(); if(res.next()) { PreparedStatement t=c.prepareStatement("delete from cus where cno=? "); t.setString(1,t1.getText()); int rest=t.executeUpdate(); if(rest>0) { JOptionPane.showMessageDialog(f, "DELETED"); } }else{JOptionPane.showMessageDialog(f, "NO SUCH CUSTOMER");}

}catch(SQLException p){System.out.println("Exception"+p.getMessage());} catch(Exception p){ System.out.println("Exception"+p.getMessage());}try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");Connection c=DriverManager.getConnection("jdbc:odbc:cust");PreparedStatement q=c.prepareStatement("select cno from reading where cno=? ");q.setString(1,t1.getText());ResultSet res =q.executeQuery(); if(res.next()) { PreparedStatement t=c.prepareStatement("delete from reading where cno=? "); t.setString(1,t1.getText()); t.executeUpdate();}}catch(SQLException p){System.out.println("Exception"+p.getMessage());} catch(Exception p){ System.out.println("Exception"+p.getMessage());}}}}}

Page 40: Saurabh

SEARCH

import java.sql.*;import java.lang.*;import javax.swing.*;import java.awt.*;import java.awt.event.*; class search implements ActionListener { Frame f; JButton se,res,exi,b,dis; JLabel l1,l2; JTextField t1; Font f1; JLabel l3 =new JLabel(new ImageIcon("electlrge.jpg")); search(){ f= new Frame("SEARCH DATA");l1=new JLabel(new ImageIcon("logo.png"));l2=new JLabel("ENTER C.NO TO SEARCH");t1=new JTextField("");se=new JButton(new ImageIcon("sb.png"));

Page 41: Saurabh

res=new JButton(new ImageIcon("res.png"));exi=new JButton(new ImageIcon("exi.png"));b=new JButton(new ImageIcon("bck.png"));dis=new JButton(new ImageIcon("disp.png"));f1=new Font("Castellar",Font.BOLD,18);f.setLayout(null);l3.setBounds(0,0,700,400);f.add(l3);l1.setBounds(5,10,100,100);l3.add(l1);l2.setBounds(150,100,600,20);l3.add(l2);f.setBackground(new Color(100,234,231));l1.setFont(f1);l2.setFont(f1);t1.setBounds(150,150,270,20);l3.add(t1);se.setBounds(150,200,90,30);l3.add(se);se.setFont(f1);se.addActionListener(this);res.setBounds(325,200,90,30);l3.add(res);res.setFont(f1);res.addActionListener(this);dis.setBounds(450,150,150,30);l3.add(dis);dis.setFont(f1);dis.addActionListener(this);exi.setBounds(325,250,90,30);l3.add(exi);exi.setFont(f1);exi.addActionListener(this);b.setBounds(150,250,90,30);l3.add(b);b.setFont(f1);b.addActionListener(this);f.setSize(700,400);f.setResizable(false);f.setVisible(true);f.addWindowListener( new WindowAdapter(){ public void windowClosing(WindowEvent s) { System.exit(0);}});}

Page 42: Saurabh

public void actionPerformed(ActionEvent e){if(e.getSource()==dis){ table disd=new table(); } elseif(e.getSource()==b){ f.setVisible(false); custom h=new custom();} elseif(e.getSource()==exi){ Object[] options = {"Yes", "No"}; int n=JOptionPane.showConfirmDialog( f, "ARE YOU SURE TO EXIT",null, JOptionPane.YES_NO_OPTION); if(n==0){System.exit(0);}} else if(e.getSource()==res){ t1.setText(""); f.setVisible(false); search t=new search();}else if(e.getSource()==se){String s;s=t1.getText();if(s.length()==0){ JOptionPane.showMessageDialog(f, "CUSTOMER NO.NOT ENTERED");}else{try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");Connection c=DriverManager.getConnection("jdbc:odbc:cust");PreparedStatement q=c.prepareStatement("select * from cus where cno=? ");q.setString(1,t1.getText());

Page 43: Saurabh

ResultSet res =q.executeQuery(); if(res.next()) { f.setSize(960,700);// l3= JLabel(new ImageIcon("electlrge.jpg"));f.add(l3);t1.setEditable(false); JLabel cn=new JLabel("C.NO : "+res.getString("cno")); l3.add(cn);l3.setBounds(0,0,960,700); cn.setBounds(150,300,400,50); cn.setFont(f1); JLabel na=new JLabel("NAME: "+res.getString("name")); l3.add(na); na.setBounds(150,340,400,50); na.setFont(f1); JLabel addr=new JLabel("ADDRESS : "+res.getString("add")); l3.add(addr); addr.setBounds(150,380,800,50); addr.setFont(f1); JLabel se=new JLabel("SEX : "+res.getString("sex")); l3.add(se); se.setBounds(150,420,400,50); se.setFont(f1); JLabel mo=new JLabel("CONTACT NO: "+res.getString("mobile")); l3.add(mo); mo.setBounds(150,460,600,50); mo.setFont(f1); JLabel ema=new JLabel("EMAIL : "+res.getString("email")); l3.add(ema); ema.setBounds(150,500,600,50); ema.setFont(f1); JLabel met=new JLabel("METER TYPE : "+res.getString("metertype")); l3.add(met); met.setBounds(150,540,400,50); met.setFont(f1); JLabel metn=new JLabel("METER NO. : "+res.getString("meterno")); l3.add(metn); metn.setBounds(150,580,400,50); metn.setFont(f1);JLabel crc=new JLabel("CIRCLE : "+res.getString("circle")); l3.add(crc); crc.setBounds(150,620,400,50); crc.setFont(f1);JLabel load=new JLabel("LOAD : "+res.getString("load")); l3.add(load); load.setBounds(150,660,400,50); load.setFont(f1); }

Page 44: Saurabh

else{JOptionPane.showMessageDialog(f, "NO SUCH CUSTOMER");}

}catch(SQLException p){System.out.println("Exception"+p.getMessage());} catch(Exception p){ System.out.println("Exception"+p.getMessage());}}}}}

Page 45: Saurabh

UPDATE

import java.sql.*;import java.lang.*;import javax.swing.*;import java.awt.*;import java.awt.event.*; class update implements ActionListener { Frame f; JButton s,res,b,u,res1; ScrollPane sq; JLabel l1,l2,n,ad,se,l5,l6,l7,l8,l9,l10,l20; Panel p1; JComboBox t6,t8; String sex; // Scrollbar s1; String m[]={"COMMERCIAL","PRIVATE","AGRICULTURAL"}; String st[]={"Adarsh Nagar", "alipur","Anand Parbat","Anand Vihar","Ashok Vihar","Azadpur","AksharDham","Avantika","Badarpur","Badli","Burari","Barakhamba Road","Bhajanpura","Budh Nagar","Budh Vihar","Chanakya Puri","Chandni Chowk","Chhatarpur","Civil Lines","Connaught Place","Chawri Bazar","Daryaganj","Defence Enclave","DhaulaKuan","Dilshad Garden","Dwarka","defence Colony","dwarka","friends colony","G T B Nagar","Geeta Colony","greater Kailash","Green Park","Gujrawala Town","Gautam Nagar","Gazipur","Gol Market","Gulabi Bagh","Hauz Khas","Hazrat Nizamuddin","I T O","inderlok","Indraprastha Colony","Jahangir Puri","janakpuri","Kalindi Colony","Kalindi Kunj","kalkaji","Kamla Nagar","Karol Bagh","Khan Market","Kirti Nagar","Karawal Nagar","Kashmiri Gate","Keshavpuram","Laxmi Nagar","Lajpat nagar","Lawrence Road","Loni","Maharani Bagh","Malka Ganj","Malviya Nagar","Mandi House","Mangolpuri","Mayur Vihar","Mehrauli","Model Town","Moti Bagh","Moti Nagar","Mukherjee Nagar","Mukundpur", "Mundka","Mayur Vihar","Najafgarh","Nangloi","Naraina","Narela","Pahar Ganj","Paschim Vihar","Patel Nagar","pitampura","Pragati Maidan","Punjabi Bagh","pira Garhi","Pratap Vihar","Preet Vihar","R K Puram","Rajender Nagar","Rajouri Garden","Rohini","Rajendra Nagar", ",Rani Bagh","Rithala","Roop Nagar","Sadar bazar","Safdarjung Enclave","Saket","Sarai Rohilla","Sarita Vihar","Sarojini Nagar","Shadipur","Shahdara","Shakti Nagar","Shalimar Bagh","Shastri Nagar","South Extension Part 1","South Extension Part 2","Sultanpuri","Sant Nagar","Sarai Kale Khan","Savita Vihar","Shakarpur","Shastri Nagar","Shastri Park","Subhash Nagar","Sundar Nagar","Timarpur","Tri Nagar","Tughlaqabad","Tagore Garden","Tis hazari","Uttam Nagar","Vaishali","Vasant Kunj","Vikas Puri","Vaishali","Wazirpur","Yamuna Vihar"}; JRadioButton ma,fe; JTextField t1,t3,t4,t5,t7,t9,t15; Font f1; update(){ l20 =new JLabel(new ImageIcon("electsuper.jpg"));f= new Frame("UPDATE DATA");l1=new JLabel(new ImageIcon("logo.png"));l2=new JLabel("ENTER C.NO TO UPDATE");t1=new JTextField("");

Page 46: Saurabh

sq= new ScrollPane();p1=new Panel();sq.setBounds(0,0,1000,900);s=new JButton(new ImageIcon("sb.png"));res=new JButton(new ImageIcon("res.png"));res1=new JButton(new ImageIcon("res.png"));u=new JButton(new ImageIcon("sb.png"));b=new JButton(new ImageIcon("bck.png"));f1=new Font("Castellar",Font.BOLD,18);p1.setLayout(null);sq.add(p1);p1.add(l20);l20.setBounds(0,0,1360,900);p1.setBounds(0,0,400,400);f.add(sq);l1.setBounds(10,10,100,100);l20.add(l1);l2.setBounds(150,100,600,20);l20.add(l2);f.setBackground(new Color(100,234,231));l1.setFont(f1);l2.setFont(f1);t1.setBounds(140,150,270,20);l20.add(t1);s.setBounds(140,200,90,30);res.setBounds(290,200,90,30);s.setFont(f1);l20.add(s);l20.add(res);res.setFont(f1);res.addActionListener(this);s.addActionListener(this);b.setBounds(220,250,90,30);l20.add(b);b.setFont(f1);b.addActionListener(this);f.setSize(700,440);f.setVisible(true);f.setResizable(false);f.addWindowListener( new WindowAdapter(){ public void windowClosing(WindowEvent s) { System.exit(0);}});}

Page 47: Saurabh

public void actionPerformed(ActionEvent e){if(e.getSource()==res1){ t3.setText("");t3.setText("");t4.setText("");t5.setText("");t7.setText("");t9.setText("");t15.setText("");

}else if(e.getSource()==b){ f.setVisible(false); custom p=new custom();

} else if(e.getSource()==res){ t1.setText(""); f.setVisible(false); update de=new update();}else if(e.getSource()==s){ String frs=t1.getText();if(frs.length()==0){JOptionPane.showMessageDialog(f, "CUSTOMER NO. NOT ENTERED");}else{try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");Connection c=DriverManager.getConnection("jdbc:odbc:cust");PreparedStatement q=c.prepareStatement("select cno from cus where cno=? ");q.setString(1,t1.getText());ResultSet res =q.executeQuery();if(res.next()){ t1.setEditable(false);

//sq.setBounds(0,0,700,1000); p1.setBounds(0,0,900,900);n=new JLabel("NAME");l20.add(n);n.setFont(f1);n.setBounds(150,350,200,20); t15=new JTextField("");t15.setBounds(350,350,200,20);

Page 48: Saurabh

l20.add(t15);ad=new JLabel("ADDRESS");l20.add(ad);ad.setFont(f1);ad.setBounds(150,400,200,20); t3=new JTextField("");t3.setBounds(350,400,200,50);l20.add(t3);se=new JLabel("SEX");se.setBounds(150,500,200,20);l20.add(se);se.setFont(f1);ma=new JRadioButton("MALE");l20.add(ma);ma.setBounds(350,500,100,20);fe=new JRadioButton("FEMALE");l20.add(fe);fe.setBounds(500,500,100,20);ButtonGroup bd=new ButtonGroup();bd.add(ma);ma.addActionListener(this);bd.add(fe);fe.addActionListener(this);l5=new JLabel("CONTACT NO.");l20.add(l5);l5.setFont(f1);l5.setBounds(150,550,200,20); t4=new JTextField("");t4.setBounds(350,550,200,20);l20.add(t4);l6=new JLabel("E MAIL");l20.add(l6);l6.setFont(f1);l6.setBounds(150,600,200,20); t5=new JTextField("");t5.setBounds(350,600,200,20);l20.add(t5);l7=new JLabel("METER TYPE");l20.add(l7);l7.setFont(f1);l7.setBounds(150,650,200,20); t6=new JComboBox(m);t6.setSelectedIndex(2);t6.addActionListener(this);t6.setBounds(350,650,200,20);l20.add(t6);l8=new JLabel("METER NO.");l20.add(l8);l8.setFont(f1);

Page 49: Saurabh

l8.setBounds(150,700,200,20); t7=new JTextField("");t7.setBounds(350,700,200,20);l20.add(t7);l9=new JLabel("CIRCLE/ZONE");l20.add(l9);l9.setFont(f1);l9.setBounds(150,750,200,20); t8=new JComboBox(st);t8.setSelectedIndex(4);t8.addActionListener(this);t8.setBounds(350,750,200,20);l20.add(t8);l10=new JLabel("LOAD");l20.add(l10);l10.setFont(f1);l10.setBounds(150,800,200,20); t9=new JTextField("");t9.setBounds(350,800,200,20);l20.add(t9);

PreparedStatement cd=c.prepareStatement("select * from cus ");cd.executeQuery();t15.setText("hdfhfg");l20.add(u);l20.add(res1);res1.setBounds(300,850,90,30);u.setBounds(150,850,90,30);u.addActionListener(this);res1.addActionListener(this);f.setSize(680,580); f.setResizable(true); }else{JOptionPane.showMessageDialog(f, "NO SUCH USER");}}catch(SQLException p){ System.out.println("Exception"+p.getMessage());} catch(Exception p){ System.out.println("Exception"+p.getMessage());}try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");Connection c=DriverManager.getConnection("jdbc:odbc:cust");PreparedStatement swt=c.prepareStatement("select * from cus where cno=?");swt.setString(1,t1.getText());ResultSet res=swt.executeQuery();if(res.next()){ t15.setText(res.getString("name"));t3.setText(res.getString("add"));

Page 50: Saurabh

String se=res.getString("sex"); if(se.equals("male")){ma.setSelected(true);}else if(se.equals("female")){ fe.setSelected(true);}t4.setText(res.getString("mobile"));t6.setSelectedItem(res.getString("metertype"));t5.setText(res.getString("email"));t7.setText(res.getString("meterno"));t8.setSelectedItem(res.getString("circle"));t9.setText(res.getString("load"));

}}catch(SQLException t){ System.out.println("Exception"+t.getMessage());} catch(Exception t){ System.out.println("Exception"+t.getMessage());}}}else if(e.getSource()==ma) { sex="male"; }else if(e.getSource()==fe) {sex="female"; }elseif(e.getSource()==t6) {JComboBox t6 = (JComboBox)e.getSource(); String s5 = (String)t6.getSelectedItem(); }else if(e.getSource()==t8) {JComboBox t8 = (JComboBox)e.getSource(); String s7 = (String)t8.getSelectedItem();} else if(e.getSource()==u){ String s1,s2,s3,s4,s5,s6,s7,s8;s1=t15.getText();s2=t3.getText();s3=t4.getText();s4=t5.getText();

Page 51: Saurabh

s5=(String)t6.getSelectedItem();s6=t7.getText();s7=(String)t8.getSelectedItem();s8=t9.getText();if(s1.length()==0||s2.length()==0||s3.length()==0||s4.length()==0||s6.length()==0||s8.length()==0){ JOptionPane.showMessageDialog(f, "SOME FIELD IS NOT ENTERED");

}else{try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");Connection d=DriverManager.getConnection("jdbc:odbc:cust");PreparedStatement qw=d.prepareStatement("select cno from cus where cno=? ");qw.setString(1,t1.getText());ResultSet res =qw.executeQuery();if(res.next()) { PreparedStatement st=d.prepareStatement("update cus set name=?, add=?, sex=?, mobile=?, email=?, metertype=?,meterno=?, circle=?, load =? where cno=?");int sp=Integer.parseInt(t4.getText());int sz=Integer.parseInt(t7.getText());int sd=Integer.parseInt(t9.getText());int se=Integer.parseInt(t1.getText());st.setString(1,t15.getText());st.setString(2,t3.getText());st.setString(3,sex);st.setInt(4,sp);st.setString(5,t5.getText());st.setString(6,s5);st.setInt(7,sz);st.setString(8,s7);st.setInt(9,sd);st.setInt(10,se);int rs=st.executeUpdate();if(rs>0){JOptionPane.showMessageDialog(f, "UPDATED");} }

}catch(SQLException p){ System.out.println("Exception"+p.getMessage());} catch(Exception p){ System.out.println("Exception"+p.getMessage());}}}}}

Page 52: Saurabh
Page 53: Saurabh

UPDATEREADING

import java.sql.*;import java.text.*;import java.lang.*;import javax.swing.*;import java.awt.*;import java.awt.event.*; class updater implements ActionListener { Frame f; JButton s,res,b,su,res1,cal1,cal2; JLabel l1,l2,l3,l4,l5,l6,l10; JLabel bc; String as,abcd,pdc; int acd,asw; JTextField t1,t2,t3,t4,t5; Font f1; updater(){ l10=new JLabel(new ImageIcon("elect.jpg"));f= new Frame("UPDATE READING");f.add(l10);l10.setBounds(0,0,700,550);l1=new JLabel(new ImageIcon("logo.png"));l2=new JLabel("ENTER C.NO TO UPDATE");t1=new JTextField("");bc=new JLabel("");s=new JButton(new ImageIcon("sb.png"));res=new JButton(new ImageIcon("res.png"));res1=new JButton(new ImageIcon("res.png"));su=new JButton(new ImageIcon("sb.png"));b=new JButton(new ImageIcon("bck.png"));f1=new Font("Castellar",Font.BOLD,18);f.setLayout(null);l1.setBounds(10,10,100,100);l10.add(l1);l10.add(bc);bc.setBounds(0,0,600,300);l2.setBounds(150,50,600,20);l10.add(l2);f.setBackground(new Color(100,234,231));l1.setFont(f1);l2.setFont(f1);t1.setBounds(140,100,270,20);l10.add(t1);s.setBounds(140,150,90,30);res.setBounds(300,150,90,30);s.setFont(f1);l10.add(s);

Page 54: Saurabh

l10.add(res);res.setFont(f1);res.addActionListener(this);s.addActionListener(this);b.setBounds(220,200,90,30);l10.add(b);b.setFont(f1); b.addActionListener(this);f.setSize(600,300);f.setVisible(true);f.setResizable(false);f.addWindowListener( new WindowAdapter(){ public void windowClosing(WindowEvent s) { System.exit(0);}});}

public void actionPerformed(ActionEvent e){if(e.getSource()==b){f.setVisible(false); mainframe d= new mainframe();} else if(e.getSource()==res){ t1.setText(""); f.setVisible(false); updater tr=new updater();}else if(e.getSource()==s){ String s; s=t1.getText(); if(s.length()==0) { JOptionPane.showMessageDialog(f, "CUSTOMER NO. NOT ENTERED"); } else { try {Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");Connection c=DriverManager.getConnection("jdbc:odbc:cust"); PreparedStatement q=c.prepareStatement("select * from reading where cno=? "); q.setString(1,t1.getText());

Page 55: Saurabh

ResultSet res =q.executeQuery(); if(res.next()){ t1.setEditable(false);l3=new JLabel("PREVIOUS DATE");l4=new JLabel("PREVIOUS READING");l5=new JLabel("CURRENT DATE");l6=new JLabel("CURRENT READING");cal1=new JButton("calender");cal2=new JButton("calender"); as=res.getString("prevdate"); asw=res.getInt("prevread"); abcd=res.getString("currdate"); acd=res.getInt("currread"); pdc=""+acd;t2=new JTextField(pdc);t3=new JTextField("");t4=new JTextField(abcd);t5=new JTextField("");l10.add(l3);l10.add(l4);l10.add(l5);l10.add(l6);l10.add(t2);l10.add(t3);l10.add(su);f1=new Font("Castellar",Font.BOLD,18);f.setLayout(null);l3.setBounds(100,250,300,20);l4.setBounds(100,290,300,20);l5.setBounds(100,330,300,20);l6.setBounds(100,370,300,20);l10.add(l2);l6.setFont(f1);l3.setFont(f1);l4.setFont(f1);l5.setFont(f1);t2.setBounds(350,290,150,20);t3.setBounds(350,370,150,20);t4.setBounds(350,250,150,20);l10.add(t4);t5.setBounds(350,330,150,20);l10.add(t5);su.setBounds(150,440,90,30);su.setFont(f1);su.addActionListener(this);res1.setBounds(380,440,90,30);l10.add(res1);res1.setFont(f1);res1.addActionListener(this);

Page 56: Saurabh

l10.add(cal1);cal1.setFont(f1);cal1.addActionListener(this);cal1.setBounds(510,250,20,20);l10.add(cal2);cal2.setFont(f1);cal2.addActionListener(this);cal2.setBounds(510,330,20,20);f.setSize(700,550);

}else JOptionPane.showMessageDialog(f, "NO SUCH CUSTOMER");}catch(SQLException p){System.out.println("Exception"+p.getMessage());} catch(Exception p){ System.out.println("Exception"+p.getMessage());}}}else if(e.getSource()==su){String s,s1,s2,s3,s4; s=t1.getText(); s1=t2.getText(); s2=t3.getText(); s3=t4.getText(); s4=t5.getText(); if(s1.length()==0||s2.length()==0||s3.length()==0||s4.length()==0) { JOptionPane.showMessageDialog(f, "SOME FIELD IS NOT ENTERED"); } else { try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection c=DriverManager.getConnection("jdbc:odbc:cust"); PreparedStatement q=c.prepareStatement("select cno from reading where cno=? "); q.setString(1,t1.getText()); ResultSet res =q.executeQuery(); if(res.next()){ int se=Integer.parseInt(t2.getText()); int ps=Integer.parseInt(t3.getText()); int dep=ps-se;if(dep<=0){ JOptionPane.showMessageDialog(f, "CURRENT READING SHOULD BE GREATER THAN PREVIOUS ONE");} SimpleDateFormat Format = new SimpleDateFormat( "dd-M-yyyy" ); java.util.Date dn=new java.util.Date() ;

Page 57: Saurabh

System.out.println(dn); dn = Format.parse(s3);System.out.println(dn);int abc=0;java.util.Date dn1=new java.util.Date() ;System.out.println(dn1); dn1 = Format.parse(s4);System.out.println(dn1);if(dn.compareTo(dn1)>0){abc=7;JOptionPane.showMessageDialog(f,"PREVIOUS DATE CAN,T BE AFTER CURRENT DATE"); }else{abc=0;}if(dep>=0&&abc!=7){PreparedStatement tc=c.prepareStatement("update reading set prevdate=?,prevread=?,currdate=?,currread=? where cno=? "); tc.setString(1,s3); tc.setInt(2,se); tc.setString(3,s4); tc.setInt(4,ps); tc.setString(5,s); int p=tc.executeUpdate(); if(p>0){JOptionPane.showMessageDialog(f, "UPDATED");}}else{ }}}catch(SQLException p){System.out.println("Exception"+p.getMessage());} catch(Exception p){ System.out.println("Exception"+p.getMessage());}}}elseif(e.getSource()==res1){ t2.setText(""); t4.setText(""); t5.setText(""); t3.setText(""); }elseif(e.getSource()==cal1){ DatePicker dp = new DatePicker(f); t4.setText(dp.setPickedDate()); }elseif(e.getSource()==cal2){ DatePicker dp = new DatePicker(f); t5.setText(dp.setPickedDate());

Page 58: Saurabh

}}}

BILLGENERATE

import java.sql.*;import java.lang.*;import javax.swing.*;import java.awt.*;import java.awt.event.*; class billg implements ActionListener { Frame f; JButton del,res,exi,b; JLabel l1,l2,l3;

Page 59: Saurabh

JTextField t1; Font f1; billg(){ l3=new JLabel(new ImageIcon("elect.jpg"));f= new Frame("GENERATE BILL");l1=new JLabel(new ImageIcon("logo.png"));l2=new JLabel("ENTER C.NO TO GENERATE BILL");t1=new JTextField("");f.add(l3);l3.setBounds(0,0,700,400);del=new JButton(new ImageIcon("sb.png"));res=new JButton(new ImageIcon("res.png"));exi=new JButton(new ImageIcon("exi.png"));b=new JButton(new ImageIcon("bck.png"));f1=new Font("Castellar",Font.BOLD,18);f.setLayout(null);l1.setBounds(5,10,100,100);l3.add(l1);l2.setBounds(250,100,600,20);l3.add(l2);f.setBackground(new Color(100,234,231));l1.setFont(f1);l2.setFont(f1);t1.setBounds(240,150,270,20);l3.add(t1);del.setBounds(240,200,90,30);l3.add(del);del.setFont(f1);del.addActionListener(this);res.setBounds(390,200,90,30);l3.add(res);res.setFont(f1);res.addActionListener(this);exi.setBounds(390,250,90,30);l3.add(exi);exi.setFont(f1);exi.addActionListener(this);b.setBounds(240,250,90,30);l3.add(b);b.setFont(f1);b.addActionListener(this);f.setSize(700,400);f.setResizable(false);f.setVisible(true);f.addWindowListener( new WindowAdapter(){ public void windowClosing(WindowEvent s) { System.exit(0);

Page 60: Saurabh

}});}

public void actionPerformed(ActionEvent e){if(e.getSource()==b){ f.setVisible(false); mainframe h=new mainframe();} elseif(e.getSource()==exi){ Object[] options = {"Yes", "No"}; int n=JOptionPane.showConfirmDialog( f, "ARE YOU SURE TO EXIT",null, JOptionPane.YES_NO_OPTION); if(n==0){System.exit(0);}} else if(e.getSource()==res){ t1.setText("");}else if(e.getSource()==del){String s;s=t1.getText();if(s.length()==0){JOptionPane.showMessageDialog(f, "CUSTOMER NO. NOT ENTERED");}else{try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");Connection c=DriverManager.getConnection("jdbc:odbc:cust");PreparedStatement q=c.prepareStatement("select cno from cus where cno=? ");q.setString(1,t1.getText());ResultSet res =q.executeQuery(); if(res.next()) { String we=t1.getText();f.setVisible(false);

Page 61: Saurabh

bill g=new bill(we); }else{JOptionPane.showMessageDialog(f, "NO SUCH CUSTOMER");}

}catch(SQLException p){System.out.println("Exception"+p.getMessage());} catch(Exception p){ System.out.println("Exception"+p.getMessage());}}}}}

BILL

import java.util.*;import java.text.*;import java.sql.*;import java.lang.*;import javax.swing.*;import javax.swing.table.*;import java.awt.*;import java.awt.event.*; class bill implements ActionListener

Page 62: Saurabh

{ int mn,cr,pr,read; float rater; JButton print; String sde=null; String cds=null; String de=null; Frame f; String pd,cd,s9; ScrollPane sq; Panel p1; JLabel l1,l2,l3,l4,l5,l6,l7,l8,l9,l10,l11,l12,l13; Font f1,f2;bill(String p){ print=new JButton("PRINT");f= new Frame("BILL");l1=new JLabel(new ImageIcon("logo.png"));l2=new JLabel("ELECTRICITY BILL");l3=new JLabel(" C.NO : " +p);l9=new JLabel("BILLING DETAILS:");sq= new ScrollPane();p1=new Panel();sq.setBounds(0,0,600,400);f1=new Font("Castellar",Font.BOLD,15);f2=new Font("Kristen ITC",Font.BOLD,30);l2.setFont(f2);p1.add(l2);l2.setBounds(260,25,500,30);p1.setLayout(null);sq.add(p1);p1.add(print);print.setBounds(760,30,90,30);print.addActionListener(this);p1.setBounds(0,0,500,200);f.add(sq);p1.add(l9);l9.setFont(f1);l9.setBounds(0,300,200,200);try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");Connection c=DriverManager.getConnection("jdbc:odbc:cust");PreparedStatement st=c.prepareStatement("select * from cus where cno=?");st.setString(1,p);ResultSet rs=st.executeQuery();if(rs.next()){l4= new JLabel("SANCTIONED LOAD : " +rs.getString("load"));p1.add(l4);l4.setBounds(400,70,300,100);l4.setFont(f1);

Page 63: Saurabh

l5= new JLabel("NAME : " +rs.getString("name"));p1.add(l5);l5.setBounds(100,110,300,100);l5.setFont(f1);s9=rs.getString("metertype");l6= new JLabel("METER TYPE : " +s9);p1.add(l6);l6.setBounds(400,110,400,100);l6.setFont(f1);l7= new JLabel("ADDRESS : " +rs.getString("add"));p1.add(l7);l7.setBounds(100,150,700,100);l7.setFont(f1);mn=rs.getInt("meterno");}}catch(SQLException t){ System.out.println("Exception"+t.getMessage());} catch(Exception t){ System.out.println("Exception"+t.getMessage());}try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");Connection c=DriverManager.getConnection("jdbc:odbc:cust");PreparedStatement swt=c.prepareStatement("select * from reading where cno=?");swt.setString(1,p);ResultSet res=swt.executeQuery();if(res.next()){pd=res.getString("prevdate");de=res.getString("currdate");cr=res.getInt("currread");pr=res.getInt("prevread");l8= new JLabel("BILLINNG MONTH: " +pd+"/"+de);p1.add(l8);l8.setBounds(100,190,500,100);l8.setFont(f1);

read=(cr-pr);}}catch(SQLException t){ System.out.println("Exception"+t.getMessage());} catch(Exception t){ System.out.println("Exception"+t.getMessage());}

try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");Connection c=DriverManager.getConnection("jdbc:odbc:cust");PreparedStatement st=c.prepareStatement("select * from manager where metertype =?");st.setString(1,s9);ResultSet rs=st.executeQuery();

Page 64: Saurabh

if(rs.next()){ rater=rs.getFloat("rate"); // System.out.println(rater);}}catch(SQLException t){ System.out.println("Exception"+t.getMessage());} catch(Exception t){ System.out.println("Exception"+t.getMessage());}

Vector columnName = new Vector();Vector dat = new Vector();

long am;am=(long)(45+(read*rater));columnName.addElement("FIXED CHARGE(in Rs)");columnName.addElement("UNIT");columnName.addElement("RATE/UNIT(in Rs)");columnName.addElement("AMOUNT(in Rs)");

Vector row1 = new Vector(4);row1.addElement("45");row1.addElement(read);row1.addElement(rater);row1.addElement(am);dat.addElement( row1 );

JTable table1 = new JTable(dat, columnName);TableColumn cole;for (int i = 0; i < table1.getColumnCount(); i++) {cole = table1.getColumnModel().getColumn(i);cole.setMaxWidth(250);} Color per=new Color(100,234,231);table1.setRowHeight(table1.getRowCount() - 1, 39);table1.setBackground(per);JScrollPane p3=new JScrollPane(table1);p1.add(p3);p3.setBounds(0,430,890,58);

{Vector columnNames = new Vector();Vector data = new Vector();

columnNames.addElement("METER NUMBER");columnNames.addElement("PREVIOUS DATE");columnNames.addElement("READING");columnNames.addElement("CURRENT DATE");

Page 65: Saurabh

columnNames.addElement("READING");columnNames.addElement("UNIT");

Vector row = new Vector(6);row.addElement(mn);row.addElement(pd);row.addElement(pr);row.addElement(de);row.addElement(cr);row.addElement(read);data.addElement( row );

JTable table = new JTable(data, columnNames);TableColumn col;for (int i = 0; i < table.getColumnCount(); i++) {col = table.getColumnModel().getColumn(i);col.setMaxWidth(250);//col.setMaxHeight(250);//setRowHeight(row,250);}table.setBackground(per);

table.setRowHeight(table.getRowCount() - 1, 39);

JScrollPane p2=new JScrollPane(table);//p2.setLayout(null);p1.add(p2);p2.setBounds(0,300,890,58);}l10=new JLabel("DUE DATE:");l11=new JLabel("AMOUNT PAYABLE:");l12=new JLabel(""+am);p1.add(l12);l12.setBounds(550,550,200,30);l12.setFont(f2);p1.add(l10);l10.setBounds(70,480,200,100);l10.setFont(f1);p1.add(l11);l11.setBounds(550,520,200,20);l11.setFont(f1);l1.setBounds(5,5,100,100);p1.add(l1);p1.add(l3);l3.setBounds(100,70,200,100);l3.setFont(f1);f.setBackground(new Color(100,234,231));f.setSize(900,700);

Page 66: Saurabh

f.setVisible(true);f.setResizable(false);f.addWindowListener( new WindowAdapter(){ public void windowClosing(WindowEvent s) { System.exit(0);}});

try{SimpleDateFormat Format = new SimpleDateFormat( "dd-M-yyyy" );java.util.Date dn=new java.util.Date() ;System.out.println(dn); dn = Format.parse(de);System.out.println(dn);String dsee=change(dn,1);System.out.println(dsee);String ase[];String ac=null;String fd=null;ase=dsee.split(" ");for (int i=0;i<3;i++){ ac=ase[1];fd=ase[2];}System.out.println(ac+""+fd);l13=new JLabel(""+ac+" "+fd);p1.add(l13);l13.setBounds(70,530,200,50);l13.setFont(f2); } catch(ParseException c){System.out.println(c.getMessage());}

}public String change(java.util.Date d, int month) { int fr=d.getMonth(); int fde=fr+month; d.setMonth(fde); String sdqw=d.toString(); return sdqw; } public void actionPerformed(ActionEvent e){ }}

Page 67: Saurabh

TABLE

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

public class table { table() {Vector columnNames = new Vector();Vector data = new Vector();JPanel p=new JPanel();try {Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");Connection con = DriverManager.getConnection("jdbc:odbc:cust");

Page 68: Saurabh

String sql = "Select * from cus";Statement stmt = con.createStatement();ResultSet rs = stmt.executeQuery( sql );ResultSetMetaData md = rs.getMetaData();int columns = md.getColumnCount();for (int i = 1; i <= columns; i++) {columnNames.addElement( md.getColumnName(i) );}while(rs.next()) {Vector row = new Vector(columns);for (int i = 1; i <= columns; i++){row.addElement( rs.getObject(i) );}data.addElement( row );}rs.close();stmt.close();}catch(Exception e){System.out.println(e);}JTable table = new JTable(data, columnNames);TableColumn col;for (int i = 0; i < table.getColumnCount(); i++) {col = table.getColumnModel().getColumn(i);col.setMinWidth(150);}JScrollPane scrollPane = new JScrollPane( table ,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);//p.setSize(400,600);scrollPane.setBounds(0,50,1365,200);//p.add( scrollPane );JLabel l2=new JLabel(new ImageIcon("electsuper.jpg"));table.setBackground(new Color(230,230,0));

JFrame f=new JFrame();f.setLayout(null);f.add(l2);l2.setBounds(0,0,1370,730);l2.add(scrollPane);scrollPane.getViewport().setBackground(new Color(200,200,0));f.setSize(1370,500); f.setVisible(true);//f.setResizable(false);}}

Page 69: Saurabh

CALENDER

import java.awt.*;import java.awt.event.*;import javax.swing.*;import java.util.*;public class calender { int month = java.util.Calendar.getInstance().get(java.util.Calendar.MONTH); int year = java.util.Calendar.getInstance().get(java.util.Calendar.YEAR);; JLabel l = new JLabel("", JLabel.CENTER); String day = ""; JDialog d; JButton[] button = new JButton[49]; public calender() { Panel parent=new Panel(); d = new JDialog(); d.setModal(true); String[] header = { "Sun", "Mon", "Tue", "Wed", "Thur", "Fri", "Sat" }; JPanel p1 = new JPanel(new GridLayout(7, 7)); p1.setPreferredSize(new Dimension(600, 200)); for (int x = 0; x < button.length; x++) { final int selection = x; button[x] = new JButton(); button[x].setFocusPainted(false); button[x].setBackground(Color.white); if (x > 6) button[x].addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { day = button[selection].getActionCommand();

Page 70: Saurabh

} }); if (x < 7) { button[x].setText(header[x]); button[x].setForeground(Color.blue); } p1.add(button[x]); } JPanel p2 = new JPanel(new GridLayout(1, 3)); JButton previous = new JButton("<< Previous Year"); previous.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { year--; displayDate(); } }); p2.add(previous); p2.add(l); JButton next = new JButton("Next Year>>"); next.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { year++; displayDate(); } });

p2.add(next); JPanel p3 = new JPanel(new GridLayout()); JButton previous1 = new JButton("<< Previous Month"); previous1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { month--; displayDate(); } }); p3.add(previous1); p3.add(l); JButton next1 = new JButton("Next Month>>"); next1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { month++; displayDate(); } }); p3.add(next1); d.add(p1, BorderLayout.CENTER); d.add(p2, BorderLayout.SOUTH); d.add(p3, BorderLayout.NORTH); d.pack(); d.setLocationRelativeTo(parent); displayDate(); d.setVisible(true); } public void displayDate() { for (int x = 7; x < button.length; x++) button[x].setText(""); java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat( "MMMM yyyy"); java.util.Calendar cal = java.util.Calendar.getInstance(); cal.set(year, month, 1);

Page 71: Saurabh

int dayOfWeek = cal.get(java.util.Calendar.DAY_OF_WEEK); int daysInMonth = cal.getActualMaximum(java.util.Calendar.DAY_OF_MONTH); for (int x = 6 + dayOfWeek, day = 1; day <= daysInMonth; x++, day++) button[x].setText("" + day); l.setText(sdf.format(cal.getTime())); d.setTitle("CALENDER"); }}

Page 72: Saurabh