基于java+mysql的swing+mysql车租赁管理系统(java+gui+文档)

基于java+mysql的swing+mysql车租赁管理系统(java+gui+文档)

运行环境

Java≥8、MySQL≥5.7

开发工具

eclipse/idea/myeclipse/sts等均可配置运行

适用

课程设计,大作业,毕业设计,项目练习,学习演示等

功能说明

基于java+mysql的Swing+MySQL车租赁管理系统(java+gui+文档)

功能介绍:

登陆界面、管理员界面、用户界面、汽车租赁文档

	public void actionPerformed (ActionEvent e) {
		Object source = e.getSource();
		String username = null;
		String adminname = null;
		String admin_password = null;
		String user_password = null;
		if (source == login_button)//如果点击的是登陆按钮,就会判断radiobutton选择的是什么,做出相应的响应
		{
			if(!yonghu_radioButton.isSelected()&&!guanliyuan_radioButton.isSelected())//radiobutton没选择
			{
				JOptionPane.showMessageDialog(null, "请选择身份!");
			}
			else if (zhanghao_field.getText().equals("") || mima_field.getText().equals(""))
			{// 判断是否输入了用户名和密码
				JOptionPane.showMessageDialog(null, "登录名和密码不能为空!");
			} 
			else 
			{
				this.connDB();
				try
				{
					stmt = con.createStatement();
				} 
				catch (SQLException e2)
				{
					e2.printStackTrace();
				}
				if(guanliyuan_radioButton.isSelected())//如果选择的是管理员的按钮
				{	
				
				 try {
						
						String sql ="select * from admin where adminname ='"+zhanghao_field.getText()+"'";
						rs = stmt.executeQuery(sql);
						if(rs.next())
						{
							adminname = rs.getString(1);
							admin_password = rs.getString(2);
							if(!mima_field.getText().equals(admin_password))
							{
								JOptionPane.showMessageDialog(null, "密码错误!");
					 
					 i++;
					 success = 1;
				 }
				 this.closeDB();
				 repaint();//刷新一下
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			 if(success == 0)
			 {
				 JOptionPane.showMessageDialog(null, "您还没有租用任何车辆!");
			 }
		}
		
		
	}

}
package Guanliyuan;

	{
		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");
			}
			this.closeDB();
		} catch (SQLException e2) {
			e2.printStackTrace();
		}
		
		field2.setText(cartype);
		field3.setText(carower);
		field4.setText(price);
		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());
		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));
				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();
								}
								else 
								{
									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();
								
		
	}
	
	public void connDB() { // 连接数据库
		try {
			Class.forName("com.mysql.jdbc.Driver");//注册驱动
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		try {//创建连接
			con = DriverManager.getConnection("jdbc:mysql://localhost:3306/project?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai&autoReconnect=true&failOverReadOnly=false&allowPublicKeyRetrieval=true&allowMultiQueries=true&zeroDateTimeBehavior=convertToNull",
					"root", "123456");
			
		} catch (SQLException e) {
			e.printStackTrace();
			
		}
		
	}

	public void closeDB() // 关闭连接
	{
		try {
			stmt.close();
			con.close();
		} 
		catch (SQLException e) {
			e.printStackTrace();
		}
		
	}
	@Override
	public void actionPerformed(ActionEvent e) {
		Object source = e.getSource();
	 if (source == buttonOfFanHui)
		{
			this.dispose();
			new Yonghuduan(username);
		}
		
			
			
		}
		
	
		
	

}
package Guanliyuan;
 * 信息录入界面
 */

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);
							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 == buttonOfXiangXi)
		{
			this.dispose();
			new Xiangxi_yonghu(field2.getText(),username);
		}

		else if(source == buttonOfLogout)
		{
			this.dispose();
			new Login();
			
		}
		else if(source == buttonOfWo)//点击我租的车辆信息
		{
			int success = 0;//用来判断 有没有 没自己租用的车辆
			 int i=0;
			 while(i<50)
			 {
				 a[i][0]=" ";
				 a[i][1]=" ";
				 a[i][2]=" ";
				 a[i][3]=" ";
				 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 block
			e1.printStackTrace();
		}
		 this.closeDB();
	}
	@Override
	public 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());
			 a[i][1]=" ";
			 a[i][2]=" ";
			 a[i][3]=" ";
			 a[i][4]=" ";
			 a[i][5]=" ";
			 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");
				 a[i][0]=number;
				 a[i][1]=cartype;
				 a[i][2]=carower;
				 a[i][3]=price;
				 a[i][4]=color;
				 a[i][5]=hire;
				 i++;
				 
			 }
			 this.closeDB();
			 repaint();
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		 this.closeDB();
	}
	
	public void actionPerformed(ActionEvent e) {
		Object source = e.getSource();
		if(source == buttonOfKe)//点击可以租用车辆的按钮
		{
			int success = 0;//用来判断 有没有 没被租用的车辆,如果能返回 “否” 值的集,则赋值为 1 
		
		add(baseBox);
		
	}
	
	public void connDB() { // 连接数据库
		try {
			Class.forName("com.mysql.jdbc.Driver");//注册驱动
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		try {//创建连接
			con = DriverManager.getConnection("jdbc:mysql://localhost:3306/project?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai&autoReconnect=true&failOverReadOnly=false&allowPublicKeyRetrieval=true&allowMultiQueries=true&zeroDateTimeBehavior=convertToNull",
					"root", "123456");
			
		} 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())
		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();
			}
			
		}
		
	}

}
package Yonghu;

