2025年停车场管理系统源码

停车场管理系统源码package CarParking import java awt event ActionEvent import java awt event ActionListen import java sql Timestamp import java sql PreparedStat import java sql SQLException import

大家好,我是讯享网,很高兴认识大家。


讯享网

 

package CarParking; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.sql.Timestamp; import java.sql.PreparedStatement; import java.sql.SQLException; import java.util.Date; import javax.swing.*; public class Add_in extends JFrame { public Add_in() { JFrame frame = new JFrame("添加入库车辆信息"); frame.setLayout(null); JLabel IDStr = new JLabel("车牌号:"); IDStr.setBounds(180, 200, 100, 25); frame.add(IDStr); JTextField carID = new JTextField(); carID.setBounds(250, 200, 150, 25); frame.add(carID); JLabel intimeStr = new JLabel("入库时间:"); intimeStr.setBounds(180, 250, 100, 25); frame.add(intimeStr); JButton nowTime = new JButton("获取当前时间"); nowTime.setBounds(250, 250, 150, 25); frame.add(nowTime); JButton buttonadd = new JButton("添加"); buttonadd.setBounds(200, 350, 70, 25); frame.add(buttonadd); JButton buttonreturn = new JButton("返回"); buttonreturn.setBounds(300, 350, 70, 25); frame.add(buttonreturn); frame.setBounds(400, 200, 600, 600); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); //返回按钮监听器 buttonreturn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { dispose(); mainWindow ar = new mainWindow(); } }); //为添加按钮增加监听器 buttonadd.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { DB bd = new DB(); Date date = new Date(); Timestamp timeStamp = new Timestamp(date.getTime()); String sql = "insert into car (carid,carin) values (?,?)"; try { PreparedStatement ps = bd.getConn().prepareStatement(sql); ps.setString(1, carID.getText()); ps.setTimestamp(2,timeStamp); ps.executeUpdate(); ps.close(); } catch (SQLException ex) { System.out.println("添加失败!"); } finally { bd.close(); } } }); } // public static void main (String[]args){ // Add_in f = new Add_in(); // } } 

讯享网
讯享网package CarParking; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.sql.*; import java.lang.*; import java.sql.Timestamp; import java.util.Date; import javax.swing.*; public class Add_out extends JFrame { public Add_out() { JFrame frame = new JFrame("添加出库车辆信息"); frame.setLayout(null); JLabel IDStr = new JLabel("车牌号:"); IDStr.setBounds(180, 200, 100, 25); frame.add(IDStr); JTextField carID = new JTextField(); carID.setBounds(250, 200, 150, 25); frame.add(carID); JLabel intimeStr = new JLabel("出库时间:"); intimeStr.setBounds(180, 250, 100, 25); frame.add(intimeStr); // JTextField carOut = new JTextField(); // carID.setBounds(250, 250, 150, 25); // frame.add(carOut); JButton nowTime = new JButton("获取当前时间"); nowTime.setBounds(250, 250, 150, 25); frame.add(nowTime); JLabel jlpayment = new JLabel("费用:"); jlpayment.setBounds(180, 300, 100, 25); frame.add(jlpayment); //计算结果显示 JLabel jpayment= new JLabel(); frame.add(jpayment); jpayment.setBounds(280, 300, 100, 25); JButton calulate = new JButton("计算"); calulate.setBounds(340, 300, 60, 25); frame.add(calulate); JButton buttonadd = new JButton("添加"); buttonadd.setBounds(200, 350, 70, 25); frame.add(buttonadd); JButton buttonreturn = new JButton("返回"); buttonreturn.setBounds(300, 350, 70, 25); frame.add(buttonreturn); frame.setBounds(400, 200, 600, 600); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); //返回按钮监听器 buttonreturn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { dispose(); mainWindow f = new mainWindow(); } }); //为获取当前时间添加监听器 nowTime.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { DB bd = new DB(); Date date = new Date(); Timestamp timeStamp = new Timestamp(date.getTime()); String number = carID.getText(); // String sql = "insert into car (carout) values (?) where carid='"+number+"' and carout =null"; String sql="update car set carout='"+timeStamp+"' where carid='"+number+"' and carout is null"; try { PreparedStatement ps = bd.getConn().prepareStatement(sql); System.out.println("获取成功!"); ps.executeUpdate(); ps.close(); } catch (SQLException ex) { System.out.println("添加失败!!!"); } finally { bd.close(); } } }); //为计算按钮添加监听 calulate.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { DB db = new DB(); Double payment =0.0; Statement stat = null; String number = carID.getText(); Date date = new Date(); String sql = "select timestampdiff(minute,carin,carout)time from car where carid='"+number+"'"; String sql1="update car set payment='"+payment+"' where carid='"+number+"' and carout is null"; try { PreparedStatement ps = db.getConn().prepareStatement(sql); stat = db.getConn().createStatement(); ResultSet res=stat.executeQuery(sql); while (res.next()) { double time= res.getDouble("time"); payment=0.01d*time; PreparedStatement ps1 = db.getConn().prepareStatement(sql1); jpayment.setText(res.getString(1)); System.out.println(time); } } catch (SQLException f) { System.out.println("失败!"); } finally { db.close(); } } }); //为添加按钮增加监听器 buttonadd.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { DB bd = new DB(); String number = carID.getText(); String sql = "update car set payment='"+jpayment.getText()+"' where carid='"+number+"'"; try { PreparedStatement ps = bd.getConn().prepareStatement(sql); ps.executeUpdate(); ps.close(); System.out.println("添加成功!!"); } catch (SQLException ex) { System.out.println("添加失败!"); } finally { bd.close(); } } }); } // public static void main (String[]args){ // Add_out f = new Add_out(); // } } 

package CarParking; public class Admin { private String id; private String password; // public administer(String id, String password) { // this.id = id; // this.password = password; // } public String getId() { return this.id; } public void setId(String id) { this.id = id; } public String getPassword() { return this.password; } public void setPassword(String password) { this.password = password; } }

讯享网package CarParking; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.sql.SQLException; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPasswordField; import javax.swing.JTextField; /* * 管理员注册界面 * */ public class AdminRegister extends JFrame{ AdminRegister () { init(); } void init() { JFrame frame = new JFrame("注册管理员账号"); frame.setLayout(null); JLabel IDStr = new JLabel("账号:"); IDStr.setBounds(250, 200, 100, 25); frame.add(IDStr); JTextField userID = new JTextField(); userID.setBounds(320, 200, 150, 25); frame.add(userID); JLabel passwordStr = new JLabel("密码:"); passwordStr.setBounds(250, 250, 100, 25); frame.add(passwordStr); JPasswordField password = new JPasswordField(); password.setBounds(320, 250, 150, 25); frame.add(password); JLabel confrimStr = new JLabel("确认密码:"); confrimStr.setBounds(250, 300, 100, 30); frame.add(confrimStr); JPasswordField confrimPassword = new JPasswordField(); confrimPassword.setBounds(320, 300, 150, 25); frame.add(confrimPassword); JButton buttonregister = new JButton("注册"); buttonregister.setBounds(350, 350, 70, 25); frame.add(buttonregister); frame.setBounds(400, 100, 800, 640); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); //为注册按钮增加监听器 buttonregister.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String ID = userID.getText(); String passwd = new String (password.getPassword()); String confrimpasswd = new String (confrimPassword.getPassword()); //创建Register类 Register register = new Register(); register.setID(ID); register.setPassword(passwd); register.setconfirmpasswd(confrimpasswd); //如果注册成功,返回登录界面 try { if(register.JudgeRegister()) { frame.setVisible(false); Login_Register login_register = new Login_Register(); } } catch (SQLException e1) { // TODO Auto-generated catch block //e1.printStackTrace(); } catch (ClassNotFoundException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } }); } } 
package CarParking; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.sql.ResultSet; import java.sql.Statement; public class DB { private static String driver = "com.mysql.cj.jdbc.Driver"; private static String url = "jdbc:mysql://localhost:3306/parkingsystem"; private static String user = "root"; private static String sqlpassword = ""; private Connection conn = null;//数据库连接对象 private Connection connectioin(){ try { Class.forName(driver); conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/parkingsystem?" + "user=root&password="); return conn; }catch(SQLException ex) { System.out.println("添加失败!"); }finally { return conn; } } public DB(){ connectioin(); } public Connection getConn(){ return conn; } public void close(){ if (conn != null){ try { conn.close(); }catch(SQLException e){ System.out.println(e); } } } public ResultSet excuteQuery(String sql) { Statement stmt = null; ResultSet rs = null; try{ stmt = conn.createStatement(); rs = stmt.executeQuery(sql); // if (rs == null){ // System.out.println("rs 没有内容"); // } // else{ // System.out.println("rs 非空"); // } return rs; }catch(SQLException e){ System.out.println(e); }finally { return rs; } } // // public static void main(String args[])throws SQLException{ // String id = "admin123"; // String pwd = ""; // String sql = "select * from admin where id='admin123' and password=''"; // DB db = new DB(); // ResultSet rs = db.excuteQuery(sql); // if (rs==null) // System.out.println("null"); // if (rs.next()){ // System.out.println("成功查询"); // }else{ // System.out.print("no"); // } } 

讯享网package CarParking; import java.sql.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; public class delCar extends JFrame{ JLabel jlcarnum = new JLabel("车牌号:"); JTextField jtcarnum = new JTextField("", 20); JButton buttondelete = new JButton("删除"); JButton buttonreturn = new JButton("返回"); public delCar() { JPanel jpcarnum = new JPanel(); JPanel jpforbutton = new JPanel(new GridLayout(1, 1)); jpcarnum.add(jlcarnum); jpcarnum.add(jtcarnum); jpforbutton.add(buttondelete); jpforbutton.add(buttonreturn); buttondelete.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String number = jtcarnum.getText(); DB db=new DB(); ResultSet res = null; Statement stat = null; String sql = "DELETE FROM car WHERE carid='" + number + "'"; try { stat = db.getConn().createStatement(); stat.executeUpdate(sql); } catch (SQLException h) { h.printStackTrace(); } finally { db.close(); } } }); buttonreturn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { dispose(); mainWindow ar=new mainWindow(); } }); this.setTitle("删除车辆信息"); this.setLayout(new GridLayout(9, 1)); this.add(jpcarnum); this.add(jpforbutton); this.setLocation(400, 300); this.setSize(350, 300); this.setVisible(true); } } 

package CarParking; import java.sql.*; import java.awt.event.*; import javax.swing.*; public class FindCar extends JFrame{ JLabel jlcarnum = new JLabel("车牌号:"); JTextField jtcarnum = new JTextField("", 20); JLabel jlcarin = new JLabel("入库时间:"); JLabel jcarin = new JLabel(); JLabel jlcarout = new JLabel("出库时间:"); JLabel jcarout = new JLabel(); JLabel jlpayment = new JLabel("费用:"); JLabel jpayment= new JLabel(); JButton buttonask = new JButton("查询"); JButton buttonreturn = new JButton("返回"); public FindCar() { JPanel jpcarnum = new JPanel(); jpcarnum.setBounds(0, 1, 336, 29); JPanel jpcarin = new JPanel(); jpcarin.setBounds(0, 30, 336, 29); JPanel jpcarout = new JPanel(); jpcarout.setBounds(0, 59, 336, 29); JPanel jppayment = new JPanel(); jppayment.setBounds(0, 88, 336, 29); jpcarnum.add(jlcarnum); jpcarnum.add(jtcarnum); jpcarin.add(jlcarin); jpcarin.add(jcarin); jpcarout.add(jlcarout); jpcarout.add(jcarout); jppayment.add(jlpayment); jppayment.add(jpayment); this.setTitle("查询信息"); getContentPane().setLayout(null); getContentPane().add(jpcarnum); getContentPane().add(jpcarin); getContentPane().add(jpcarout); getContentPane().add(jppayment); buttonask.setBounds(0, 224, 168, 29); getContentPane().add(buttonask); buttonreturn.setBounds(168, 224, 168, 29); getContentPane().add(buttonreturn); buttonreturn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { dispose(); mainWindow ar=new mainWindow(); } }); buttonask.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { DB db=new DB(); ResultSet res = null; Statement stat = null; String sql = "SELECT carid,carin,carout,payment FROM car;"; try { stat = db.getConn().createStatement(); res = stat.executeQuery(sql); while (res.next()) { if (res.getString(1).equals(jtcarnum.getText())) { jcarin.setText(res.getString(2)); jcarout.setText(res.getString(3)); jpayment.setText(res.getString(4)); break; } } } catch (SQLException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } finally { db.close(); } } }); this.setLocation(400, 300); this.setSize(350, 300); this.setVisible(true); } } 
讯享网package CarParking; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; public class Login { Admin admin; void setAdmin(Admin admin) { this.admin=admin; //System.out.println(this.admin.getPassword()+" " + this.admin.getID()); } /* * JudgeAdmin()方法 * 判断Admin的ID和密码是否正确,如果正确,显示登录成功 * 如果错误,弹出一个窗口,显示账号或密码错误 */ public boolean login(Admin admin) throws SQLException, ClassNotFoundException { DB bd=new DB(); String sql="select * from admin where id=? and password=?"; PreparedStatement ps = bd.getConn().prepareStatement(sql); ps.setString(1, admin.getId()); ps.setString(2, admin.getPassword()); ResultSet rs = ps.executeQuery(); int ans = 0; if(rs.next()) { ans = 1; } rs.close(); ps.close(); bd.getConn().close(); if(ans == 1) { return true; } else return false; } int JudgeAdmin() { try { if(login(this.admin)) { System.out.println("登录成功"); return 1; }else { return 0; } }catch(Exception e) { //e.printStackTrace(); //System.out.println("!!!!!!!!!"); } return 0; } } 
package CarParking; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPasswordField; import javax.swing.JTextField; public class Login_Register extends JFrame{ Login_Register() {init();} //登录界面初始化 public void init() { JFrame frame = new JFrame("管理员登录"); frame.setLayout(null); JLabel nameStr = new JLabel("账号:"); nameStr.setBounds(250, 200, 100, 25); frame.add(nameStr); JLabel passwordStr = new JLabel("密码:"); passwordStr.setBounds(250, 250, 100, 25); frame.add(passwordStr); JTextField userID = new JTextField(); userID.setBounds(300, 200, 150, 25); frame.add(userID); JPasswordField password = new JPasswordField(); password.setBounds(300, 250, 150, 25); frame.add(password); //添加登陆按钮 JButton buttonlogin = new JButton("登录"); buttonlogin.setBounds(275, 300, 70, 25); frame.add(buttonlogin); frame.setBounds(400, 100, 800, 640); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); //添加注册按钮 JButton buttonregister = new JButton("注册"); buttonregister.setBounds(375, 300, 70, 25); frame.add(buttonregister); frame.setBounds(400, 100, 800, 640); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); //为登录按钮添加监听器 buttonlogin.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String ID = userID.getText(); String passwd = new String (password.getPassword()); //创建一个Admin用户,把输入框中的用户名密码和提出来 Admin admin = new Admin(); admin.setId(ID); admin.setPassword(passwd); //登录 Login login = new Login(); login.setAdmin(admin); if(login.JudgeAdmin()==0) { //弹出账号或密码错误的窗口对话框 JOptionPane.showMessageDialog(null, "账号或密码错误", "账号或密码错误", JOptionPane.WARNING_MESSAGE); //清除密码框中的信息 password.setText(""); //清除账号框中的信息 userID.setText(""); //System.out.println("登陆失败"); } else { //弹出登录成功的窗口 JOptionPane.showMessageDialog(null, "登陆成功", "登陆成功", JOptionPane.NO_OPTION); //点击确定后会跳转到主窗口 frame.setVisible(false); mainWindow ar=new mainWindow(); } } }); //为注册按钮添加监听器 buttonregister.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { //注册页面 frame.setVisible(false); AdminRegister ar = new AdminRegister(); } }); } public static void main(String []args) { //登录窗口 Login_Register login_register = new Login_Register(); } } 

讯享网package CarParking; import javax.swing.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.sql.*; import java.awt.*; import java.util.*; public class LookCar extends JFrame { JButton buttonreturn = new JButton("返回"); JTable jtable; JScrollPane jscrollpane = new JScrollPane(); Vector columnNames = null; Vector rowData = null; public LookCar() { JPanel jpforbutton = new JPanel(new GridLayout(1, 1)); columnNames = new Vector(); columnNames.add("车牌号"); columnNames.add("入库时间"); columnNames.add("出库时间"); columnNames.add("费用"); rowData = new Vector(); jpforbutton.add(buttonreturn); buttonreturn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { dispose(); mainWindow ar=new mainWindow(); } }); DB db = new DB(); try { String sql="SELECT * FROM car"; PreparedStatement ps = db.getConn().prepareStatement(sql); ResultSet res = ps.executeQuery(); while (res.next()) { Vector hang = new Vector(); hang.add(res.getString(1)); hang.add(res.getString(2)); hang.add(res.getString(3)); hang.add(res.getString(4)); rowData.add(hang); } System.out.println("成功载入"); } catch (Exception q) { q.printStackTrace(); System.out.println("失败"); } finally { db.close(); } jtable = new JTable(rowData, columnNames); jscrollpane = new JScrollPane(jtable); getContentPane().add(jscrollpane); this.setTitle("浏览车辆信息"); getContentPane().setLayout(new GridLayout(2, 5)); getContentPane().add(jpforbutton); this.setLocation(300, 300); this.setSize(500, 300); this.setVisible(true); this.setResizable(false); } // public static void main(String[] args) { // LookCar f=new LookCar(); // } } 
package CarParking; import javax.swing.*; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; / * 主界面 */ class mainWindow extends JFrame { mainWindow (){ init(); } void init() { JFrame frame = new JFrame("车辆信息管理中心"); frame.setLayout(null); JButton buttonlook = new JButton("浏览车辆信息"); buttonlook.setBounds(250, 150, 150, 30); frame.add(buttonlook); JButton buttonadd_in = new JButton("添加入库信息"); buttonadd_in.setBounds(250, 200, 150, 30); frame.add(buttonadd_in); JButton buttonadd_out = new JButton("添加出库信息"); buttonadd_out.setBounds(250, 250, 150, 30); frame.add(buttonadd_out); JButton buttondel = new JButton("删除车辆信息"); buttondel.setBounds(250, 300, 150, 30); frame.add(buttondel); JButton buttonask = new JButton("查询车辆信息"); buttonask.setBounds(250, 350, 150, 30); frame.add(buttonask); frame.setBounds(400, 100, 600, 600); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); //为各功能按钮添加监听器 buttonlook.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { frame.setVisible(false); LookCar f=new LookCar(); } }); buttonadd_in.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { frame.setVisible(false); Add_in f=new Add_in(); } }); buttonadd_out.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { frame.setVisible(false); Add_out f=new Add_out(); } }); buttondel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { frame.setVisible(false); delCar f=new delCar(); } }); buttonask.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { //注册页面 frame.setVisible(false); FindCar f=new FindCar(); } }); } }

讯享网package CarParking; import java.sql.PreparedStatement; import java.sql.SQLException; import javax.swing.JOptionPane; public class Register { String ID; String password; String confirmpassword; void setID(String ID) { this.ID = ID; } void setPassword(String password) { this.password = password; } void setconfirmpasswd(String confirmpassword) { this.confirmpassword = confirmpassword; } //判断注册的账号是否符合规则 boolean JudgeRegister() throws SQLException, ClassNotFoundException { if(this.ID.equals("")) { JOptionPane.showMessageDialog(null, "账号不能为空!", "账号为空", JOptionPane.ERROR_MESSAGE); return false; } if(this.password.equals("")) { JOptionPane.showMessageDialog(null, "密码不能为空!", "密码为空", JOptionPane.ERROR_MESSAGE); return false; } if(!this.password.equals(this.confirmpassword)) { JOptionPane.showMessageDialog(null, "两次输入的密码不一致!", "密码不一致", JOptionPane.ERROR_MESSAGE); return false; } //符合规则,弹出注册成功的窗口,并将账号添加数据库 JOptionPane.showMessageDialog(null, "注册成功"); addAdmin(); return true; } //向数据库添加Admin账户 void addAdmin() throws ClassNotFoundException, SQLException { DB bd=new DB(); bd.getConn(); String sql="insert into admin (id,password) values (?,?)"; try { PreparedStatement ps = bd.getConn().prepareStatement(sql); ps.setString(1, this.ID); ps.setString(2, this.password); ps.executeUpdate(); ps.close(); bd.getConn().close(); }catch(SQLException ex) { System.out.println("添加用户失败!"); } } } 
小讯
上一篇 2025-04-05 13:17
下一篇 2025-02-14 09:03

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/125990.html