Java课程设计——汽车信息租赁信息管理系统

article/2025/6/23 2:20:08

一.功能需求

       需求分析是发现需求,分析求精,逻辑建模,需求规约的过程,其的目的是为了全面获取软件需求,准确理解业务逻辑。车辆租赁系统具有以下基本功能。

  1. 用户管理:

包括用户的注册,登陆等,没有账户的用户可以注册会员,登录,通过分类查询车辆,以及查看其详细信息。

  1. 车源管理:

包括车辆信息的删除,添加,修改等,管理员能够向数据库中发布车辆信息,包括车辆的车型,价格,车主等信息。

  1. 车源信息查找

用户可以在窗口上直接浏览车辆基本信息,也可以按照不同的要求方式对车辆信息进行查询,这样用户可以方便的找到自己想要的车源,人性化的查找方式为用户带来了极大的便利。

二.系统解决的问题

   本系统主要完成前台浏览(用户注册,信息修改,车辆浏览),后台管理(车辆信息的录入,管理员登录)等功能。通过以上功能实现简单,便捷的租车系统。

车辆浏览:所有人都可以操作,顾客可以随意浏览车辆信息,按照车辆的序号排序,在点击按钮后,可以在表格中显示出可以租用车辆的信息,可以让用户选择。

车辆租用:顾客在浏览车辆信息后,可以根据自身需求选择所需租用的车辆,输入车辆的序号后,点击确定按钮,可以成功租用车辆,并且该车辆是否被租用的信息会自动更改为已被租用,如果用户租用已被租用的车辆则租用失败,无法租用成功。

车辆管理:该功能只能由管理员完成,由管理员完成对车辆信息的录入包括录入车辆的车主,价格,是否被租用等信息,并可以删除车辆信息。

会员管理:该功能由管理员完成,管理员可以注册其他的用户帐号,并将帐号密码录入数据库中。

各个模块的实现方法描述 

 运行结果截图

 

 