/*
 * 
 * 这个界面详细信息 用户端
 */
public class Xiangxi_yonghu 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  Xiangxi_yonghu(String number,String username)
	{
		
		init();
		setVisible(true);
//		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(500, 200, 620, 360);
		setTitle("用户详细信息界面");
		this.number = number;
		this.username = username;
		setArea();
	}
	
	public  void setArea()//打开界面就把 数据库中的详细信息写入到area中
	{
		this.connDB();
		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));
//		
//		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("jdbc:mysql://localhost:3306/project?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai&autoReconnect=true&failOverReadOnly=false&allowPublicKeyRetrieval=true&allowMultiQueries=true&zeroDateTimeBehavior=convertToNull",
					"root", "123456");
			
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
	}

	public void closeDB() // 关闭连接
	{
		try {
			stmt.close();
			con.close();
			field5.setText("");
			field6.setText("");
			
			
		}
		
		
	}

	
}
package Guanliyuan;

/*
 * 信息录入界面
 */

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);
			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));
	
	
	
	

package Index;

public class Zhuce extends JFrame implements ActionListener {

	JTextField field1;
	JPasswordField field2,field3;
	JButton buttonOfZhuce,buttonOfFanhui;
	Box box1,box2,box3,box4,baseBox;
	Connection con = null;
	Statement stmt = null;
	ResultSet rs = null;
	
	public Zhuce()
	{
		setLayout(new FlowLayout());
		init();
		setVisible(true);
//		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(500, 200, 500, 450);
		setTitle("注册界面");
	}
	
					stmt.executeUpdate(sqlString);
				} catch (SQLException e1) 
				{
					e1.printStackTrace();
				}
				JOptionPane.showMessageDialog(null, "提交成功!");
				this.closeDB();
				this.dispose();
				new Guanliyuan(true);
			}
			else
			{
				JOptionPane.showMessageDialog(null, "请点击编辑变换成编辑状态!");
			}
			
		}
		
	}

}
package Yonghu;

/*
 * 
 * 这个界面详细信息 用户端
 */
public class Xiangxi_yonghu 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  Xiangxi_yonghu(String number,String username)
	{
		
		init();
		setVisible(true);
//		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}
	
	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));
/*
 * 详细详细的管理员编辑页面
 */
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);
		
		
				 this.closeDB();
				 repaint();
			} catch (SQLException e1){
				e1.printStackTrace();
			}
			 
			
		}
		else if (source == buttonOfQyueding)//点击 租用的确定键
		{
			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()+"' and hire = '否'";//获取输入的 序号并且 没被租用的信息
					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)//确认框
						{	
							try
							{
								stmt = con.createStatement();
								String sql2 = "update  car_information set hire = '是',username = '"+username+"' where number='"+field.getText()+"';";//把租用的赋值为 是 
								stmt.executeUpdate(sql2);
							}
							catch (SQLException e1)
							{
								e1.printStackTrace();
							}
							this.closeDB();
							repaint();
		
		
	}
	
	
	public void connDB() { // 连接数据库
		try {
			Class.forName("com.mysql.jdbc.Driver");//注册驱动
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		try {//创建连接
			con = DriverManager.getConnection("jdbc:mysql://localhost:3306/project?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai&autoReconnect=true&failOverReadOnly=false&allowPublicKeyRetrieval=true&allowMultiQueries=true&zeroDateTimeBehavior=convertToNull",
					"root", "123456");
			
		} 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++;
	
	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);
	{
		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;

请添加图片描述

请添加图片描述
请添加图片描述
请添加图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,为了实现基于Java+Swing+MySQL的汽租赁管理系统,我们需要进行以下几个步骤: 1. 创建MySQL数据库并设计表结构,包括辆信息表、客户信息表、订单信息表等。 2. 使用Java JDBC连接MySQL数据库,编写Java代码来实现数据的增删改查等基本操作。 3. 使用Swing GUI框架设计系统的用户界面,包括登录界面、主界面、辆信息管理界面、客户信息管理界面、订单信息管理界面等。 4. 将Java代码和MySQL数据库连接起来,实现系统的功能,例如辆信息的添加、查询、修改、删除,客户信息的添加、查询、修改、删除等。 5. 针对不同的用户权限,设置不同的操作权限,例如管理员可以对系统进行管理,普通用户只能进行租赁等操作。 6. 对系统进行测试和调试,确保系统稳定性和安全性。 这里提供一个简单的代码示例,用于连接MySQL数据库并进行查询操作: ``` import java.sql.*; public class Demo { public static void main(String[] args) { try { // 驱动程序名 String driver = "com.mysql.jdbc.Driver"; // 数据库URL String url = "jdbc:mysql://localhost:3306/test"; // 数据库用户名 String user = "root"; // 数据库密码 String password = "123456"; // 加载驱动程序 Class.forName(driver); // 连接数据库 Connection conn = DriverManager.getConnection(url, user, password); // 创建Statement对象 Statement stmt = conn.createStatement(); // 查询操作 String sql = "SELECT * FROM user"; ResultSet rs = stmt.executeQuery(sql); // 处理结果集 while(rs.next()){ System.out.println(rs.getString("name")); } // 关闭结果集、Statement和连接 rs.close(); stmt.close(); conn.close(); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } } } ``` 此外,还需要编写Swing GUI界面和其他相关代码来实现完整的汽租赁管理系统
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值