ELECTRICITY BILLING SYSTEM
Create a electricity biilling system using JAVA
#knowledge #stream #blog
you can find the full source code for the project below.
A - Below is the source code of the project.
B - Create separate class files for every class.
C - Copy the code of one class (ex: login.java) and paste it in Login class file, do it for every class.
1 - Create your first class with name 'conn' and paste the code
package Electricity;
import java.sql.*;
//knowledgestreams.blogspot.com
public class conn{
Connection c;
Statement s;
public conn(){
try{
Class.forName("com.mysql.jdbc.Driver");
c =DriverManager.getConnection("jdbc:mysql:///project","root","");
s =c.createStatement();
}catch(Exception e){
System.out.println(e);
}
}
}
//knowledgestreams.blogspot.com
//knowledgestreams.blogspot.com
2 - Create next class with name 'Splash' and paste the code below in it. This is also our Main Frame of the project.
package Electricity;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class splash {
public static void main(String[] args){
fframe f1 = new fframe();
f1.setVisible(true);
int i;
int x=1;
for(i=2; i<=600; i+=4, x+=1){
f1.setLocation(800 - ((i+x)/2), 500 - (i/2));
f1.setSize(i+x,i);
try{
Thread.sleep(10);
}catch(Exception e){}
}
}
}
class fframe extends JFrame implements Runnable{
Thread t1;
fframe(){
super("Electricity Billing System");
setLayout(new FlowLayout());
ImageIcon c1 = new ImageIcon(ClassLoader.getSystemResource("icon/elect.jpg"));
Image i1 = c1.getImage().getScaledInstance(730, 550,Image.SCALE_DEFAULT);
ImageIcon i2 = new ImageIcon(i1);
JLabel l1 = new JLabel(i2);
add(l1);
t1 = new Thread(this);
t1.start();
}
public void run(){
try{
Thread.sleep(7000);
this.setVisible(false);
Login l = new Login();
l.setVisible(true);
}catch(Exception e){
e.printStackTrace();
}
}
}
//knowledgestreams.blogspot.com https://knowledgestreams.blogspot.com/
//knowledgestreams.blogspot.com https://knowledgestreams.blogspot.com/
3 - Create next class with name 'Login'.
package Electricity;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
public class Login extends JFrame implements ActionListener{
JLabel l1,l2,l3;
JTextField tf1;
JPasswordField pf2;
JButton b1,b2;
JPanel p1,p2,p3,p4;
Login(){
super("Login Page");
l1 = new JLabel("Username");
l2 = new JLabel("Password");
tf1 = new JTextField(15);
pf2 = new JPasswordField(15);
ImageIcon ic1 = new ImageIcon(ClassLoader.getSystemResource("icon/login.png"));
Image i1 = ic1.getImage().getScaledInstance(16, 16,Image.SCALE_DEFAULT);
b1 = new JButton("Login", new ImageIcon(i1));
ImageIcon ic2 = new ImageIcon(ClassLoader.getSystemResource("icon/cancel.jpg"));
Image i2 = ic2.getImage().getScaledInstance(16, 16,Image.SCALE_DEFAULT);
b2 = new JButton("Cancel",new ImageIcon(i2));
b1.addActionListener(this);
b2.addActionListener(this);
ImageIcon ic3 = new ImageIcon(ClassLoader.getSystemResource("icon/pop.png"));
Image i3 = ic3.getImage().getScaledInstance(128, 128,Image.SCALE_DEFAULT);
ImageIcon icc3 = new ImageIcon(i3);
l3 = new JLabel(icc3);
setLayout(new BorderLayout());
p1 = new JPanel();
p2 = new JPanel();
p3 = new JPanel();
p4 = new JPanel();
knowledgestreams.blogspot.com
add(l3,BorderLayout.WEST);
p2.add(l1);
p2.add(tf1);
p2.add(l2);
p2.add(pf2);
add(p2,BorderLayout.CENTER);
p4.add(b1);
p4.add(b2);
add(p4,BorderLayout.SOUTH);
p2.setBackground(Color.WHITE);
p4.setBackground(Color.WHITE);
setSize(440,250);
setLocation(600,400);
setVisible(true);
//knowledgestreams.blogspot.com
}
public void actionPerformed(ActionEvent ae){
try{
conn c1 = new conn();
String a = tf1.getText();
String b = pf2.getText();
String q = "select * from login where username = '"+a+"' and password = '"+b+"'";
ResultSet rs = c1.s.executeQuery(q);
if(rs.next()){
new Project().setVisible(true);
this.setVisible(false);
}else{
JOptionPane.showMessageDialog(null, "Invalid login");
setVisible(false);
}
}catch(Exception e){
e.printStackTrace();
System.out.println("error: "+e);
}
}
public static void main(String[] args){
new Login().setVisible(true);
}
}
//knowledgestreams.blogspot.com
4 - Create next class with name 'Project' and paste the code inside the class.
package Electricity;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Project extends JFrame implements ActionListener{
Project(){
super("Electricity Billing System");
setSize(1920,1030);
/* Adding background image */
ImageIcon ic = new ImageIcon(ClassLoader.getSystemResource("icon/elect1.jpg"));
Image i3 = ic.getImage().getScaledInstance(1900, 950,Image.SCALE_DEFAULT);
ImageIcon icc3 = new ImageIcon(i3);
JLabel l1 = new JLabel(icc3);
add(l1);
/* First Column */
JMenuBar mb = new JMenuBar();
JMenu master = new JMenu("Master");
JMenuItem m1 = new JMenuItem("New Customer");
JMenuItem m2 = new JMenuItem("Customer Details");
JMenuItem m3 = new JMenuItem("Deposit Details");
master.setForeground(Color.BLUE);
/* ---- Customer Details ---- */
m1.setFont(new Font("monospaced",Font.PLAIN,12));
ImageIcon icon1 = new ImageIcon(ClassLoader.getSystemResource("icon/icon1.png"));
Image image1 = icon1.getImage().getScaledInstance(20, 20,Image.SCALE_DEFAULT);
m1.setIcon(new ImageIcon(image1));
m1.setMnemonic('D');
m1.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_D, ActionEvent.CTRL_MASK));
m1.setBackground(Color.WHITE);
/* ---- Meter Details ---- */
m2.setFont(new Font("monospaced",Font.PLAIN,12));
ImageIcon icon2 = new ImageIcon(ClassLoader.getSystemResource("icon/icon2.png"));
Image image2 = icon2.getImage().getScaledInstance(20, 20,Image.SCALE_DEFAULT);
m2.setIcon(new ImageIcon(image2));
m2.setMnemonic('M');
m2.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_M, ActionEvent.CTRL_MASK));
m2.setBackground(Color.WHITE);
/* ---- Deposit Details ----- */
m3.setFont(new Font("monospaced",Font.PLAIN,12));
ImageIcon icon3 = new ImageIcon(ClassLoader.getSystemResource("icon/icon3.png"));
Image image3 = icon3.getImage().getScaledInstance(20, 20,Image.SCALE_DEFAULT);
m3.setIcon(new ImageIcon(image3));
m3.setMnemonic('N');
m3.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.CTRL_MASK));
m3.setBackground(Color.WHITE);
m1.addActionListener(this);
m2.addActionListener(this);
m3.addActionListener(this);
// --------------------------------------------------------------------------------------------
//knowledgestreams.blogspot.com
/* Second Column */ JMenu user = new JMenu("User"); JMenuItem u1 = new JMenuItem("Pay Bill"); JMenuItem u2 = new JMenuItem("Calculate Bill"); JMenuItem u3 = new JMenuItem("Last Bill"); user.setForeground(Color.RED); /* ---- Pay Bill ---- */ u1.setFont(new Font("monospaced",Font.PLAIN,12)); ImageIcon icon4 = new ImageIcon(ClassLoader.getSystemResource("icon/icon4.png")); Image image4 = icon4.getImage().getScaledInstance(20, 20,Image.SCALE_DEFAULT); u1.setIcon(new ImageIcon(image4)); u1.setMnemonic('P'); u1.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, ActionEvent.CTRL_MASK)); u1.setBackground(Color.WHITE); /* ---- Bill Details ---- */ u2.setFont(new Font("monospaced",Font.PLAIN,12)); ImageIcon icon5 = new ImageIcon(ClassLoader.getSystemResource("icon/icon5.png")); Image image5 = icon5.getImage().getScaledInstance(20, 20,Image.SCALE_DEFAULT); u2.setIcon(new ImageIcon(image5)); u2.setMnemonic('B'); u2.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_B, ActionEvent.CTRL_MASK)); u2.setBackground(Color.WHITE); /* ---- Last Bill ----*/ u3.setFont(new Font("monospaced",Font.PLAIN,12)); ImageIcon icon6 = new ImageIcon(ClassLoader.getSystemResource("icon/icon6.png")); Image image6 = icon6.getImage().getScaledInstance(20, 20,Image.SCALE_DEFAULT); u3.setIcon(new ImageIcon(image6)); u3.setMnemonic('L'); u3.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_L, ActionEvent.CTRL_MASK)); u3.setBackground(Color.WHITE); u1.addActionListener(this); u2.addActionListener(this); u3.addActionListener(this); // --------------------------------------------------------------------------------------------- /* Third Column*/ JMenu report = new JMenu("Report"); JMenuItem r1 = new JMenuItem("Generate Bill"); report.setForeground(Color.BLUE); /* ---- Report ---- */ r1.setFont(new Font("monospaced",Font.PLAIN,12)); ImageIcon icon7 = new ImageIcon(ClassLoader.getSystemResource("icon/icon7.png")); Image image7 = icon7.getImage().getScaledInstance(20, 20,Image.SCALE_DEFAULT); r1.setIcon(new ImageIcon(image7)); r1.setMnemonic('R'); r1.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, ActionEvent.CTRL_MASK)); r1.setBackground(Color.WHITE); r1.addActionListener(this); // ----------------------------------------------------------------------------------------------- /* Fourth Column*/ JMenu utility = new JMenu("Utility"); JMenuItem ut1 = new JMenuItem("Notepad"); JMenuItem ut2 = new JMenuItem("Calculator"); JMenuItem ut3 = new JMenuItem("Web Browser"); utility.setForeground(Color.RED); /* ---- Calender ---- */ ut1.setFont(new Font("monospaced",Font.PLAIN,12)); ImageIcon icon8 = new ImageIcon(ClassLoader.getSystemResource("icon/icon12.png")); Image image8 = icon8.getImage().getScaledInstance(20, 20,Image.SCALE_DEFAULT); ut1.setIcon(new ImageIcon(image8)); ut1.setMnemonic('C'); ut1.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.CTRL_MASK)); ut1.setBackground(Color.WHITE); /* ---- Calculator ---- */ ut2.setFont(new Font("monospaced",Font.PLAIN,12)); ImageIcon icon9 = new ImageIcon(ClassLoader.getSystemResource("icon/icon9.png")); Image image9 = icon9.getImage().getScaledInstance(20, 20,Image.SCALE_DEFAULT); ut2.setIcon(new ImageIcon(image9)); ut2.setMnemonic('X'); ut2.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, ActionEvent.CTRL_MASK)); ut2.setBackground(Color.WHITE); /* ---- Web Browser ---- */ ut3.setFont(new Font("monospaced",Font.PLAIN,12)); ImageIcon icon10 = new ImageIcon(ClassLoader.getSystemResource("icon/icon10.png")); Image image10 = icon10.getImage().getScaledInstance(20, 20,Image.SCALE_DEFAULT); ut3.setIcon(new ImageIcon(image10)); ut3.setMnemonic('W'); ut3.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_W, ActionEvent.CTRL_MASK)); ut3.setBackground(Color.WHITE); ut1.addActionListener(this); ut2.addActionListener(this); ut3.addActionListener(this); // --------------------------------------------------------------------------------------- /*Fifth Column */ JMenu exit = new JMenu("Exit"); JMenuItem ex = new JMenuItem("Exit"); exit.setForeground(Color.BLUE); /* ---- Exit ---- */ ex.setFont(new Font("monospaced",Font.PLAIN,12)); ImageIcon icon11 = new ImageIcon(ClassLoader.getSystemResource("icon/icon11.png")); Image image11 = icon11.getImage().getScaledInstance(20, 20,Image.SCALE_DEFAULT); ex.setIcon(new ImageIcon(image11)); ex.setMnemonic('Z'); ex.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Z, ActionEvent.CTRL_MASK)); ex.setBackground(Color.WHITE); ex.addActionListener(this); // --------------------------------------------------------------------------------------------- master.add(m1); master.add(m2); master.add(m3); user.add(u1); user.add(u2); user.add(u3); report.add(r1); utility.add(ut1); utility.add(ut2); utility.add(ut3); exit.add(ex); mb.add(master); mb.add(user); mb.add(report); mb.add(utility); mb.add(exit); setJMenuBar(mb); setFont(new Font("Senserif",Font.BOLD,16)); setLayout(new FlowLayout()); setVisible(false); } public void actionPerformed(ActionEvent ae){ String msg = ae.getActionCommand(); if(msg.equals("Customer Details")){ new customer_details().setVisible(true); }else if(msg.equals("New Customer")){ new new_customer().setVisible(true); }else if(msg.equals("Calculate Bill")){ new calculate_bill().setVisible(true); }else if(msg.equals("Pay Bill")){ new pay_bill().setVisible(true); }else if(msg.equals("Notepad")){ try{ Runtime.getRuntime().exec("notepad.exe"); }catch(Exception e){ } }else if(msg.equals("Calculator")){ try{ Runtime.getRuntime().exec("calc.exe"); }catch(Exception e){ } }else if(msg.equals("Web Browser")){ try{ Runtime.getRuntime().exec("C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe"); }catch(Exception e){ } }else if(msg.equals("Exit")){ System.exit(0); }else if(msg.equals("Generate Bill")){ new generate_bill().setVisible(true); } } public static void main(String[] args){ new Project().setVisible(true); } }
/* Second Column */ JMenu user = new JMenu("User"); JMenuItem u1 = new JMenuItem("Pay Bill"); JMenuItem u2 = new JMenuItem("Calculate Bill"); JMenuItem u3 = new JMenuItem("Last Bill"); user.setForeground(Color.RED); /* ---- Pay Bill ---- */ u1.setFont(new Font("monospaced",Font.PLAIN,12)); ImageIcon icon4 = new ImageIcon(ClassLoader.getSystemResource("icon/icon4.png")); Image image4 = icon4.getImage().getScaledInstance(20, 20,Image.SCALE_DEFAULT); u1.setIcon(new ImageIcon(image4)); u1.setMnemonic('P'); u1.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, ActionEvent.CTRL_MASK)); u1.setBackground(Color.WHITE); /* ---- Bill Details ---- */ u2.setFont(new Font("monospaced",Font.PLAIN,12)); ImageIcon icon5 = new ImageIcon(ClassLoader.getSystemResource("icon/icon5.png")); Image image5 = icon5.getImage().getScaledInstance(20, 20,Image.SCALE_DEFAULT); u2.setIcon(new ImageIcon(image5)); u2.setMnemonic('B'); u2.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_B, ActionEvent.CTRL_MASK)); u2.setBackground(Color.WHITE); /* ---- Last Bill ----*/ u3.setFont(new Font("monospaced",Font.PLAIN,12)); ImageIcon icon6 = new ImageIcon(ClassLoader.getSystemResource("icon/icon6.png")); Image image6 = icon6.getImage().getScaledInstance(20, 20,Image.SCALE_DEFAULT); u3.setIcon(new ImageIcon(image6)); u3.setMnemonic('L'); u3.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_L, ActionEvent.CTRL_MASK)); u3.setBackground(Color.WHITE); u1.addActionListener(this); u2.addActionListener(this); u3.addActionListener(this); // --------------------------------------------------------------------------------------------- /* Third Column*/ JMenu report = new JMenu("Report"); JMenuItem r1 = new JMenuItem("Generate Bill"); report.setForeground(Color.BLUE); /* ---- Report ---- */ r1.setFont(new Font("monospaced",Font.PLAIN,12)); ImageIcon icon7 = new ImageIcon(ClassLoader.getSystemResource("icon/icon7.png")); Image image7 = icon7.getImage().getScaledInstance(20, 20,Image.SCALE_DEFAULT); r1.setIcon(new ImageIcon(image7)); r1.setMnemonic('R'); r1.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, ActionEvent.CTRL_MASK)); r1.setBackground(Color.WHITE); r1.addActionListener(this); // ----------------------------------------------------------------------------------------------- /* Fourth Column*/ JMenu utility = new JMenu("Utility"); JMenuItem ut1 = new JMenuItem("Notepad"); JMenuItem ut2 = new JMenuItem("Calculator"); JMenuItem ut3 = new JMenuItem("Web Browser"); utility.setForeground(Color.RED); /* ---- Calender ---- */ ut1.setFont(new Font("monospaced",Font.PLAIN,12)); ImageIcon icon8 = new ImageIcon(ClassLoader.getSystemResource("icon/icon12.png")); Image image8 = icon8.getImage().getScaledInstance(20, 20,Image.SCALE_DEFAULT); ut1.setIcon(new ImageIcon(image8)); ut1.setMnemonic('C'); ut1.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.CTRL_MASK)); ut1.setBackground(Color.WHITE); /* ---- Calculator ---- */ ut2.setFont(new Font("monospaced",Font.PLAIN,12)); ImageIcon icon9 = new ImageIcon(ClassLoader.getSystemResource("icon/icon9.png")); Image image9 = icon9.getImage().getScaledInstance(20, 20,Image.SCALE_DEFAULT); ut2.setIcon(new ImageIcon(image9)); ut2.setMnemonic('X'); ut2.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, ActionEvent.CTRL_MASK)); ut2.setBackground(Color.WHITE); /* ---- Web Browser ---- */ ut3.setFont(new Font("monospaced",Font.PLAIN,12)); ImageIcon icon10 = new ImageIcon(ClassLoader.getSystemResource("icon/icon10.png")); Image image10 = icon10.getImage().getScaledInstance(20, 20,Image.SCALE_DEFAULT); ut3.setIcon(new ImageIcon(image10)); ut3.setMnemonic('W'); ut3.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_W, ActionEvent.CTRL_MASK)); ut3.setBackground(Color.WHITE); ut1.addActionListener(this); ut2.addActionListener(this); ut3.addActionListener(this); // --------------------------------------------------------------------------------------- /*Fifth Column */ JMenu exit = new JMenu("Exit"); JMenuItem ex = new JMenuItem("Exit"); exit.setForeground(Color.BLUE); /* ---- Exit ---- */ ex.setFont(new Font("monospaced",Font.PLAIN,12)); ImageIcon icon11 = new ImageIcon(ClassLoader.getSystemResource("icon/icon11.png")); Image image11 = icon11.getImage().getScaledInstance(20, 20,Image.SCALE_DEFAULT); ex.setIcon(new ImageIcon(image11)); ex.setMnemonic('Z'); ex.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Z, ActionEvent.CTRL_MASK)); ex.setBackground(Color.WHITE); ex.addActionListener(this); // --------------------------------------------------------------------------------------------- master.add(m1); master.add(m2); master.add(m3); user.add(u1); user.add(u2); user.add(u3); report.add(r1); utility.add(ut1); utility.add(ut2); utility.add(ut3); exit.add(ex); mb.add(master); mb.add(user); mb.add(report); mb.add(utility); mb.add(exit); setJMenuBar(mb); setFont(new Font("Senserif",Font.BOLD,16)); setLayout(new FlowLayout()); setVisible(false); } public void actionPerformed(ActionEvent ae){ String msg = ae.getActionCommand(); if(msg.equals("Customer Details")){ new customer_details().setVisible(true); }else if(msg.equals("New Customer")){ new new_customer().setVisible(true); }else if(msg.equals("Calculate Bill")){ new calculate_bill().setVisible(true); }else if(msg.equals("Pay Bill")){ new pay_bill().setVisible(true); }else if(msg.equals("Notepad")){ try{ Runtime.getRuntime().exec("notepad.exe"); }catch(Exception e){ } }else if(msg.equals("Calculator")){ try{ Runtime.getRuntime().exec("calc.exe"); }catch(Exception e){ } }else if(msg.equals("Web Browser")){ try{ Runtime.getRuntime().exec("C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe"); }catch(Exception e){ } }else if(msg.equals("Exit")){ System.exit(0); }else if(msg.equals("Generate Bill")){ new generate_bill().setVisible(true); } } public static void main(String[] args){ new Project().setVisible(true); } }
knowledge streams blog spot com
5 - Create next class with name 'new_customer'.
package Electricity;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
public class new_customer extends JFrame implements ActionListener{
JLabel l1,l2,l3,l4,l5,l6,l7,l8;
JTextField t1,t2,t3,t4,t5,t6,t7;
JButton b1,b2;
new_customer(){
setLocation(350,200);
setSize(650,600);
JPanel p = new JPanel();
p.setLayout(new GridLayout(9,2,10,10));
p.setBackground(Color.WHITE);
l1 = new JLabel("Name");
t1 = new JTextField();
p.add(l1);
p.add(t1);
l2 = new JLabel("Meter No");
t2 = new JTextField();
p.add(l2);
p.add(t2);
l3 = new JLabel("Address");
t3 = new JTextField();
p.add(l3);
p.add(t3);
l4 = new JLabel("State");
t4 = new JTextField();
p.add(l4);
p.add(t4);
l5 = new JLabel("City");
t5 = new JTextField();
p.add(l5);
p.add(t5);
l6 = new JLabel("Email");
t6 = new JTextField();
p.add(l6);
p.add(t6);
l7 = new JLabel("Phone Number");
t7 = new JTextField();
p.add(l7);
p.add(t7);
b1 = new JButton("Submit");
b2 = new JButton("Cancel");
b1.setBackground(Color.BLACK);
b1.setForeground(Color.WHITE);
b2.setBackground(Color.BLACK);
b2.setForeground(Color.WHITE);
p.add(b1);
p.add(b2);
setLayout(new BorderLayout());
add(p,"Center");
ImageIcon ic1 = new ImageIcon(ClassLoader.getSystemResource("icon/hicon1.jpg"));
Image i3 = ic1.getImage().getScaledInstance(150, 300,Image.SCALE_DEFAULT);
ImageIcon ic2 = new ImageIcon(i3);
l8 = new JLabel(ic2);
add(l8,"West");
//for changing the color of the whole
getContentPane().setBackground(Color.WHITE);
b1.addActionListener(this);
b2.addActionListener(this);
}
public void actionPerformed(ActionEvent ae){
String a = t1.getText();
String c = t2.getText();
String d = t3.getText();
String e = t4.getText();
String f = t5.getText();
String g = t6.getText();
String h = t7.getText();
String q1 = "insert into emp values('"+a+"','"+c+"','"+d+"','"+e+"','"+f+"','"+g+"','"+h+"')";
try{
conn c1 = new conn();
c1.s.executeUpdate(q1);
JOptionPane.showMessageDialog(null,"Employee Created");
this.setVisible(false);
}catch(Exception ex){
ex.printStackTrace();
}
}
public static void main(String[] args){
new new_customer().setVisible(true);
}
}
6 - Create next class with name 'customer_details'.
#knowledgestreams.blogspot.com
//knowledge streams blog spot
//knowledge streams blog spot
package Electricity;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
public class customer_details extends JFrame implements ActionListener{
JTable t1;
JButton b1;
String x[] = {"Emp Name","Meter No","Address","State","City","Email","Phone"};
String y[][] = new String[20][8];
int i=0, j=0;
customer_details(){
super("Customer Details");
setSize(1200,650);
setLocation(200,200);
try{
conn c1 = new conn();
String s1 = "select * from emp";
ResultSet rs = c1.s.executeQuery(s1);
while(rs.next()){
y[i][j++]=rs.getString("name");
y[i][j++]=rs.getString("meter_number");
y[i][j++]=rs.getString("address");
y[i][j++]=rs.getString("state");
y[i][j++]=rs.getString("city");
y[i][j++]=rs.getString("email");
y[i][j++]=rs.getString("phone");
i++;
j=0;
}
t1 = new JTable(y,x);
}catch(Exception e){
e.printStackTrace();
}
b1 = new JButton("Print");
add(b1,"South");
JScrollPane sp = new JScrollPane(t1);
add(sp);
b1.addActionListener(this);
}
public void actionPerformed(ActionEvent ae){
try{
t1.print();
}catch(Exception e){}
}
public static void main(String[] args){
new customer_details().setVisible(true);
}
}
7 - Create next class with name 'calculate_bill'.
package Electricity;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
public class calculate_bill extends JFrame implements ActionListener{
JLabel l1,l2,l3,l4,l5;
JTextField t1;
Choice c1,c2;
JButton b1,b2;
JPanel p;
calculate_bill(){
p = new JPanel();
p.setLayout(new GridLayout(4,2,30,30));
p.setBackground(Color.WHITE);
l1 = new JLabel("Calculate Electricity Bill");
l2 = new JLabel("Meter No");
l3 = new JLabel("Units Cosumed");
l5 = new JLabel("Month");
t1 = new JTextField();
c1 = new Choice();
c1.add("1001");
c1.add("1002");
c1.add("1003");
c1.add("1004");
c1.add("1005");
c1.add("1006");
c1.add("1007");
c1.add("1008");
c1.add("1009");
c1.add("1010");
c2 = new Choice();
c2.add("January");
c2.add("February");
c2.add("March");
c2.add("April");
c2.add("May");
c2.add("June");
c2.add("July");
c2.add("August");
c2.add("September");
c2.add("October");
c2.add("November");
c2.add("December");
b1 = new JButton("Submit");
b2 = new JButton("Cancel");
b1.setBackground(Color.BLACK);
b1.setForeground(Color.WHITE);
b2.setBackground(Color.BLACK);
b2.setForeground(Color.WHITE);
ImageIcon i1 = new ImageIcon(ClassLoader.getSystemResource("icon/hicon2.jpg"));
Image i2 = i1.getImage().getScaledInstance(180, 270,Image.SCALE_DEFAULT);
ImageIcon i3 = new ImageIcon(i2);
l4 = new JLabel(i3);
l1.setFont(new Font("Senserif",Font.PLAIN,26));
//Move the label to center
l1.setHorizontalAlignment(JLabel.CENTER);
p.add(l2);
p.add(c1);
p.add(l5);
p.add(c2);
p.add(l3);
p.add(t1);
p.add(b1);
p.add(b2);
setLayout(new BorderLayout(30,30));
add(l1,"North");
add(p,"Center");
add(l4,"West");
//knowledgestreams.blogspot.com
b1.addActionListener(this);
b2.addActionListener(this);
getContentPane().setBackground(Color.WHITE);
setSize(650,500);
setLocation(350,220);
}
public void actionPerformed(ActionEvent ae){
String a = c1.getSelectedItem();
String b = t1.getText();
String c = c2.getSelectedItem();
int p1 = Integer.parseInt(b);
int p2 = p1*7;
int p3 = p2+50+12+102+20+50;
String q = "insert into bill values('"+a+"','"+c+"','"+b+"','"+p3+"')";
try{
conn c1 = new conn();
c1.s.executeUpdate(q);
JOptionPane.showMessageDialog(null,"Bill Updated");
}catch(Exception aee){
aee.printStackTrace();
}
}
public static void main(String[] args){
new calculate_bill().setVisible(true);
}
}
8 - Create next class with name 'pay_bill'.
package Electricity;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class pay_bill extends JFrame{
pay_bill(){
JEditorPane j = new JEditorPane();
j.setEditable(false);
try {
j.setPage("https://paytm.com/electricity-bill-payment");
}catch (Exception e) {
j.setContentType("text/html");
j.setText("<html>Could not load</html>");
}
JScrollPane scrollPane = new JScrollPane(j);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
getContentPane().add(scrollPane);
setPreferredSize(new Dimension(800,600));
setSize(800,800);
setLocation(250,120);
setVisible(true);
}
public static void main(String[] args){
new pay_bill().setVisible(true);
}
}
//knowledgestreams.blogspot.com
9 - Create next class with name 'generate_bill'.
package Electricity;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
public class generate_bill extends JFrame implements ActionListener{
JLabel l1;
JTextArea t1;
JButton b1;
Choice c1,c2;
JPanel p1;
generate_bill(){
setSize(500,900);
setLayout(new BorderLayout());
p1 = new JPanel();
l1 = new JLabel("Generate Bill");
c1 = new Choice();
c2 = new Choice();
//knowledgestreams.blogspot.com
c1.add("1001"); c1.add("1002"); c1.add("1003"); c1.add("1004"); c1.add("1005"); c1.add("1006"); c1.add("1007"); c1.add("1008"); c1.add("1009"); c1.add("1010"); c2.add("January"); c2.add("February"); c2.add("March"); c2.add("April"); c2.add("May"); c2.add("June"); c2.add("July"); c2.add("August"); c2.add("September"); c2.add("October"); c2.add("November"); c2.add("December"); t1 = new JTextArea(50,15); JScrollPane jsp = new JScrollPane(t1); t1.setFont(new Font("Senserif",Font.ITALIC,18)); b1 = new JButton("Generate Bill"); p1.add(l1); p1.add(c1); p1.add(c2); add(p1,"North"); add(jsp,"Center"); add(b1,"South"); b1.addActionListener(this); //knowledgestreams.blogspot.com setLocation(350,40); } public void actionPerformed(ActionEvent ae){ try{ conn c = new conn(); String month = c2.getSelectedItem(); t1.setText("\abc\nELECTRICITY BILL FOR THE MONTH OF "+month+" ,2018\n\n\n"); ResultSet rs = c.s.executeQuery("select * from emp where meter_number="+c1.getSelectedItem()); if(rs.next()){ t1.append("\n Customer Name:"+rs.getString("name")); t1.append("\n Meter Number: "+rs.getString("meter_number")); t1.append("\n Address: "+rs.getString("address")); t1.append("\n State: "+rs.getString("state")); t1.append("\n City: "+rs.getString("city")); t1.append("\n Email: "+rs.getString("email")); t1.append("\n Phone Number "+rs.getString("phone")); t1.append("\n-------------------------------------------------------------"); t1.append("\n"); } rs = c.s.executeQuery("select * from tax"); if(rs.next()){ t1.append("\n Meter Location:"+rs.getString("meter_location")); t1.append("\n Meter Type: "+rs.getString("meter_type")); t1.append("\n Phase Code: "+rs.getString("phase_code")); t1.append("\n Bill Type: "+rs.getString("bill_type")); t1.append("\n Days: "+rs.getString("days")); t1.append("\n"); t1.append("---------------------------------------------------------------"); t1.append("\n\n"); t1.append("\n Meter Rent:\t\t"+rs.getString("meter_rent")); t1.append("\n MCB Rent: \t\t"+rs.getString("mcb_rent")); t1.append("\n Service Tax:\t"+rs.getString("service_rent")); t1.append("\n GST@9%:\t\t"+rs.getString("gst")); t1.append("\n"); } rs = c.s.executeQuery("select * from bill where meter_number="+c1.getSelectedItem()); if(rs.next()){ t1.append("\n Current Month :\t"+rs.getString("month")); t1.append("\n Units Consumed:\t"+rs.getString("units")); t1.append("\n Total Charges :\t"+rs.getString("amount")); t1.append("\n---------------------------------------------------------------"); t1.append("\n TOTAL PAYABLE :\t"+rs.getString("amount")); } //knowledgestreams.blogspot.com
}catch(Exception e){ e.printStackTrace(); } } public static void main(String[] args){ new generate_bill().setVisible(true); } }
c1.add("1001"); c1.add("1002"); c1.add("1003"); c1.add("1004"); c1.add("1005"); c1.add("1006"); c1.add("1007"); c1.add("1008"); c1.add("1009"); c1.add("1010"); c2.add("January"); c2.add("February"); c2.add("March"); c2.add("April"); c2.add("May"); c2.add("June"); c2.add("July"); c2.add("August"); c2.add("September"); c2.add("October"); c2.add("November"); c2.add("December"); t1 = new JTextArea(50,15); JScrollPane jsp = new JScrollPane(t1); t1.setFont(new Font("Senserif",Font.ITALIC,18)); b1 = new JButton("Generate Bill"); p1.add(l1); p1.add(c1); p1.add(c2); add(p1,"North"); add(jsp,"Center"); add(b1,"South"); b1.addActionListener(this); //knowledgestreams.blogspot.com setLocation(350,40); } public void actionPerformed(ActionEvent ae){ try{ conn c = new conn(); String month = c2.getSelectedItem(); t1.setText("\abc\nELECTRICITY BILL FOR THE MONTH OF "+month+" ,2018\n\n\n"); ResultSet rs = c.s.executeQuery("select * from emp where meter_number="+c1.getSelectedItem()); if(rs.next()){ t1.append("\n Customer Name:"+rs.getString("name")); t1.append("\n Meter Number: "+rs.getString("meter_number")); t1.append("\n Address: "+rs.getString("address")); t1.append("\n State: "+rs.getString("state")); t1.append("\n City: "+rs.getString("city")); t1.append("\n Email: "+rs.getString("email")); t1.append("\n Phone Number "+rs.getString("phone")); t1.append("\n-------------------------------------------------------------"); t1.append("\n"); } rs = c.s.executeQuery("select * from tax"); if(rs.next()){ t1.append("\n Meter Location:"+rs.getString("meter_location")); t1.append("\n Meter Type: "+rs.getString("meter_type")); t1.append("\n Phase Code: "+rs.getString("phase_code")); t1.append("\n Bill Type: "+rs.getString("bill_type")); t1.append("\n Days: "+rs.getString("days")); t1.append("\n"); t1.append("---------------------------------------------------------------"); t1.append("\n\n"); t1.append("\n Meter Rent:\t\t"+rs.getString("meter_rent")); t1.append("\n MCB Rent: \t\t"+rs.getString("mcb_rent")); t1.append("\n Service Tax:\t"+rs.getString("service_rent")); t1.append("\n GST@9%:\t\t"+rs.getString("gst")); t1.append("\n"); } rs = c.s.executeQuery("select * from bill where meter_number="+c1.getSelectedItem()); if(rs.next()){ t1.append("\n Current Month :\t"+rs.getString("month")); t1.append("\n Units Consumed:\t"+rs.getString("units")); t1.append("\n Total Charges :\t"+rs.getString("amount")); t1.append("\n---------------------------------------------------------------"); t1.append("\n TOTAL PAYABLE :\t"+rs.getString("amount")); } //knowledgestreams.blogspot.com
}catch(Exception e){ e.printStackTrace(); } } public static void main(String[] args){ new generate_bill().setVisible(true); } }
10- Create next class with name "Last Bill"
package Electricity; import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.sql.*; public class LastBill extends JFrame implements ActionListener{ JLabel l1; JTextArea t1; JButton b1; Choice c1; JPanel p1; LastBill(){ setSize(500,900); setLayout(new BorderLayout()); p1 = new JPanel(); l1 = new JLabel("Generate Bill"); c1 = new Choice(); c1.add("1001"); c1.add("1002"); c1.add("1003"); c1.add("1004"); c1.add("1005"); c1.add("1006"); c1.add("1007"); c1.add("1008"); c1.add("1009"); c1.add("1010"); t1 = new JTextArea(50,15); JScrollPane jsp = new JScrollPane(t1); t1.setFont(new Font("Senserif",Font.ITALIC,18)); b1 = new JButton("Generate Bill"); p1.add(l1); p1.add(c1); add(p1,"North"); add(jsp,"Center"); add(b1,"South"); b1.addActionListener(this); setLocation(350,40); } public void actionPerformed(ActionEvent ae){ try{ conn c = new conn(); ResultSet rs = c.s.executeQuery("select * from emp where meter_number="+c1.getSelectedItem()); if(rs.next()){ t1.append("\n Customer Name:"+rs.getString("name")); t1.append("\n Meter Number: "+rs.getString("meter_number")); t1.append("\n Address: "+rs.getString("address")); t1.append("\n State: "+rs.getString("state")); t1.append("\n City: "+rs.getString("city")); t1.append("\n Email: "+rs.getString("email")); t1.append("\n Phone Number "+rs.getString("phone")); t1.append("\n-------------------------------------------------------------"); t1.append("\n"); } t1.append("Details of the Last Bills\n\n\n"); rs = c.s.executeQuery("select * from bill where meter_number="+c1.getSelectedItem()); while(rs.next()){ t1.append(" "+ rs.getString("month") + " " +rs.getString("amount") + "\n"); } }catch(Exception e){ e.printStackTrace(); } } public static void main(String[] args){ new LastBill().setVisible(true); } }
#java #electricity #bill #code
Free source code for java project on electricity billing system.
package Electricity; import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.sql.*; public class LastBill extends JFrame implements ActionListener{ JLabel l1; JTextArea t1; JButton b1; Choice c1; JPanel p1; LastBill(){ setSize(500,900); setLayout(new BorderLayout()); p1 = new JPanel(); l1 = new JLabel("Generate Bill"); c1 = new Choice(); c1.add("1001"); c1.add("1002"); c1.add("1003"); c1.add("1004"); c1.add("1005"); c1.add("1006"); c1.add("1007"); c1.add("1008"); c1.add("1009"); c1.add("1010"); t1 = new JTextArea(50,15); JScrollPane jsp = new JScrollPane(t1); t1.setFont(new Font("Senserif",Font.ITALIC,18)); b1 = new JButton("Generate Bill"); p1.add(l1); p1.add(c1); add(p1,"North"); add(jsp,"Center"); add(b1,"South"); b1.addActionListener(this); setLocation(350,40); } public void actionPerformed(ActionEvent ae){ try{ conn c = new conn(); ResultSet rs = c.s.executeQuery("select * from emp where meter_number="+c1.getSelectedItem()); if(rs.next()){ t1.append("\n Customer Name:"+rs.getString("name")); t1.append("\n Meter Number: "+rs.getString("meter_number")); t1.append("\n Address: "+rs.getString("address")); t1.append("\n State: "+rs.getString("state")); t1.append("\n City: "+rs.getString("city")); t1.append("\n Email: "+rs.getString("email")); t1.append("\n Phone Number "+rs.getString("phone")); t1.append("\n-------------------------------------------------------------"); t1.append("\n"); } t1.append("Details of the Last Bills\n\n\n"); rs = c.s.executeQuery("select * from bill where meter_number="+c1.getSelectedItem()); while(rs.next()){ t1.append(" "+ rs.getString("month") + " " +rs.getString("amount") + "\n"); } }catch(Exception e){ e.printStackTrace(); } } public static void main(String[] args){ new LastBill().setVisible(true); } }
#java #electricity #bill #code
Free source code for java project on electricity billing system.