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

Vehicle Parking Management Code

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

Vehicle Parking Management Code

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

Vehicle Parking Management

Code (Login Page)


package Parking;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.ResultSet;
public class Login extends JFrame implements ActionListener{
JLabel l1,l2,l3, l4;
JTextField tf1;
JPasswordField pf2;
JButton b1,b2, b3;
JPanel p1,p2,p3,p4;
Choice c1;
Login(){
super("Login Page");
setLayout(null);
getContentPane().setBackground(Color.WHITE);
l1 = new JLabel("Username");
l1.setBounds(300, 20, 100, 20);
add(l1);
l2 = new JLabel("Password");
l2.setBounds(300, 60, 100, 20);
add(l2);
tf1 = new JTextField(15);
tf1.setBounds(400, 20, 150, 20);
add(tf1);
pf2 = new JPasswordField(15);
pf2.setBounds(400, 60, 150, 20);
add(pf2);
l4 = new JLabel("Logging in as");
l4.setBounds(300, 100, 100, 20);
add(l4);
c1 = new Choice();
c1.add("Admin");
c1.add("Customer");
c1.setBounds(400, 100, 150, 20);
add(c1);
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));
b1.setBounds(330, 160, 100, 20);
add(b1);
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));
b2.setBounds(450, 160, 100, 20);
add(b2);
ImageIcon ic4 = new ImageIcon(ClassLoader.getSystemResource("icon/signup.png"));
Image i4 = ic4.getImage().getScaledInstance(16, 16,Image.SCALE_DEFAULT);
b3 = new JButton("Signup",new ImageIcon(i4));
b3.setBounds(380, 200, 130, 20);
add(b3);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
ImageIcon ic3 = new ImageIcon(ClassLoader.getSystemResource("icon/second.jpg"));
Image i3 = ic3.getImage().getScaledInstance(250, 250,Image.SCALE_DEFAULT);
ImageIcon icc3 = new ImageIcon(i3);
l3 = new JLabel(icc3);
l3.setBounds(0, 0, 250, 250);
add(l3);
setLayout(new BorderLayout());
setSize(640,300);
setLocation(600,300);
setVisible(true);
}
public void actionPerformed(ActionEvent ae){
if(ae.getSource() == b1){
try{
Conn c = new Conn();
String a = tf1.getText();
String b = pf2.getText();
String user = c1.getSelectedItem();
String q = "select * from login where username = '"+a+"' and password = '"+b+"' and user =
'"+user+"'";
ResultSet rs = c.s.executeQuery(q);
if(rs.next()){
String meter = rs.getString("meter_no");
new Project(meter, user).setVisible(true);
this.setVisible(false);
}else{
JOptionPane.showMessageDialog(null, "Invalid login");
tf1.setText("");
pf2.setText("");
}
}catch(Exception e){
e.printStackTrace();
System.out.println("error: "+e);
}
}else if(ae.getSource() == b2){
this.setVisible(false);
}else if(ae.getSource() == b3){
this.setVisible(false);
new Signup().setVisible(true);
}
}
public static void main(String[] args){
new Login().setVisible(true);
}
}

Code (Customer Details)


