javaSwing车辆租赁管理系统

一、 引言

车辆租赁管理系统是一种便捷的解决方案,用于有效管理汽车租赁业务。本博客将介绍一个基于Java Swing的车辆租赁管理系统的开发,并展示相应的数据库设计。

二、 开发环境

Java Swing
MySQL数据库

三、 数据库设计

在MySQL数据库中,我们创建了四张表:car、rental、stores、user,分别用于存储车辆信息、租赁记录、门店信息和用户信息。

3.1 car表

car表用于存储车辆信息,包括车牌号、车型、数量、租金、颜色、是否可租、车辆信息详情和所属用户。

CREATE TABLE car (
carnum varchar(11) NOT NULL,
cartype varchar(25) DEFAULT NULL,
num varchar(3) DEFAULT NULL,
price double(20,0) DEFAULT NULL,
color varchar(10) DEFAULT NULL,
hire varchar(10) DEFAULT NULL,
information text,
username varchar(20) DEFAULT NULL,
PRIMARY KEY (carnum)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

3.2 rental表

rental表用于记录车辆租赁信息,包括车牌号、用户名、租赁天数和总租金。

CREATE TABLE rental (
carnum varchar(11) NOT NULL,
username varchar(20) NOT NULL,
days int(20) DEFAULT NULL,
allprice double(20,0) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

3.3 stores表

stores表用于存储门店信息,包括门店编号、地址、联系方式、管理员用户名和密码。

CREATE TABLE stores (
num varchar(3) NOT NULL,
address varchar(100) NOT NULL,
contact char(11) NOT NULL,
adminname varchar(20) DEFAULT NULL,
admin_password varchar(20) DEFAULT NULL,
PRIMARY KEY (num)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

3.4 user表

user表用于存储用户信息,包括用户名、密码、身份证号和手机号。

CREATE TABLE user (
username varchar(20) NOT NULL,
user_password varchar(20) NOT NULL,
user_cardid varchar(20) NOT NULL,
user_phone char(11) NOT NULL,
PRIMARY KEY (username)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

四、数据库初始化数据

为了方便演示,我们在数据库中插入了一些初始数据,包括车辆信息、租赁记录、门店信息和用户信息。

五、Java Swing车辆租赁管理系统开发

使用Java Swing进行开发,可以实现一个用户友好的界面。在开发过程中,可以通过JDBC连接MySQL数据库,实现对车辆、租赁、门店和用户信息的增删改查功能。

六、程序截图

1.管理员界面

在这里插入图片描述

2.租赁信息浏览

在这里插入图片描述

3.用户信息浏览

在这里插入图片描述

4.车辆信息修改

在这里插入图片描述

5.车辆信息录入

在这里插入图片描述

6.删除

在这里插入图片描述

7.修改用户

在这里插入图片描述

2.用户登录

1.用户浏览界面

在这里插入图片描述

2.个人信息修改界面

在这里插入图片描述

3.注册界面

在这里插入图片描述

七、代码

1.adminUI

package controller;
import java.awt.BorderLayout;import util.DbUtil;
import vo.User;import java.awt.HeadlessException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;import service.UserService;@SuppressWarnings({ "unused", "serial" })
public class AdminUI extends JFrame implements ActionListener{/** * 管理员端的界面*/JTable table;JLabel label1,label2,label3,label4,label5;Object a[][];Object name[] = {"编号","车型","车主","价格(元/天)","颜色","是否被租用","租用的用户"};JButton buttonOfXinxiluru,buttonOfuserliulan,buttonOfuserxiugai,buttonOfUdelete,buttonOfXinxiliulan,buttonOfDelete,buttonOfLogout,buttonOfXiangXi,buttonOfXiugai,buttonOfRental;Box box1,box2;JTextField field,field2,field3,field4;JPanel jPanel4,jPanel5;Connection con = null;Statement stmt = null;ResultSet rs = null;public AdminUI(Boolean success){init();setVisible(true);setBounds(500, 200, 700, 750);setTitle("管理员界面");if(success)//successs是一个boolean类型,如果为true,打开此窗口直接信息浏览,false表里面没有信息,需要点击信息浏览!{xinXiLiuLan();			}}void init(){label1 = new JLabel("汽车租赁信息管理系统");buttonOfXinxiluru = new JButton("  汽车信息录入  ");buttonOfXinxiluru.addActionListener(this);buttonOfXinxiliulan = new JButton("  汽车信息浏览  ");buttonOfXinxiliulan.addActionListener(this);buttonOfuserliulan = new JButton("  用户信息浏览  ");buttonOfuserliulan.addActionListener(this);buttonOfRental = new JButton("  租赁信息浏览  ");buttonOfRental.addActionListener(this);buttonOfuserxiugai = new JButton("  用户信息修改  ");buttonOfuserxiugai.addActionListener(this);buttonOfUdelete = new JButton("  用户信息删除  ");buttonOfUdelete.addActionListener(this);buttonOfDelete = new JButton("    删	            除      ");buttonOfDelete.addActionListener(this);buttonOfLogout = new JButton("  退   出   登   录  ");buttonOfLogout.addActionListener(this);buttonOfXiugai = new JButton("    修	           改      ");buttonOfXiugai.addActionListener(this);buttonOfXiangXi = new JButton("  详   细   信   息  ");buttonOfXiangXi.addActionListener(this);label2 = new JLabel("待删除信息车牌号:");label3 = new JLabel("待修改信息的车牌号:");label4 = new JLabel("待查询车辆备注的车牌号:");label5 = new JLabel("需操作的用户名 :   ");field = new JTextField();field2 = new JTextField();field3 = new JTextField();field4 = new JTextField();a = new Object[50][7];table = new JTable(a, name);//组件的创建table.setEnabled(false);JScrollPane scrollPane = new JScrollPane(table);box1 = Box.createVerticalBox();box1.add(Box.createVerticalStrut(20));box1.add(buttonOfXinxiluru);box1.add(Box.createVerticalStrut(10));box1.add(buttonOfXinxiliulan);box1.add(Box.createVerticalStrut(10));box1.add(buttonOfuserliulan);box1.add(Box.createVerticalStrut(10));box1.add(buttonOfRental);box1.add(Box.createVerticalStrut(10));box1.add(label5);box1.add(Box.createVerticalStrut(10));box1.add(field4);box1.add(Box.createVerticalStrut(10));box1.add(buttonOfUdelete);		box1.add(Box.createVerticalStrut(10));box1.add(buttonOfuserxiugai);box1.add(Box.createVerticalStrut(15));box1.add(label2);box1.add(Box.createVerticalStrut(5));box1.add(field);box1.add(Box.createVerticalStrut(5));box1.add(buttonOfDelete);box1.add(Box.createVerticalStrut(25));box1.add(label3);box1.add(Box.createVerticalStrut(5));box1.add(field2);box1.add(Box.createVerticalStrut(5));box1.add(buttonOfXiugai);box1.add(Box.createVerticalStrut(25));box1.add(label4);box1.add(Box.createVerticalStrut(5));box1.add(field3);box1.add(Box.createVerticalStrut(5));box1.add(buttonOfXiangXi);box1.add(Box.createVerticalStrut(40));box1.add(buttonOfLogout);box2 = Box.createHorizontalBox();box2.add(Box.createHorizontalStrut(10));box2.add(box1);   //左边的按钮部分用 box布局jPanel4 = new JPanel();jPanel5 = new JPanel();jPanel4.setLayout(new BorderLayout());jPanel4.add(box2,BorderLayout.NORTH);//把左边的按钮部分放到jpanel4中。jPanel5.setLayout(new BorderLayout());jPanel5.add(label1,BorderLayout.NORTH);jPanel5.add(scrollPane,BorderLayout.CENTER);//把表格 放jpanel5里this.setLayout(new BorderLayout());add(jPanel5,BorderLayout.EAST);add(jPanel4,BorderLayout.WEST);//把两个大的panel放到窗口里面				}public void connDB() {try {Class.forName("com.mysql.jdbc.Driver");//注册驱动} catch (ClassNotFoundException e) {e.printStackTrace();}try {//创建连接con = DriverManager.getConnection(DbUtil.dbUrlString, DbUtil.dbUser, DbUtil.dbpassword);} catch (SQLException e) {e.printStackTrace();}}public void closeDB() {try {stmt.close();con.close();} catch (SQLException e) {e.printStackTrace();}}public void xinXiLiuLan()//信息浏览的方法,因为删除数据后会刷新一下,自动调用此函数。{int i=0;while(i<50){a[i][0]=" ";a[i][1]=" ";a[i][2]=" ";a[i][3]=" ";a[i][4]=" ";a[i][5]=" ";a[i][6]=" "; i++;}i=0;this.connDB();try {stmt = con.createStatement();String sql= "select * from car";rs = stmt.executeQuery(sql);while(rs.next()){String number = rs.getString("carnum");String cartype = rs.getString("cartype");String carower = rs.getString("num");String price = rs.getString("price");String color = rs.getString("color");String  hire= rs.getString("hire");String username= rs.getString("username");a[i][0]=number;a[i][1]=cartype;a[i][2]=carower;a[i][3]=price;a[i][4]=color;a[i][5]=hire;a[i][6]=username;i++;}this.closeDB();repaint();} catch (SQLException e1) {e1.printStackTrace();}this.closeDB();}@Overridepublic void actionPerformed(ActionEvent e) {Object source = e.getSource();if(source == buttonOfXinxiluru){this.dispose();new Input();}else if(source == buttonOfXinxiliulan){xinXiLiuLan();}else if (source == buttonOfUdelete) {if(field4.getText().equals("")){JOptionPane.showMessageDialog(null, "输入用户名!");}else {vo.User user = new User();UserService us = new UserService();user.setUsername(field4.getText());if (us.showUser(user).getUsername().equals(field4.getText())) {us.delete(user);JOptionPane.showMessageDialog(null, "删除成功!");}else {JOptionPane.showMessageDialog(null, "用户名不存在!");}}}else if(source == buttonOfXiugai){if(field2.getText().equals("")){JOptionPane.showMessageDialog(null, "输入修改车型的编号!");}else{this.dispose();new InfoMod(field2.getText());}}else if(source == buttonOfXiangXi)//点击详细信息按钮{this.dispose();new Info(field3.getText());}else if(source == buttonOfuserliulan){this.dispose();new UserAll();}else if(source == buttonOfDelete)//点击删除按钮{if(field.getText().equals("")){JOptionPane.showMessageDialog(null, "请输入删除车辆的编号!");}else{this.connDB();String sql;try {stmt = con.createStatement();sql = "select * from car_information  where number='"+field.getText()+"'";//表里找到需要删除的车信息rs = stmt.executeQuery(sql);} catch (SQLException e2) {e2.printStackTrace();}try {if(rs.next())//判断是否有 输入编号的 车辆{int n = JOptionPane.showConfirmDialog(this, "确定删除此车辆信息?","确认对话框",JOptionPane.YES_NO_OPTION);//确认文本框if(n == JOptionPane.YES_OPTION){	String hire2 = rs.getString("hire");if(hire2.equals("是")){int m = JOptionPane.showConfirmDialog(this, "此车辆正在被租用,是否删除?","确认对话框",JOptionPane.YES_NO_OPTION);//确认文本框if(m == JOptionPane.YES_OPTION){try{stmt = con.createStatement();String sql2 = "delete from car_information where number='"+field.getText()+"';";stmt.executeUpdate(sql2);}catch (SQLException e1){e1.printStackTrace();}this.closeDB();repaint();field.setText("");JOptionPane.showMessageDialog(null,"删除成功!");xinXiLiuLan();return;}else {return;				}}try{stmt = con.createStatement();String sql2 = "delete from car where carnum='"+field.getText()+"';";stmt.executeUpdate(sql2);}catch (SQLException e1){e1.printStackTrace();}this.closeDB();repaint();field.setText("");JOptionPane.showMessageDialog(null,"删除成功!");xinXiLiuLan();}else if(n == JOptionPane.NO_OPTION){}}else{JOptionPane.showMessageDialog(null, "没有此编号的车辆信息!");}} catch (HeadlessException e1) {e1.printStackTrace();} catch (SQLException e1) {e1.printStackTrace();}												}}else if (source == buttonOfuserxiugai) {new AdminUserRevise(field4.getText());}else if (source == buttonOfRental) {new Rental();}else if(source == buttonOfLogout)//退出{this.dispose();new Login();}}}

2.AdminUserRevise


package controller;import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JTextField;import util.DbUtil;@SuppressWarnings("serial")public class AdminUserRevise extends JFrame implements ActionListener {JTextField field1,field4,field5;JPasswordField field2,field3;JButton buttonOfZhuce,buttonOfFanhui;Box box1,box2,box3,box4,box5,box6,baseBox;Connection con = null;Statement stmt = null;ResultSet rs = null;public AdminUserRevise(String username){init();setVisible(true);setBounds(500, 200, 500, 450);setTitle("管理员修改用户界面");}@SuppressWarnings("static-access")void init(){			box1= Box.createHorizontalBox();box1.add(new JLabel("新用户名:"));box1.add(Box.createHorizontalStrut(8));field1 = new JTextField(15);box1.add(field1);box2= Box.createHorizontalBox();box2.add(new JLabel("密         码:"));box2.add(Box.createHorizontalStrut(8));field2 = new JPasswordField(15);box2.add(field2);box3= Box.createHorizontalBox();box3.add(new JLabel("再次输入:"));box3.add(Box.createHorizontalStrut(8));field3 = new JPasswordField(15);box3.add(field3);box5= Box.createHorizontalBox();box5.add(new JLabel("驾驶证号:"));box5.add(Box.createHorizontalStrut(8));field4 = new JTextField(15);box5.add(field4);box6= Box.createHorizontalBox();box6.add(new JLabel("手  机  号:"));box6.add(Box.createHorizontalStrut(8));field5 = new JTextField(15);box6.add(field5);box4= Box.createHorizontalBox();buttonOfZhuce = new JButton("修改");buttonOfZhuce.addActionListener(this);buttonOfFanhui = new JButton("返回");buttonOfFanhui.addActionListener(this);box4.add(buttonOfZhuce);box4.add(box4.createHorizontalStrut(5));box4.add(buttonOfFanhui);baseBox = Box.createVerticalBox();baseBox.add(Box.createVerticalStrut(50));baseBox.add(box1);baseBox.add(Box.createVerticalStrut(10));baseBox.add(box2);baseBox.add(Box.createVerticalStrut(10));baseBox.add(box3);baseBox.add(Box.createVerticalStrut(10));baseBox.add(box5);baseBox.add(Box.createVerticalStrut(10));baseBox.add(box6);baseBox.add(Box.createVerticalStrut(20));baseBox.add(box4);add(baseBox);}public void connDB() { // 连接数据库try {Class.forName("com.mysql.jdbc.Driver");//注册驱动} catch (ClassNotFoundException e) {e.printStackTrace();}try {//创建连接con = DriverManager.getConnection(DbUtil.dbUrlString, DbUtil.dbUser, DbUtil.dbpassword);stmt = con.createStatement();} catch (SQLException e) {e.printStackTrace();}}public void closeDB() // 关闭连接{try {stmt.close();con.close();} catch (SQLException e) {e.printStackTrace();}}public void actionPerformed(ActionEvent e) {Object source = e.getSource();			if(source == buttonOfZhuce){if (field1.getText().equals("")||field4.getText().equals("")||field5.getText().equals("")||String.valueOf(field2.getPassword()).equals("")||String.valueOf(field3.getPassword()).equals("")){JOptionPane.showMessageDialog(null, "请填写完整!");}				else {if(String.valueOf(field2.getPassword()).equals(String.valueOf(field3.getPassword()))){String str ="update user set username='"+field1.getText()+"', user_password='"+String.valueOf(field2.getPassword())+"',user_cardid='"+field4.getText()+"',user_phone='"+field5.getText()+"';";try {stmt.executeUpdate(str);rs.close();} catch (SQLException e1) {e1.printStackTrace();}JOptionPane.showMessageDialog(null, "修改成功!");this.dispose();}else {JOptionPane.showMessageDialog(null,"两次输入的密码不匹配!" );}}}																																			 												else if(source == buttonOfFanhui){this.dispose();				}						}}

3.CarRemark

package controller;
import java.awt.HeadlessException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextArea;import util.DbUtil;/** * 这个车辆界面详细信息 用户端*/
@SuppressWarnings("serial")
public class CarRemak extends JFrame implements ActionListener{JTextArea area;Box box1,baseBox,box2,baseBox2;JButton buttonOfBianJi,buttonOfFanHui;Connection con = null;Statement stmt = null;ResultSet rs = null;String number=null;int setEnable =0;String information;String username = null;public  CarRemak(String number,String username){init();setVisible(true);setBounds(500, 200, 620, 360);setTitle("车辆详细信息界面");this.number = number;this.username = username;setArea();}public  void setArea()//打开界面就把 数据库中的详细信息写入到area中{this.connDB();try {stmt = con.createStatement();String sql = "select * from car_information where number='"+number+"'; ";rs = stmt.executeQuery(sql);} catch (SQLException e2) {e2.printStackTrace();}try {if(rs.next()){information = rs.getString("information");area.setText(information);area.setEnabled(false);}else{JOptionPane.showMessageDialog(null,"没有此编号的车辆的详细信息!");}} catch (HeadlessException e2) {e2.printStackTrace();} catch (SQLException e2) {e2.printStackTrace();}}@SuppressWarnings("static-access")void init(){JLabel label = new JLabel("车辆的详细信息:");area = new JTextArea(10, 10);buttonOfFanHui = new JButton("返回");buttonOfFanHui.addActionListener(this);box1 = Box.createVerticalBox();box1.add(box1.createVerticalStrut(8));box1.add(label);box1.add(area);box2 = Box.createHorizontalBox();box2.add(box2.createHorizontalStrut(8));box2.add(buttonOfFanHui);baseBox = Box.createHorizontalBox();baseBox.add(baseBox.createHorizontalStrut(10));baseBox.add(box1);baseBox.add(baseBox.createHorizontalStrut(10));baseBox2 = Box.createVerticalBox();baseBox2.add(baseBox);baseBox2.add(baseBox2.createVerticalStrut(10));baseBox2.add(box2);baseBox2.add(baseBox2.createVerticalStrut(10));add(baseBox2);}public void connDB() { // 连接数据库try {Class.forName("com.mysql.jdbc.Driver");//注册驱动} catch (ClassNotFoundException e) {e.printStackTrace();}try {//创建连接con = DriverManager.getConnection(DbUtil.dbUrlString, DbUtil.dbUser, DbUtil.dbpassword);} catch (SQLException e) {e.printStackTrace();}}public void closeDB() // 关闭连接{try {stmt.close();con.close();} catch (SQLException e) {e.printStackTrace();}}@Overridepublic void actionPerformed(ActionEvent e) {Object source = e.getSource();if (source == buttonOfFanHui){this.dispose();new UserUI(username);}							}			
}

4.Info


package controller;
import java.awt.HeadlessException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextArea;import util.DbUtil;@SuppressWarnings("serial")
public class Info extends JFrame implements ActionListener{JTextArea area;Box box1,baseBox,box2,baseBox2;JButton buttonOfBianJi,buttonOfFanHui,buttonOfTi;Connection con = null;Statement stmt = null;ResultSet rs = null;String number=null;int setEnable =0;String information;
/*	* 管理员查询车辆的详细信息*/public Info(String number){init();setVisible(true);setBounds(500, 200, 620, 360);setTitle("管理员详细信息界面");this.number = number;setArea();}public  void setArea()//打开界面就把 数据库中的详细信息写入到area中{this.connDB();try {stmt = con.createStatement();String sql = "select * from car where carnum='"+number+"'; ";rs = stmt.executeQuery(sql);} catch (SQLException e2) {e2.printStackTrace();}try {if(rs.next()){information = rs.getString("information");area.setText(information);area.setEnabled(false);}else{JOptionPane.showMessageDialog(null,"没有此编号的车辆的详细信息!");new AdminUI(true);}} catch (HeadlessException e2) {e2.printStackTrace();} catch (SQLException e2) {e2.printStackTrace();}}@SuppressWarnings("static-access")void init(){JLabel label = new JLabel("车辆的详细信息:");area = new JTextArea(10, 10);buttonOfBianJi = new JButton("编辑");buttonOfBianJi.addActionListener(this);buttonOfFanHui = new JButton("返回");buttonOfFanHui.addActionListener(this);buttonOfTi = new JButton("提交");buttonOfTi.addActionListener(this);box1 = Box.createVerticalBox();box1.add(box1.createVerticalStrut(8));box1.add(label);box1.add(area);box2 = Box.createHorizontalBox();box2.add(box2.createHorizontalStrut(8));box2.add(buttonOfBianJi);box2.add(box2.createHorizontalStrut(8));box2.add(buttonOfTi);box2.add(box2.createHorizontalStrut(8));box2.add(buttonOfFanHui);baseBox = Box.createHorizontalBox();baseBox.add(baseBox.createHorizontalStrut(10));baseBox.add(box1);baseBox.add(baseBox.createHorizontalStrut(10));baseBox2 = Box.createVerticalBox();baseBox2.add(baseBox);baseBox2.add(baseBox2.createVerticalStrut(10));baseBox2.add(box2);baseBox2.add(baseBox2.createVerticalStrut(10));add(baseBox2);}public void connDB() { // 连接数据库try {Class.forName("com.mysql.jdbc.Driver");//注册驱动} catch (ClassNotFoundException e) {e.printStackTrace();}try {//创建连接con = DriverManager.getConnection(DbUtil.dbUrlString, DbUtil.dbUser, DbUtil.dbpassword);} catch (SQLException e) {e.printStackTrace();}}public void closeDB() // 关闭连接{try {stmt.close();con.close();} catch (SQLException e) {e.printStackTrace();}}public void actionPerformed(ActionEvent e) {Object source = e.getSource();if(source == buttonOfBianJi){area.setEnabled(true);setEnable = 1;}else if (source == buttonOfFanHui){this.dispose();new AdminUI(false);}else if(source == buttonOfTi){if(setEnable == 1){String areaString = area.getText();this.connDB();try {stmt = con.createStatement();		String sqlString ="update car_information set information='"+areaString+"'where number = '"+number+"';";stmt.executeUpdate(sqlString);} catch (SQLException e1) {e1.printStackTrace();}JOptionPane.showMessageDialog(null, "提交成功!");this.closeDB();this.dispose();new AdminUI(true);}else{JOptionPane.showMessageDialog(null, "请点击编辑变换成编辑状态!");}}}}

5.Login

package controller;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.swing.Box;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import service.AdminService;
import service.UserService;
import vo.Stores;
import vo.User;
@SuppressWarnings("serial")
public class Login extends JFrame implements ActionListener{JTextField zhanghao_field;JPasswordField mima_field;JRadioButton yonghu_radioButton,guanliyuan_radioButton;JButton login_button,zhuce_button;Box box1,box2,box3,box4,basebBox;//账号,密码,两个radiobutton,两个按钮都是用行式盒子布局。 basebox用列式把他们包裹起来。Connection con = null;Statement stmt = null;ResultSet rs = null;public Login(){setLayout(new FlowLayout());init();setVisible(true);setBounds(500, 200, 500, 500);setTitle("登陆界面");}void init(){		box1 = Box.createHorizontalBox();box1.add(new JLabel("账号:"));box1.add(Box.createHorizontalStrut(8));zhanghao_field = new JTextField(15);box1.add(zhanghao_field);//登陆界面 账号和输入框的一行box2 = Box.createHorizontalBox();box2.add(new JLabel("密码:"));box2.add(Box.createHorizontalStrut(8));mima_field = new JPasswordField(15);box2.add(mima_field);//登陆界面密码和输入框的一行box3 = Box.createHorizontalBox();ButtonGroup group = new ButtonGroup();yonghu_radioButton = new JRadioButton("用户");group.add(yonghu_radioButton);yonghu_radioButton.addActionListener(this);box3.add(yonghu_radioButton);box3.add(Box.createHorizontalStrut(8));guanliyuan_radioButton = new JRadioButton("管理员");group.add(guanliyuan_radioButton);guanliyuan_radioButton.addActionListener(this);box3.add(guanliyuan_radioButton);//登陆界面 单选框box4 = Box.createHorizontalBox();login_button = new JButton("登陆");login_button.addActionListener(this);box4.add(login_button);box4.add(Box.createHorizontalStrut(8));zhuce_button = new JButton("注册");zhuce_button.addActionListener(this);box4.add(zhuce_button);//登陆界面两个按钮basebBox = Box.createVerticalBox();basebBox.add(Box.createVerticalStrut(50));basebBox.add(box1);basebBox.add(Box.createVerticalStrut(10));basebBox.add(box2);basebBox.add(Box.createVerticalStrut(30));basebBox.add(box3);basebBox.add(Box.createVerticalStrut(80));basebBox.add(box4);//把4个盒子放一个大盒子		add(basebBox);	}		public void actionPerformed(ActionEvent e) {Object source = e.getSource();if (source == login_button) {if (!yonghu_radioButton.isSelected() && !guanliyuan_radioButton.isSelected()) {JOptionPane.showMessageDialog(null, "请选择身份!");} else if (zhanghao_field.getText().equals("") || mima_field.toString().equals("")) {JOptionPane.showMessageDialog(null, "登录名和密码不能为空!");} else {if (guanliyuan_radioButton.isSelected()) {if (zhanghao_field.getText().equals("admin") && String.valueOf(mima_field.getPassword()).equals("admin")) {new AdminUI(false);} else {JOptionPane.showMessageDialog(null, "管理员账号或密码错误!");zhanghao_field.setText("");mima_field.setText("");}} else {UserService userService = new UserService();vo.User user = new User();user.setUsername(zhanghao_field.getText());userService.showUser(user);if (userService.showUser(user).getUsername().equals(zhanghao_field.getText())) {if (userService.showUser(user).getUser_password().equals(String.valueOf(mima_field.getPassword()))) {new UserUI(zhanghao_field.getText());} else {JOptionPane.showMessageDialog(null, "密码错误!");mima_field.setText("");}} else {JOptionPane.showMessageDialog(null, "不存在此账号,请注册!");zhanghao_field.setText("");mima_field.setText("");}}}} else if (source == zhuce_button) {new Enrol();}}
}	

八、总结

通过本博客,我们了解了一个基于Java Swing的车辆租赁管理系统的数据库设计和开发流程。这个系统可以帮助车辆租赁公司更好地管理业务,提高效率,提供更好的服务。

九、联系与交流

:969060742 完整代码、sql、程序资源

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/305317.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【C语言】程序练习(二)

大家好&#xff0c;这里是争做图书馆扫地僧的小白。 个人主页&#xff1a;争做图书馆扫地僧的小白_-CSDN博客 目标&#xff1a;希望通过学习技术&#xff0c;期待着改变世界。 目录 前言 一、运算符练习 1 算术运算符 1.1 练习题&#xff1a; 2 自加自减运算符 3 关系运…

最新AI系统ChatGPT网站系统源码,Midjourney绘画,GPT语音对话+ChatFile文档对话总结+DALL-E3文生图+思维导图一站式解决方案

一、前言 SparkAi创作系统是基于ChatGPT进行开发的Ai智能问答系统和Midjourney绘画系统&#xff0c;支持OpenAI-GPT全模型国内AI全模型。本期针对源码系统整体测试下来非常完美&#xff0c;可以说SparkAi是目前国内一款的ChatGPT对接OpenAI软件系统。那么如何搭建部署AI创作Ch…

射频PCB电路布局设计及布线注意事项

在电子产品和设备中&#xff0c;电路板是一个不可缺少的部件&#xff0c;它起着电路系统的电气和机械等的连接作用。如何将电路中的元器件按照一定的要求&#xff0c;在PCB上排列组合起来&#xff0c;是PCB设计师的主要任务之一。布局设计不是简单的将元器件在PCB上排列起来&am…

【ZYNQ】教你用 Vivado HLS 快速设计一个 IP

Xilinx 推出的 Vivado HLS 工具可以直接使用 C、C或 System C 来对 Xilinx 系列的 FPGA 进行编程&#xff0c;从而提高抽象的层级&#xff0c;大大减少了使用传统 RTL 描述进行 FPGA 开发所需的时间。 Vivado HLS 的功能简单地来说就是把 C、C 或 SystemC 的设计转换成 RTL 实…

分布式事务的8种解决方案(荣耀典藏版)

大家好&#xff0c;我是月夜枫&#xff0c;在上篇文章中&#xff0c;我们已经谈到了分布式中至关重要的两个理论&#xff1a;CAP 理论和 BASE 理论。 今天将带大家探讨分布式事务里的“八奇技”&#xff0c;帮助大家在实际的分布式系统中更好地运用事务。 时光穿梭机&#xff…

Redis缓存雪崩、缓存击穿、缓存穿透

1. 什么是缓存雪崩 当我们提到缓存系统中的问题&#xff0c;缓存雪崩是一个经常被讨论的话题。缓存雪崩是指在某一时刻发生大量的缓存失效&#xff0c;导致瞬间大量的请求直接打到了数据库&#xff0c;可能会导致数据库瞬间压力过大甚至宕机。尤其在高并发的系统中&#xff0c;…

CodeWhisperer——轻松使用一个超级强大的工具

CodeWhisperer 简介 CodeWhisperer是亚⻢逊云科技出品的一款基于机器学习的通用代码生成器&#xff0c;可实时提供代码建议。 CodeWhisperer有以下几个主要用途&#xff1a; 解决编程问题&#xff0c;提供代码建议&#xff0c;学习编程知识等等&#xff0c;并且CodeWhisper…

第一节 初始化项目

系列文章目录 第一节 初始化项目 文章目录 操作步骤 总结 操作步骤 打开cmd 输入 vue ui 在打开的网页中点击“创建”&#xff0c;复制文件夹路径并粘贴点击“在此创建新项目” 输入项目名称 点击下一步选择手动配置 选择babel、router、vuex、css pre-processors、 linter建…

大数据与人工智能|万物皆算法(第三节)

要点一&#xff1a;数据与智能的关系 1. 一切的核心都是数据&#xff0c;数据和智能之间是密切相关的。 数据是对客观现实的描述&#xff0c;而信息是数据转化而来的。 例如&#xff0c;24是数据&#xff0c;但说“今天的气温是24摄氏度”是信息&#xff0c;而说“班可以分成24…

Unity TextMeshPro中文字体的转换与显示

Unity TextMeshPro功能非常强大&#xff0c;但是我们用默认的字体格式却无法显示中文&#xff0c;必须把字体转换之后才能正常显示中文。 具体转换方法&#xff1a; 1、准备好字体&#xff0c;ttf或otf格式都可以&#xff0c;如&#xff1a;SOURCEHANSANSCN-NORMAL.OTF 2、准…

Elasticsearch8.x结合OpenAI CLIP模型实现图搜图及文搜图功能

前言 在当今大数据时代&#xff0c;搜索引擎已经是许多应用的核心组件之一&#xff0c;近年随着大模型以及AI技术&#xff08;如&#xff1a;自然语言处理NLP&#xff09;的流行&#xff0c;这些技术的结合将会创造出更多的应用场景&#xff0c;比如&#xff1a;电商商品搜索、…

数据驱动与数据安全,自动驾驶看得见的门槛和看不见的天花板

作者 |田水 编辑 |德新 尽管心理有所准备&#xff0c;2023年智能驾驶赛道的内卷程度还是超出了大多数人的预期。 这一年&#xff0c;汽车价格战突然开打&#xff0c;主机厂将来自销售终端的价格压力&#xff0c;传导到下游智驾供应商&#xff0c;于是&#xff0c;市面上出现…