package Guanliyuan;
import java.awt.BorderLayout;import Util.DbUtil;
import Yonghu.*;import java.awt.Container;
import java.awt.FlowLayout;
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 java.text.FieldPosition;import javax.naming.InitialContext;
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.JScrollBar;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.table.TableColumn;import Index.*;
public class Guanliyuan extends JFrame implements ActionListener{/** * 管理员端的界面*/JTable table;JLabel label1,label2,label3,label4;Object a[][];Object name[] = {"编号","车型","车主","价格(元/天)","颜色","是否被租用","租用的用户"};JButton buttonOfXinxiluru,buttonOfXinxiliulan,buttonOfDelete,buttonOfLogout,buttonOfXiangXi,buttonOfXiugai;Box box1,box2;JTextField field,field2,field3;JPanel jPanel4,jPanel5;Connection con = null;Statement stmt = null;ResultSet rs = null;public Guanliyuan(Boolean success){init();setVisible(true);
//		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);setBounds(500, 200, 625, 490);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);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("待查询详情的编号:");field = new JTextField();field2 = new JTextField();field3 = 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(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中。//		jPanel1 = new JPanel();
//		jPanel2 = new JPanel();
//		jPanel3 = new JPanel();
//		jPanel4 = new JPanel();
//		jPanel5 = new JPanel();
//		
//		jPanel1.setLayout(new BorderLayout());
//		jPanel1.add(label2,BorderLayout.NORTH);
//		jPanel1.add(field,BorderLayout.CENTER);
//		jPanel1.add(buttonOfDelete,BorderLayout.SOUTH);//把删除的模块放一个jpanel1里
//		
//		jPanel2.setLayout(new BorderLayout());
//		jPanel2.add(jPanel1,BorderLayout.NORTH);
//		jPanel2.add(buttonOfLogout,BorderLayout.CENTER);//把删除模块和 退出登录模块放一个jpanel2里
//		
//		jPanel3.setLayout(new BorderLayout());
//		jPanel3.add(buttonOfXinxiluru,BorderLayout.NORTH);
//		jPanel3.add(buttonOfXinxiliulan,BorderLayout.CENTER);//信息录入浏览按钮放到jpanel3里
//		
//		jPanel4.setLayout(new BorderLayout());
//		jPanel4.add(jPanel3,BorderLayout.NORTH);
//		jPanel4.add(jPanel2,BorderLayout.CENTER);//把jpanel 2 3 放到 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_information";rs = stmt.executeQuery(sql);while(rs.next()){String number = rs.getString("number");String cartype = rs.getString("cartype");String carower = rs.getString("carower");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) {// TODO Auto-generated catch blocke1.printStackTrace();}this.closeDB();}@Overridepublic void actionPerformed(ActionEvent e) {Object source = e.getSource();if(source == buttonOfXinxiluru)//点击信息修改按钮{this.dispose();new Luru();}else if(source == buttonOfXinxiliulan)//点击信息浏览按钮{xinXiLiuLan();}else if(source == buttonOfXiugai)//点击修改按钮{if(field2.getText().equals("")){JOptionPane.showMessageDialog(null, "输入修改车型的编号!");}else{this.dispose();new Xiugai(field2.getText());}}else if(source == buttonOfXiangXi)//点击详细信息按钮{this.dispose();new Xiangxi(field3.getText());}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_information where number='"+field.getText()+"';";
//										stmt.executeUpdate(sql2);
//									}
//									catch (SQLException e1)
//									{
//										e1.printStackTrace();
//									}
//									this.closeDB();
//									repaint();
//									field.setText("");
//									JOptionPane.showMessageDialog(null,"删除成功!");
//									xinXiLiuLan();}}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();}else if(n == JOptionPane.NO_OPTION){}}else{JOptionPane.showMessageDialog(null, "没有此编号的车辆信息!");}} catch (HeadlessException e1) {e1.printStackTrace();} catch (SQLException e1) {e1.printStackTrace();}}}else if(source == buttonOfLogout)//退出{this.dispose();new Login();}}}

 

package Guanliyuan;
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.JTextField;
/** 信息录入界面*/import Util.DbUtil;public class Luru extends JFrame implements ActionListener {JTextField field1,field2,field3,field4,field5,field6;Box box1,box2,box3,box4,box5,box6,box7,baseBox;JButton buttonOfQueDing,buttonOfReset,buttonOfQuXIAO;Connection con = null;Statement stmt = null;ResultSet rs = null;public Luru(){init();setVisible(true);
//		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);setBounds(550, 200, 550, 280);setTitle("车辆信息录入界面");}void init(){JLabel label1 = new JLabel(" 序        号  : ");JLabel label2 = new JLabel(" 车        型  : ");JLabel label3 = new JLabel(" 车        主  : ");JLabel label4 = new JLabel("价格(元/天):");JLabel label5 = new JLabel(" 颜        色  : ");JLabel label6 = new JLabel("已租用(是/否):");field1 = new JTextField();field2 = new JTextField();field3 = new JTextField();field4 = new JTextField();field5 = new JTextField();field6 = new JTextField();buttonOfQueDing = new JButton("提交");buttonOfReset = new JButton("重置");buttonOfQuXIAO = new JButton("取消");buttonOfQueDing.addActionListener(this);buttonOfQuXIAO.addActionListener(this);buttonOfReset.addActionListener(this);box1 = Box.createHorizontalBox();box1.add(box1.createHorizontalStrut(8));box1.add(label1);box1.add(box1.createHorizontalStrut(8));box1.add(field1);box1.add(box1.createHorizontalStrut(8));box2 = Box.createHorizontalBox();box2.add(box2.createHorizontalStrut(8));box2.add(label2);box2.add(box2.createHorizontalStrut(8));box2.add(field2);box2.add(box2.createHorizontalStrut(8));box3 = Box.createHorizontalBox();box3.add(box3.createHorizontalStrut(8));box3.add(label3);box3.add(box3.createHorizontalStrut(8));box3.add(field3);box3.add(box3.createHorizontalStrut(8));box4 = Box.createHorizontalBox();box4.add(box4.createHorizontalStrut(8));box4.add(label4);box4.add(box4.createHorizontalStrut(8));box4.add(field4);box4.add(box4.createHorizontalStrut(8));box5 = Box.createHorizontalBox();box5.add(box5.createHorizontalStrut(8));box5.add(label5);box5.add(box5.createHorizontalStrut(8));box5.add(field5);box5.add(box5.createHorizontalStrut(8));box6 = Box.createHorizontalBox();box6.add(box6.createHorizontalStrut(8));box6.add(label6);box6.add(box6.createHorizontalStrut(8));box6.add(field6);box6.add(box6.createHorizontalStrut(8));box7 = Box.createHorizontalBox();box7.add(box7.createHorizontalStrut(8));box7.add(buttonOfQueDing);box7.add(box7.createHorizontalStrut(8));box7.add(buttonOfQuXIAO);box7.add(box7.createHorizontalStrut(8));box7.add(buttonOfReset);box7.add(box7.createHorizontalStrut(8));baseBox = Box.createVerticalBox();baseBox.add(Box.createVerticalStrut(15));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(box4);baseBox.add(Box.createVerticalStrut(10));baseBox.add(box5);baseBox.add(Box.createVerticalStrut(10));baseBox.add(box6);baseBox.add(Box.createVerticalStrut(10));baseBox.add(box7);baseBox.add(Box.createVerticalStrut(15));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);} catch (SQLException e) {e.printStackTrace();}}public void closeDB() // 关闭连接{try {stmt.close();con.close();} catch (SQLException e) {e.printStackTrace();}}public static boolean isNumeric(String str){for (int i = str.length();--i>=0;){   if (!Character.isDigit(str.charAt(i))){return false;}}return true;}//判断 编号输入的是不是整数!@Overridepublic void actionPerformed(ActionEvent e) {Object source = e.getSource();String number = field1.getText();String cartype = field2.getText() ;String carower = field3.getText() ;String price = field4.getText();String color = field5.getText();String hire = field6.getText();
//		if(field6.getText().equals("是")&&field6.getText().equals("已经")&&field6.getText().equals("已租用")&&field6.getText().equals("已"))
//		{
//			hire = "1";
//		}
//		else 
//		{
//			hire = "0";
//		}if(source == buttonOfQueDing){if(number.equals("")||cartype.equals("")||carower.equals("")||price.equals("")||color.equals("")||hire.equals("")){JOptionPane.showMessageDialog(null, "请填写完整!");}else if(!isNumeric(number)){JOptionPane.showMessageDialog(null, "序号 请输入整数!");}else{this.connDB();try {int numberint = Integer.parseInt(field1.getText());stmt = con.createStatement();String str = "insert into car_information (number,cartype,carower,price,color,hire)values('"+numberint+"','"+cartype+"','"+carower+"','"+price+"','"+color+"','"+hire+"');";stmt.executeUpdate(str);JOptionPane.showMessageDialog(null, "录入成功!");this.closeDB();this.dispose();new Guanliyuan(true);} catch (SQLException e1) {
//				e1.printStackTrace();JOptionPane.showMessageDialog(null, "此编号已经被使用,请换一个编号!");}}}else if(source == buttonOfQuXIAO){this.dispose();new Guanliyuan(false);}else if(source == buttonOfReset){//field1.setText("");field2.setText("");field3.setText("");field4.setText("");field5.setText("");field6.setText("");}}}
package Guanliyuan;
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;public class Xiangxi 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 Xiangxi(String number){init();setVisible(true);
//		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);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_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,"没有此编号的车辆的详细信息!");new Guanliyuan(true);}} catch (HeadlessException e2) {e2.printStackTrace();} catch (SQLException e2) {e2.printStackTrace();}}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 Guanliyuan(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 Guanliyuan(true);}else{JOptionPane.showMessageDialog(null, "请点击编辑变换成编辑状态!");}}}}
package Guanliyuan;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextArea;/** 详细详细的管理员编辑页面*/
public class Xinxitijiao extends JFrame implements ActionListener{JTextArea area;Box box1,baseBox,box2,baseBox2;JButton buttonOfTijiao,buttonOfFanHui;public Xinxitijiao(){init();setVisible(true);
//		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);setBounds(500, 200, 620, 360);setTitle("详细信息编辑界面");}void init(){JLabel label = new JLabel("车辆的详细信息:");area = new JTextArea(10, 10);buttonOfTijiao = new JButton("提交");buttonOfFanHui = new JButton("返回");box1 = Box.createVerticalBox();box1.add(box1.createVerticalStrut(8));box1.add(label);box1.add(area);box2 = Box.createHorizontalBox();box2.add(box2.createHorizontalStrut(8));box2.add(buttonOfTijiao);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);}@Overridepublic void actionPerformed(ActionEvent e) {// TODO Auto-generated method stub}}
package Guanliyuan;
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.JTextField;import Util.DbUtil;
/** 信息录入界面*/public class Xiugai extends JFrame implements ActionListener {JTextField field1,field2,field3,field4,field5,field6;Box box1,box2,box3,box4,box5,box6,box7,baseBox;JButton buttonOfQueDing,buttonOfReset,buttonOfQuXIAO;Connection con = null;Statement stmt = null;ResultSet rs = null;String number;public Xiugai(String number){init();setVisible(true);
//		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);setBounds(550, 200, 550, 280);setTitle("车辆信息修改界面");this.number = number;setText();}void init(){JLabel label1 = new JLabel(" 序        号  : ");JLabel label2 = new JLabel(" 车        型  : ");JLabel label3 = new JLabel(" 车        主  : ");JLabel label4 = new JLabel(" 价        格  : ");JLabel label5 = new JLabel(" 颜        色  : ");JLabel label6 = new JLabel("是否被租用:");field1 = new JTextField();field2 = new JTextField();field3 = new JTextField();field4 = new JTextField();field5 = new JTextField();field6 = new JTextField();buttonOfQueDing = new JButton("提交");buttonOfQueDing.addActionListener(this);buttonOfReset = new JButton("重置");buttonOfReset.addActionListener(this);buttonOfQuXIAO = new JButton("取消");buttonOfQuXIAO.addActionListener(this);box1 = Box.createHorizontalBox();box1.add(box1.createHorizontalStrut(8));box1.add(label1);box1.add(box1.createHorizontalStrut(8));box1.add(field1);box1.add(box1.createHorizontalStrut(8));box2 = Box.createHorizontalBox();box2.add(box2.createHorizontalStrut(8));box2.add(label2);box2.add(box2.createHorizontalStrut(8));box2.add(field2);box2.add(box2.createHorizontalStrut(8));box3 = Box.createHorizontalBox();box3.add(box3.createHorizontalStrut(8));box3.add(label3);box3.add(box3.createHorizontalStrut(8));box3.add(field3);box3.add(box3.createHorizontalStrut(8));box4 = Box.createHorizontalBox();box4.add(box4.createHorizontalStrut(8));box4.add(label4);box4.add(box4.createHorizontalStrut(8));box4.add(field4);box4.add(box4.createHorizontalStrut(8));box5 = Box.createHorizontalBox();box5.add(box5.createHorizontalStrut(8));box5.add(label5);box5.add(box5.createHorizontalStrut(8));box5.add(field5);box5.add(box5.createHorizontalStrut(8));box6 = Box.createHorizontalBox();box6.add(box6.createHorizontalStrut(8));box6.add(label6);box6.add(box6.createHorizontalStrut(8));box6.add(field6);box6.add(box6.createHorizontalStrut(8));box7 = Box.createHorizontalBox();box7.add(box7.createHorizontalStrut(8));box7.add(buttonOfQueDing);box7.add(box7.createHorizontalStrut(8));box7.add(buttonOfQuXIAO);box7.add(box7.createHorizontalStrut(8));box7.add(buttonOfReset);box7.add(box7.createHorizontalStrut(8));baseBox = Box.createVerticalBox();baseBox.add(Box.createVerticalStrut(15));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(box4);baseBox.add(Box.createVerticalStrut(10));baseBox.add(box5);baseBox.add(Box.createVerticalStrut(10));baseBox.add(box6);baseBox.add(Box.createVerticalStrut(10));baseBox.add(box7);baseBox.add(Box.createVerticalStrut(15));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);} catch (SQLException e) {e.printStackTrace();}}public void closeDB() // 关闭连接{try {stmt.close();con.close();} catch (SQLException e) {e.printStackTrace();}}public void setText()//此函数功能是 把数据库 需要修改的信息 都打印到界面的文本框中{String cartype =null;String carower=null;String price=null;String color=null;String hire=null;field1.setText(number);field1.setEnabled(false);this.connDB();try {stmt = con.createStatement();//String sql = "select * from car_information (cartype,carower,price,color,hire);";String sql = "select * from car_information where number = '"+number+"';";rs = stmt.executeQuery(sql);if(rs.next()){cartype = rs.getString("cartype");carower = rs.getString("carower");price = rs.getString("price");color = rs.getString("color");hire = rs.getString("hire");}else{JOptionPane.showMessageDialog(null, "不存在该编号!");this.dispose();new Guanliyuan(true);//为ture}this.closeDB();} catch (SQLException e2) {e2.printStackTrace();}field2.setText(cartype);field3.setText(carower);field4.setText(price);field5.setText(color);field6.setText(hire);}public void actionPerformed(ActionEvent e) {String cartype =null;String carower=null;String price=null;String color=null;String hire=null;	 Object source = e.getSource();this.connDB();cartype = field2.getText() ;carower = field3.getText() ;price = field4.getText();color = field5.getText();hire = field6.getText();if(source == buttonOfQueDing)//点击确定按钮{if(cartype.equals("")||carower.equals("")||price.equals("")||color.equals("")||hire.equals("")){JOptionPane.showMessageDialog(null, "请填写完整!");}else{int n  = JOptionPane.showConfirmDialog(this, "确定修改此车辆信息?","确认对话框",JOptionPane.YES_NO_OPTION);//确认文本框if(n == JOptionPane.YES_OPTION){this.connDB();try {stmt = con.createStatement();String str =  "update car_information set cartype='"+cartype+"',carower='"+carower+"',price='"+price+"',color='"+color+"',hire='"+hire+"' where number = '"+number+"';";stmt.executeUpdate(str);JOptionPane.showMessageDialog(null, "修改成功!");this.closeDB();this.dispose();new Guanliyuan(true);//为ture} catch (SQLException e1) {e1.printStackTrace();}}else {}}}else if(source == buttonOfQuXIAO){this.dispose();new Guanliyuan(false);}else if(source == buttonOfReset){field2.setText("");field3.setText("");field4.setText("");field5.setText("");field6.setText("");}}}


http://chatgpt.dhexx.cn/article/nb5HEEvB.shtml

相关文章

Java GUI+SQL Server开发车辆管理系统

Java GUISQL Server开发车辆管理系统 一、程序功能设计 本项目为“车辆管理系统”&#xff0c;需包含一下功能&#xff1a; 1)车辆管理模块&#xff0c;增删查改车辆信息 2)租车管理模块&#xff0c;增删查改租车记录 3)换车管理模块&#xff0c;增删查改换车记录 4)修车…

Java+MySQL汽车租赁管理系统课程设计

wx供重浩&#xff1a;创享日记 对话框发送&#xff1a;汽车租赁系统 获取完整源码源文件视频演示文档资料等 一、 课程设计目的 1、综合运用Java程序设计课程和其他相关课程的理论和知识&#xff0c;掌握面向对象程序设计的一般方法、常用技术及技巧&#xff0c;树立良好的软件…

QT+SQL Server实现车辆管理系统 -简介

QTSQL Server 实现车辆管理系统 -简介 1.摘要2.界面展示及其功能介绍2.1 登录界面2.2 申请账户界面2.3 管理员界面2.3.1 添加车辆功能界面2.3.2 查询、删除、修改车辆信息功能界面2.3.3 添加司机功能界面2.3.4 查询、删除司机功能界面 2.4 普通用户界面2.4.1 查询车辆信息功能窗…

基于SpringBoot的汽车租赁管理系统

文末获取源码 一、项目技术栈 开发语言&#xff1a;Java Java开发工具&#xff1a;JDK1.8 后端框架&#xff1a;SpringBoot 前端&#xff1a;采用HTML和Vue相结合开发 数据库&#xff1a;MySQL5.7和Navicat管理工具结合 服务器&#xff1a;Tomcat8.5 开发软件&#xff1a;IDEA …

asp.net汽车出租信息管理系统VS开发sqlserver数据库web结构c#编程计算机网页项目

一、源码特点 ASP.NET 汽车出租信息管理系统是一套完善的web设计管理系统&#xff0c;系统具有完整的源代码和数据库&#xff0c;系统主要采用B/S模式开发。开发环境为vs2010&#xff0c;数据库为sqlserver2008&#xff0c;使用c# 语言开发 asp.net汽车出租信息管理系统…

数据库--汽车销售管理系统【课程设计】

目录 1.设计任务 1.1系统开发的背景 1.2系统开发的意义 1.3系统所应用的模块 2.需求分析 2.1功能分析 2.2数据流图 2.3数据字典 3.概念结构设计 4.逻辑结构设计 5.物理结构设计 5.1基本表 5.2视图 6.数据库实施 6.1 建立数据库表 6.2建立视图 7.数据库操作 目录 1.1系统开发的…

汽车租赁管理系统/汽车租赁网站/汽车管理系统

摘 要 21世纪的今天&#xff0c;随着社会的不断发展与进步&#xff0c;人们对于信息科学化的认识&#xff0c;已由低层次向高层次发展&#xff0c;由原来的感性认识向理性认识提高&#xff0c;管理工作的重要性已逐渐被人们所认识&#xff0c;科学化的管理&#xff0c;使信息存…

C#windows车库信息管理系统

中文摘要 为了提高车辆信息的管理效率&#xff0c;本课题使用C#语言和SQL Server数据库系统开发了一个WinForm类型的车库管理系统对车辆信息进行高效管理&#xff0c;以提升管理质量。本系统包含管理员登录注册、管理员信息修改模块、添加车辆信息模块、删除车辆信息模块、查找…

asp.net 汽车信息管理系统VS编程sqlserver数据库c#开发

一、源码特点 asp.net 汽车信息管理系统 是一套完善的WEB设计管理系统&#xff0c;系统具有完整的源代码和数据库&#xff0c;系统主要采用B/S模式开发。 下载地址&#xff1a;下载 https://download.csdn.net/download/qq_41221322/21516579 视频播放&#xff1a; …

基于Java+SQL的汽车销售管理系统

文章目录 1.前言系统概要附1: 建表语句附2: 项目整体结构附3: view包结构附4: utils包结构 2.基本功能介绍&#xff1a;2.1 登陆与注册2.2 主界面2.3 修改密码2.4 相应的操作数据界面2.5 增、删、查、改示例2.5.1 添加数据2.5.2 删除数据2.5.3 修改数据2.5.4 查询数据 3.食用该…

python判断闰年(leap year)

python判断闰年(leap year) 闰年的计算方法是“四年一闰,百年不闰,四百年再闰”,这就造成了在一些特殊年份,会出现八年一闰的现象。例如1896年为闰年,四年之后的1900年并不是闰年,直到再过四年之后的1904年才是闰年。也就是一般情况下年份能被4整除即为闰年,而整百年的…

python判断闰年程序_python实现闰年

广告关闭 腾讯云11.11云上盛惠 ,精选热门产品助力上云,云服务器首年88元起,买的越多返的越多,最高返5000元! 30个常用python实现:1、冒泡排序 ? 2、计算x的n次方的方法? 3、计算a*a + b*b + c*c + ...? 4、计算阶乘 n! ?5、列出当前目录下的所有文件和目录名? 6、…

python实现判断闰年

先来看条件&#xff1a; 如果我们要判断的年份是整百年&#xff0c;我们不能去除以4&#xff0c;而应该除以400。如1900年&#xff0c;因为这个年份是整百年&#xff0c;所以要除以400&#xff0c;1900/4004……300&#xff0c;不是400的倍数&#xff0c;所以1900年不是闰年&a…

python判断闰年

4.1 python 判断闰年 代码 yearint(input("请输入年份&#xff1a;")) if(year%40 and year%100 !0):print("是闰年&#xff01;") elif(year%4000):print("是闰年&#xff01;") else:print("不是闰年&#xff01;")运行结果截图&…

chatgpt赋能python:Python闰年的判断方法

Python闰年的判断方法 在Python编程中&#xff0c;经常需要判断某个年份是否是闰年。闰年是指能被4整除但不能被100整除的年份&#xff0c;或者能被400整除的年份。 闰年的判断方法在编程中非常常见&#xff0c;也非常简单。下面将介绍Python中三种实现闰年判断的方法。 方法…

Lingo 11安装教程

Lingo 11&#xff08;32/64&#xff09;位下载地址&#xff1a; 链接&#xff1a;http://pan.baidu.com/s/1pLFk5xL 密码&#xff1a;bt95 软件介绍&#xff1a; LINGO是Linear Interactive and General Optimizer的缩写&#xff0c;即“交互式的线性和通用优化求解器”&…

LINGO 11.0安装教程

文章目录 1. 安装步骤2. 下载地址 1. 安装步骤 解压压缩包&#xff0c;然后双击Lingo11.exe以运行它 单击No以禁用自动更新 开始使用 2. 下载地址 参考&#xff1a;Lingo多版本下载地址和安装教程

最优化问题求解及Lingo教程

介绍 Lingo是一款求解最优化问题的软件&#xff0c;可以用于求解非线性规划&#xff0c;也可以用于一些线性和非线性方程组的求解等&#xff0c;功能十分强大&#xff0c;是求解优化模型的最佳选择。 最优化问题 首先介绍一下什么是最优化问题。 最优化问题&#xff0c;即在…

lingo入门教程之三 --- 文件数据处理

有时候我们想输入的数据是在一个Excel表格或者其他什么形式中&#xff0c;或者说这里数据是实时变化的并不利于直接在程序中输入&#xff0c;耳而应该在程序之外将数据存储&#xff0c;实现数据与程序的分离存储&#xff0c;这个时候就涉及到程序与数据之间的传递 下面简要介绍…

lingo入门教程之一 初识lingo

lingo对于一些线性或者非线性的规划&#xff0c;优化问题非常有效 首先介绍一下&#xff0c;在lingo中运行程序时出现的页面&#xff08;在工具栏点击类似靶子一样的图标便可运行&#xff09; Solver status:求解器(求解程序)状态框 Model Class:当前模型的类型:LP&#xff0c;…