package Parking;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.ResultSet;
public class CustomerDetails extends JFrame implements ActionListener{
JTable t1;
JButton b1;
String x[] = {"Customer Name","Vehicle Number","Address","City","State","Email","Phone"};
String y[][] = new String[40][8];
int i=0, j=0;
CustomerDetails(){
super("Customer Details");
setSize(1200,650);
setLocation(400,150);
try{
Conn c1 = new Conn();
String s1 = "select * from customer";
ResultSet rs = c1.s.executeQuery(s1);
while(rs.next()){
y[i][j++]=rs.getString("name");
y[i][j++]=rs.getString("meter");
y[i][j++]=rs.getString("address");
y[i][j++]=rs.getString("city");
y[i][j++]=rs.getString("state");
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 CustomerDetails().setVisible(true);
}
}

Code (New Customer)

package Parking;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class NewCustomer extends JFrame implements ActionListener{
JLabel l1,l2,l3,l4,l5,l6,l7,l8;
JTextField t1,t2,t3,t4,t5,t6,t7,t8;
JButton b1,b2;
NewCustomer(){
setLocation(600,200);
setSize(700,500);
JPanel p = new JPanel();
p.setLayout(null);
p.setBackground(Color.WHITE);
p.setBackground(new Color(173,216,230));
JLabel title = new JLabel("New Customer");
title.setBounds(180, 10, 200, 26);
title.setFont(new Font("Tahoma", Font.PLAIN, 24));
p.add(title);
l1 = new JLabel("Customer Name");
l1.setBounds(100, 80, 100, 20);
t1 = new JTextField();
t1.setBounds(240, 80, 200, 20);
p.add(l1);
p.add(t1);
l2 = new JLabel("Vehicle No");
l2.setBounds(100, 120, 100, 20);
t8 = new JTextField();
t8.setBounds(240, 120, 200, 20);
p.add(l2);
p.add(t8);
l3 = new JLabel("Address");
l3.setBounds(100, 160, 100, 20);
t3 = new JTextField();
t3.setBounds(240, 160, 200, 20);
p.add(l3);
p.add(t3);
l5 = new JLabel("City");
l5.setBounds(100, 200, 100, 20);
t5 = new JTextField();
t5.setBounds(240, 200, 200, 20);
p.add(l5);
p.add(t5);
l4 = new JLabel("State");
l4.setBounds(100, 240, 100, 20);
t4 = new JTextField();
t4.setBounds(240, 240, 200, 20);
p.add(l4);
p.add(t4);
l6 = new JLabel("Email");
l6.setBounds(100, 280, 100, 20);
t6 = new JTextField();
t6.setBounds(240, 280, 200, 20);
p.add(l6);
p.add(t6);
l7 = new JLabel("Phone Number");
l7.setBounds(100, 320, 100, 20);
t7 = new JTextField();
t7.setBounds(240, 320, 200, 20);
p.add(l7);
p.add(t7);
b1 = new JButton("Next");
b1.setBounds(120, 390, 100, 25);
b2 = new JButton("Cancel");
b2.setBounds(250, 390, 100, 25);
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 Frame
getContentPane().setBackground(Color.WHITE);
b1.addActionListener(this);
b2.addActionListener(this);
}
public void actionPerformed(ActionEvent ae){
if(ae.getSource() == b1){
String name = t1.getText();
String meter = t8.getText();
String address = t3.getText();
String state = t4.getText();
String city = t5.getText();
String email = t6.getText();
String phone = t7.getText();
String q1 = "insert into customer
values('"+name+"','"+meter+"','"+address+"','"+city+"','"+state+"','"+email+"','"+phone+"')";
String q2 = "insert into login values('"+meter+"', '', '', '', '')";
try{
Conn c1 = new Conn();
c1.s.executeUpdate(q1);
c1.s.executeUpdate(q2);
JOptionPane.showMessageDialog(null,"Customer Details Added Successfully");
this.setVisible(false);
new MeterInfo(meter).setVisible(true);
}catch(Exception ex){
ex.printStackTrace();
}
}else if(ae.getSource() ==b2){
this.setVisible(false);
}
}
public static void main(String[] args){
new NewCustomer().setVisible(true);
}
}

Code (Generate Bill)


package Parking;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.ResultSet;

public class GenerateBill extends JFrame implements ActionListener{


JLabel l1, l2;
JTextArea t1;
JButton b1;
Choice c2;
JPanel p1;
String meter;
GenerateBill(String meter){
this.meter = meter;
setSize(500,900);
setLayout(new BorderLayout());
p1 = new JPanel();
l1 = new JLabel("Generate Bill");
l2 = new JLabel(meter);
c2 = new Choice();
c2.add("Monday");
c2.add("Tuesday");
c2.add("Wednesday");
c2.add("Thursday");
c2.add("Friday");
c2.add("Saturday");
c2.add("Sunday");
t1 = new JTextArea(50,15);
t1.setText("\n\n\t------- Click on the -------\n\t Generate Bill Button to get\n\tthe bill of the
Selected Day\n\n");
JScrollPane jsp = new JScrollPane(t1);
t1.setFont(new Font("Senserif",Font.ITALIC,18));
b1 = new JButton("Generate Bill");
p1.add(l1);
p1.add(l2);
p1.add(c2);
add(p1,"North");

add(jsp,"Center");
add(b1,"South");
b1.addActionListener(this);
setLocation(750,100);
}
public void actionPerformed(ActionEvent ae){
try{
Conn c = new Conn();
String day = c2.getSelectedItem();
t1.setText("\tBharati Vidyapeeth Parking \nParking BILL FOR "+day+" ,\n\n\n");
// Use single quotes around the meter value if it's a string
ResultSet rs = c.s.executeQuery("select * from customer where meter='" + meter + "'");
if(rs.next()){
t1.append("\n Customer Name:" + rs.getString("name"));
t1.append("\n Vehicle Number: " + rs.getString("meter"));
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 meter_info where meter_number='" + meter + "'");
if(rs.next()){
t1.append("\n Vehicle Location: " + rs.getString("meter_location"));
t1.append("\n Vehicle 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");
}
rs = c.s.executeQuery("select * from bill where meter='" + meter + "' AND month='" +
c2.getSelectedItem() + "'");
if(rs.next()){
t1.append("\n Day: \t" + rs.getString("month"));
t1.append("\n Hours: \t" + rs.getString("units"));
t1.append("\n Total Charges: \t" + rs.getString("total_bill"));
t1.append("\n---------------------------------------------------------------");
t1.append("\n TOTAL PAYABLE: \t" + rs.getString("total_bill"));
}
}catch(Exception e){
e.printStackTrace();
}
}
public static void main(String[] args){
new GenerateBill("").setVisible(true);
}
}

Code (Database Connectivity)

package Parking;
import java.sql.*;
public class Conn{
Connection c;
Statement s;
public Conn(){
try{
Class.forName("com.mysql.jdbc.Driver");
c =DriverManager.getConnection("jdbc:mysql://localhost:3307/parking","root","");
s =c.createStatement();
}catch(Exception e){
System.out.println(e);
}
}
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy