java-GUI实现汽车租赁管理系统
java-GUI实现汽车租赁管理系统孔子曰:“温故而知新”。大二时做的一个项目,现对其进行回顾、评价、找不足,后续会进行完善和改进工作一、问题描述二、基本要求三、设计思想四、数据库结构五、功能实现及主要代码孔子曰:“温故而知新”。大二时做的一个项目,现对其进行回顾、评价、找不足,后续会进行完善和改进工作一、问题描述在java开发环境下,使用程序设计实例选讲课程的内容,编程实现“汽车租赁管理系统”。
java-GUI实现汽车租赁管理系统
孔子曰:“温故而知新”。大二时做的一个项目,现对其进行回顾、评价、找不足,后续会进行完善和改进工作
序
一、问题描述
在java开发环境下,使用程序设计实例选讲课程的内容,编程实现“汽车租赁管理系统”。要求自行设计图形界面,对用户所填信息进行规定、采集和保存,并掌握Java数据库编程的基本步骤,通过jdbc连接mysql数据库实现。“汽车租赁管理系统”必须实现的三个功能:汽车基本信息管理、汽车租赁服务、汽车回收服务。
二、基本要求
1)汽车基本信息管理(车号,车型,颜色,购置年份,保险情况,现存油量,一天租金等),请完成该公司所有可以对外租赁汽车基本信息的增、删、改、查等操作。汽车的状态分为:正常待租、维修和租赁中,实现汽车状态查询。
2)汽车租赁服务,处于“正常待租”状态的汽车可以向外出租,处于“维修”状态现在不能出租。对于“正常待租”状态的汽车,进行出租操作时需要提供承租人的身份证信息,并提交一定数量的押金,完成“租赁”操作后,汽车应该从“正常”状态转换为“租赁中”状态。
3)汽车回收服务,只有处于“租赁中”状态的汽车可以执行“汽车回收”操作,根据该汽车每天的租赁费,加上租赁天数,算出租赁费。完成汽车回收操作后其状态从“租赁中”转换为“正常”或者“维修”。
三、设计思想
(1)定义一个Automobile类,设置汽车租赁系统主页面,其中包含四个按钮:“汽车基本信息管理”,“汽车租赁服务”,“汽车回收服务”,“退出本系统”。每个按钮在被点击时会进入实现相关功能的页面或者退出。在页面上插入图片作为装饰,并另设置一个线程用于设置滚动字幕。
(2)定义一个AutomobileMessage类,用于实现汽车基本信息管理,其中包含“增”、 “删”、 “改”、 “查”和“显示所有信息”等按钮,对应实现相应的功能。如果该车辆正处于“已租赁”状态,则拒绝删除;如果系统找不到用户输入的车号对应的汽车信息记录,也会通告用户并拒绝相应的操作。
(3)定义一个AutomobileLeasing类,用于实现汽车租赁服务,用户可通过点击“查看汽车租赁信息”按钮,并选择“正常待租”、“已租赁”、“维修中”三个按钮,来筛选查看系统内已存在的汽车租赁情况,然后再提供用户的自身信息,点击“确认”按钮即可租车。里面还需要设定对用户输入的信息格式的要求。
(4)定义一个AutomobileRecycle类,用于实现汽车回收服务,用户在提供身份证信息后即可查看详细租单,在提供身份证信息、所租车号、归还日期后可查看租金,勾选确认归还复选框并选择是否需要维修后,再按确认按钮即可归还车辆。
四、数据库结构
*分为两个表:汽车信息表(automobliemessage)和租赁信息表(lesseemessage)
automobilemessage表结构
各属性分别代表:
Cnumber —— 汽车牌号 (主键 非空)
Cmodel —— 汽车型号 (非空)
Ccolor —— 汽车颜色
Cdate —— 汽车生产日期
Cinsurance —— 汽车保险状态
Coil —— 汽车油量
Crent —— 汽车租金
conditions —— 租赁状态(非空)
lesseemessage表结构
各属性分别代表:
Lname —— 租赁者姓名 (非空)
Lgender —— 租赁者性别 (非空)
Lnation —— 租赁者民族
Ldate —— 租赁者生日
Laddress —— 租赁者地址
Lid —— 租赁者身份证号 (主键 非空)
Cnumber —— 所租车号 (主键 非空)
Lpay —— 租金支付方式 (非空)
五、功能实现及主要代码
1、增添汽车信息
class AutomobileMessageInsert {
JLabel jl1, jl2, jl3, jl4, jl5, jl6, jl7;
JTextField jt1, jt2, jt3, jt4, jt5, jt6, jt7;
Pattern pattern = Pattern.compile("^[1-9]\\d*$");
Pattern pattern1 = Pattern.compile("^[+]{0,1}(\\d+)$");
Pattern pattern2 = Pattern.compile("^((0{1}\\.\\d+)|([1-9]\\d*\\.{1}\\d+)|([1-9]+\\d*)|0)$");
Matcher matcher;
private final String conditions="正常待租";
Connection con;
Statement stmt;
void clearJTextField() {
jt1.setText("");
jt2.setText("");
jt3.setText("");
jt4.setText("");
jt5.setText("");
jt6.setText("");
jt7.setText("");
}
public AutomobileMessageInsert(String s,long Cnum) {
jf1 = new JFrame(s+"汽车信息");
jf1.setLayout(new FlowLayout());
jl1 = new JLabel("车号");
jl2 = new JLabel("车型");
jl3 = new JLabel("颜色");
jl4 = new JLabel("购置年份");
jl5 = new JLabel("保险情况(有/无)");
jl6 = new JLabel("现存油量(单位:mL)");
jl7 = new JLabel("一天租金(单位:元)");
sure = new JButton("确定");
back = new JButton("返回");
jt1 = new JTextField(15);
jt2 = new JTextField(15);
jt3 = new JTextField(15);
jt4 = new JTextField(15);
jt5 = new JTextField(10);
jt6 = new JTextField(10);
jt7 = new JTextField(15);
fh = new FocusHandler();
jt1.addFocusListener(fh);
jt4.addFocusListener(fh);
jt6.addFocusListener(fh);
jt7.addFocusListener(fh);
JPanel p1 = new JPanel();
JPanel p2 = new JPanel();
JPanel p3 = new JPanel();
JPanel p4 = new JPanel();
JPanel p5 = new JPanel();
JPanel p6 = new JPanel();
JPanel p7 = new JPanel();
JPanel p8 = new JPanel();
p1.add(jl1);
p1.add(jt1);
p2.add(jl2);
p2.add(jt2);
p3.add(jl3);
p3.add(jt3);
p4.add(jl4);
p4.add(jt4);
p5.add(jl5);
p5.add(jt5);
p6.add(jl6);
p6.add(jt6);
p7.add(jl7);
p7.add(jt7);
p7.add(sure);
p7.add(back);
area = new JTextArea(8, 45);
area.setEditable(false);
Font f = new Font("仿宋",Font.PLAIN,20);
area.setFont(f);
jf1.add(p1);
jf1.add(p2);
jf1.add(p3);
jf1.add(p4);
jf1.add(p5);
jf1.add(p6);
jf1.add(p7);
jf1.add(p8);
JScrollPane js = new JScrollPane(area);
js.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
js.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
jf1.add(js);
int width = 550;
int height = 420;
jf1.setBounds((d.width - width) / 2, (d.height - height) / 2, width, height);
jf1.setVisible(true);
sure.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(s.equals("插入")) {
try {
Class.forName("com.mysql.cj.jdbc.Driver");
con = DriverManager.getConnection(dbUrl, dbUser, password);
PreparedStatement addStmt = con.prepareStatement(
"insert into AutomobileMessage(Cnumber,Cmodel,Ccolor,Cdate,Cinsurance,Coil,Crent,conditions)values(?,?,?,?,?,?,?,?)");
long Cnumber = Long.parseLong(jt1.getText().trim());
String Cmodel = jt2.getText().trim();
String Ccolor = jt3.getText().trim();
String Cdate = jt4.getText().trim();
String Cinsurance = jt5.getText().trim();
int Coil = Integer.parseInt(jt6.getText().trim());
matcher = pattern2.matcher(jt7.getText().trim());
if (!matcher.matches()) {
JOptionPane.showMessageDialog(jt7, "请您输入一个大于等于0的数值型数据!");
jt7.setText("");
jt7.requestFocus();
return;
}
if(jt1.getText().equals("")||jt2.getText().equals("")||jt4.getText().equals("")||jt7.getText().equals("")) {
JOptionPane.showMessageDialog(null, "请您将信息补充完整!");
return;
}
double Crent = Double.parseDouble(jt7.getText().trim());
addStmt.setLong(1, Cnumber);
addStmt.setString(2, Cmodel);
addStmt.setString(3, Ccolor);
addStmt.setString(4, Cdate);
addStmt.setString(5, Cinsurance);
addStmt.setInt(6, Coil);
addStmt.setDouble(7, Crent);
addStmt.setString(8, conditions);
addStmt.execute();
JOptionPane.showMessageDialog(null, "已成功添加汽车信息!");
clearJTextField();
addStmt.close();
con.close();
area.append("您所添加的汽车信息为:\n");
area.append("车号:" + Cnumber + " \n车型:" + Cmodel + " \n颜色:" + Ccolor + " \n购置年份:" + Cdate
+ "\n保险情况:" + Cinsurance + "\n现存油量:" + Coil + "mL\n一天租金:" + Crent+ "元\n租赁状态:"+conditions+"\n");
} catch (Exception ex) {
ex.printStackTrace();
JOptionPane.showMessageDialog(null, "哎呀,系统出错误了!");
}
}
else if(s.equals("修改")) {
try {
Class.forName("com.mysql.cj.jdbc.Driver");
con = DriverManager.getConnection(dbUrl, dbUser, password);
PreparedStatement addStmt = con.prepareStatement(
"update AutomobileMessage set Cmodel=?,Ccolor=?,Cdate=?,Cinsurance=?,Coil=?,Crent=? where Cnumber="+jt1.getText());
String Cmodel = jt2.getText().trim();
String Ccolor = jt3.getText().trim();
String Cdate = jt4.getText().trim();
String Cinsurance = jt5.getText().trim();
int Coil = Integer.parseInt(jt6.getText().trim());
matcher = pattern2.matcher(jt7.getText().trim());
if (!matcher.matches()) {
JOptionPane.showMessageDialog(jt7, "请您输入一个大于等于0的数值型数据!");
jt7.setText("");
jt7.requestFocus();
return;
}
double Crent = Double.parseDouble(jt7.getText().trim());
addStmt.setString(1, Cmodel);
addStmt.setString(2, Ccolor);
addStmt.setString(3, Cdate);
addStmt.setString(4, Cinsurance);
addStmt.setInt(5, Coil);
addStmt.setDouble(6, Crent);
addStmt.executeUpdate();
addStmt.close();
con.close();
JOptionPane.showMessageDialog(null, "已成功修改汽车信息!");
clearJTextField();
area.append("您所修改后的汽车信息为:\n");
area.append("车号:" + Cnum + " \n车型:" + Cmodel + " \n颜色:" + Ccolor + " \n购置年份:" + Cdate
+ "\n保险情况:" + Cinsurance + "\n现存油量:" + Coil + "mL\n一天租金:" + Crent+ "元\n租赁状态:"+conditions+"\n");
} catch (Exception ex) {
JOptionPane.showMessageDialog(null, "哎呀,系统出错误了!");
}
}
}
});
back.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jf1.dispose();
}
});
}
2、删、改、查汽车信息
class AutomobileMessageManagement {
JPanel jp;
JLabel jl;
JTextField jt;
Connection con;
Statement stmt;
long Cnumber;
boolean flag=true;
public AutomobileMessageManagement(String s) throws SQLException, UnsupportedEncodingException {
jf2 = new JFrame(s + "汽车信息");
jf2.setLayout(new BorderLayout());
jp = new JPanel();
jl = new JLabel("请输入车号:");
sure=new JButton("确定");
sure.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(s.equals("删除"))
delete();
else if(s.equals("修改")) {
alter();
if(flag) {
ami=new AutomobileMessageInsert("修改",Cnumber);
ami.jt1.setText(String.valueOf(Cnumber));
ami.jt1.setEditable(false);
}
}
else if(s.equals("查询"))
search();
}
}
);
back = new JButton("返回");
back.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jf2.dispose();
}
});
jt = new JTextField(15);
area = new JTextArea();
Font f = new Font("黑体",Font.PLAIN,20);
area.setFont(f);
area.setEditable(false);
jp.add(jl);
jp.add(jt);
jp.add(sure);
int width = 520;
int height = 210;
JScrollPane js = new JScrollPane(area);
js.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
js.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
jf2.add(BorderLayout.NORTH, jp);
jf2.add(BorderLayout.CENTER, js);
jf2.add(BorderLayout.SOUTH, back);
jf2.setBounds((d.width - width) / 2, (d.height - height) / 2, width, height);
jf2.setVisible(true);
}
public void delete() { //删除汽车信息
try {
Long.parseLong(jt.getText());
}catch(Exception ex) {
JOptionPane.showMessageDialog(null, "请输入格式正确的汽车编号!");
jt.setText("");
jt.requestFocus();
}
String sqlExpression1 ="select * from AutomobileMessage where Cnumber="+jt.getText().trim();
String sqlExpression2 ="delete from AutomobileMessage where Cnumber=?";
try {
Class.forName("com.mysql.cj.jdbc.Driver");
con = DriverManager.getConnection(dbUrl, dbUser, password);
stmt = con.createStatement();
stmt.executeQuery(sqlExpression1);
} catch (SQLException e) {
JOptionPane.showMessageDialog(null, "未找到该汽车编号对应的信息!");
jt.setText("");
jt.requestFocus();
return;
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
ResultSet rs;long Cnumber = 0 ;String Cmodel = null ;String Ccolor=null;String Cdate=null;String Cinsurance=null;int Coil=0;double Crent=0;String Conditions=null;
try {
rs = stmt.executeQuery(sqlExpression1);
rs.next();
Cnumber = rs.getLong("Cnumber");
Cmodel = rs.getString("Cmodel");
Ccolor = rs.getString("Ccolor");
Cdate = rs.getString("Cdate");
Cinsurance = rs.getString("Cinsurance");
Coil = rs.getInt("Coil");
Crent = rs.getDouble("Crent");
Conditions=rs.getString("conditions");
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "未找到该汽车编号对应的信息!");
jt.setText("");
jt.requestFocus();
return;
}
try {
stmt = con.createStatement();
PreparedStatement deleteStmt = con.prepareStatement(sqlExpression2);
deleteStmt.setLong(1, Long.parseLong(jt.getText()));
deleteStmt.execute();
stmt.close();
con.close();
} catch (SQLException e) {
//e.printStackTrace();
JOptionPane.showMessageDialog(null, "不能删除该汽车编号对应的信息!");
jt.setText("");
jt.requestFocus();
return;
}
JOptionPane.showMessageDialog(null, "已成功删除汽车信息!");
area.append("您所删除的汽车信息为:\n");
area.append("车号:" + Cnumber + ", 车型:" + Cmodel + ", 颜色:" + Ccolor + ", 购置年份:" + Cdate + ", 保险情况:"
+ Cinsurance + " ,现存油量:" + Coil + "mL, 一天租金:" + Crent + "元"+ ", 租赁状态:"+Conditions+"\n");
area.validate();
}
public void alter() { //修改汽车信息
try {
Class.forName("com.mysql.cj.jdbc.Driver");
con = DriverManager.getConnection(dbUrl, dbUser, password);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException ex) {
ex.printStackTrace();
}
try {
Long.parseLong(jt.getText());
}catch(Exception ex) {
JOptionPane.showMessageDialog(null, "请输入格式正确的汽车编号!");
jt.setText("");
jt.requestFocus();
}
String sqlExpression1 ="select * from AutomobileMessage where Cnumber="+jt.getText().trim();
ResultSet rs;
try {
stmt = con.createStatement();
rs=stmt.executeQuery(sqlExpression1);
} catch (SQLException e) {
JOptionPane.showMessageDialog(null, "未找到该汽车编号对应的信息!");
flag=false;
jt.setText("");
jt.requestFocus();
return;
}
Cnumber = 0 ;String Cmodel = null ;String Ccolor=null;String Cdate=null;String Cinsurance=null;int Coil=0;double Crent=0;String conditions=null;
try {
//rs = stmt.executeQuery(sqlExpression1);
rs.next();
Cnumber = rs.getLong("Cnumber");
Cmodel = rs.getString("Cmodel");
Ccolor = rs.getString("Ccolor");
Cdate = rs.getString("Cdate");
Cinsurance = rs.getString("Cinsurance");
Coil = rs.getInt("Coil");
Crent = rs.getDouble("Crent");
conditions=rs.getString("conditions");
} catch (SQLException e) {
flag=false;
JOptionPane.showMessageDialog(null, "未找到该汽车编号对应的信息!");
jt.setText("");
jt.requestFocus();
return;
}
area.append("您所更改之前的汽车信息为:\n");
area.append("车号:" + Cnumber + "\n车型:" + Cmodel + "\n颜色:" + Ccolor + "\n购置年份:" + Cdate + "\n保险情况:"
+ Cinsurance + "\n现存油量:" + Coil + "mL\n一天租金:" + Crent + "元\n租赁状态:"+conditions+"\n");
area.validate();
try {
stmt.close();
con.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
flag=true;
}
public void search() { //按编号查询汽车信息
try {
Long.parseLong(jt.getText());
}catch(Exception ex) {
JOptionPane.showMessageDialog(null, "请输入格式正确的汽车编号!");
jt.setText("");
jt.requestFocus();
}
try {
Class.forName("com.mysql.cj.jdbc.Driver");
con = DriverManager.getConnection(dbUrl, dbUser, password);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException ex) {
ex.printStackTrace();
}
String sqlExpression ="select * from AutomobileMessage where Cnumber="+jt.getText().trim();
try {
stmt = con.createStatement();
stmt.executeQuery(sqlExpression);
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "未查询到该汽车编号对应的信息!");
jt.setText("");
jt.requestFocus();
return;
}
ResultSet rs;long Cnumber = 0 ;String Cmodel = null ;String Ccolor=null;String Cdate=null;String Cinsurance=null;int Coil=0;double Crent=0;String conditions=null;
try {
rs = stmt.executeQuery(sqlExpression);
rs.next();
Cnumber = rs.getLong("Cnumber");
Cmodel = rs.getString("Cmodel");
Ccolor = rs.getString("Ccolor");
Cdate = rs.getString("Cdate");
Cinsurance = rs.getString("Cinsurance");
Coil = rs.getInt("Coil");
Crent = rs.getDouble("Crent");
conditions = rs.getString("conditions");
} catch (SQLException e) {
JOptionPane.showMessageDialog(null, "未查询到该汽车编号对应的信息!");
jt.setText("");
jt.requestFocus();
return;
}
area.append("您所查询的汽车信息为:\n");
area.append("车号:" + Cnumber + "\n车型:" + Cmodel + "\n颜色:" + Ccolor + "\n购置年份:" + Cdate + "\n保险情况:"
+ Cinsurance + "\n现存油量:" + Coil + "mL\n一天租金:" + Crent + "元,\n租赁状态:"+conditions+"\n");
area.validate();
try {
stmt.close();
con.close();
} catch (SQLException e1) {
e1.printStackTrace();
}
}
}
3、查看所有汽车信息
class AutomobileMessageShown {
Statement stmt;
Connection con;
public void showAll() throws SQLException, UnsupportedEncodingException {
String sqlExpression = "select * from AutomobileMessage";
con = DriverManager.getConnection(dbUrl, dbUser, password);
stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(sqlExpression);
//rs = stmt.executeQuery(sqlExpression);
while (rs.next()) {
long Cnumber = rs.getLong("Cnumber");
String Cmodel = rs.getString("Cmodel");
String Ccolor = rs.getString("Ccolor");
String Cdate = rs.getString("Cdate");
String Cinsurance = rs.getString("Cinsurance");
int Coil = rs.getInt("Coil");
double Crent = rs.getDouble("Crent");
String conditions = rs.getString("conditions");
area.append("车号:" + Cnumber + ", 车型:" + Cmodel + ", 颜色:" + Ccolor + ", 购置年份:" + Cdate + ", 保险情况:"
+ Cinsurance + " ,现存油量:" + Coil + "mL, 一天租金:" + Crent+ "元, 租赁状态:"+conditions+"\n");
area.validate();
}
try {
stmt.close();
con.close();
} catch (SQLException e1) {
e1.printStackTrace();
}
}
public AutomobileMessageShown(String s) {
jf3 = new JFrame("查看" + s);
jf3.setLayout(new BorderLayout());
jf3 = new JFrame(s + "汽车信息");
back = new JButton("返回");
back.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jf3.dispose();
}
});
area = new JTextArea();
area.setEditable(false);
Font f = new Font("黑体",Font.PLAIN,20);
area.setFont(f);
int width = 520;
int height = 210;
JScrollPane js = new JScrollPane(area);
js.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
js.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
jf3.add(BorderLayout.CENTER, js);
jf3.add(BorderLayout.SOUTH, back);
jf3.setBounds((d.width - width) / 2, (d.height - height) / 2, width, height);
jf3.setVisible(true);
}
}
4、分类查看汽车租赁信息、租赁汽车
class AutomobileLeasing implements ActionListener {
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
JFrame jf1;
JLabel l1, l2, l3, l4, l5, l6, l7, l8, pic1, pic2, pic3;
JTextField t1, t2, t3, t4, t5, t6, t7;
JPanel p1, p2, p3, p4, p5, p6, p7, p8, p9, p0;
JRadioButton rb1, rb2, rb3;
JButton showAll, ensure, back;
ButtonGroup bg;
private String dbUrl = "jdbc:mysql://localhost:3306/automobile?serverTimezone=UTC&useUnicode=true&characterEncoding=utf8&useSSL=false&allowPublicKeyRetrieval=true";
private String dbUser = "Alan";
private String password = "1234";
Statement stmt;
Connection con;
FocusHandler fh;
Pattern pattern = Pattern
.compile("(^[1-9]\\d{5}(18|19|20)\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\d{3}[0-9Xx]$)|"
+ "(^[1-9]\\d{5}\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\d{3}$)");
Pattern pattern1 = Pattern.compile("^[+]{0,1}(\\d+)$");
Matcher matcher;
private String Lpay = null;
boolean flag = true;
AutomobileLeasing() {
jf1 = new JFrame("汽车租赁服务");
jf1.setLayout(new FlowLayout());
l1 = new JLabel("客户姓名");
l2 = new JLabel("性别(男/女)");
l3 = new JLabel("民族");
l4 = new JLabel("租车日期(yyyy-mm-dd)");
l5 = new JLabel("家庭住址");
l6 = new JLabel("身份证号码");
l7 = new JLabel("所租车号");
l8 = new JLabel(" 押金支付方式: ");
pic1 = new JLabel(new ImageIcon("src\\automobileLeasingManagementSystem\\1.png"));
pic2 = new JLabel(new ImageIcon("src\\automobileLeasingManagementSystem\\2.png"));
pic3 = new JLabel(new ImageIcon("src\\automobileLeasingManagementSystem\\3.png"));
t1 = new JTextField(10);
t2 = new JTextField(10);
t3 = new JTextField(10);
t4 = new JTextField(25);
t5 = new JTextField(30);
t6 = new JTextField(25);
t7 = new JTextField(25);
fh = new FocusHandler();
t4.addFocusListener(fh);
t6.addFocusListener(fh);
t7.addFocusListener(fh);
rb1 = new JRadioButton("微信");
rb2 = new JRadioButton("支付宝");
rb3 = new JRadioButton("银联");
bg = new ButtonGroup();
bg.add(rb1);
bg.add(rb2);
bg.add(rb3);
showAll = new JButton("查看汽车租赁状态信息");
showAll.addActionListener(this);
ensure = new JButton("确认租车");
back = new JButton("返回主菜单");
ensure.addActionListener(this);
back.addActionListener(this);
p1 = new JPanel();
p2 = new JPanel();
p3 = new JPanel();
p4 = new JPanel();
p5 = new JPanel();
p6 = new JPanel();
p7 = new JPanel();
p8 = new JPanel();
p9 = new JPanel();
p0 = new JPanel();
p1.add(l1);
p1.add(t1);
p2.add(l2);
p2.add(t2);
p3.add(l3);
p3.add(t3);
p4.add(l4);
p4.add(t4);
p5.add(l5);
p5.add(t5);
p6.add(l6);
p6.add(t6);
p7.add(l7);
p7.add(t7);
p8.add(l8);
p8.add(rb1);
p8.add(rb2);
p8.add(rb3);
p0.add(new JLabel(" "));
p0.add(pic1);
p0.add(new JLabel(" "));
p0.add(pic2);
p0.add(new JLabel(" "));
p0.add(pic3);
p9.add(showAll);
p9.add(ensure);
p9.add(back);
jf1.add(p1);
jf1.add(p2);
jf1.add(p3);
jf1.add(p4);
jf1.add(p5);
jf1.add(p6);
jf1.add(p7);
jf1.add(p8);
jf1.add(p0);
jf1.add(p9);
int width = 590;
int height = 390;
jf1.setBounds((d.width - width) / 2, (d.height - height) / 2, width, height);
jf1.setVisible(true);
}
class showAllAutomobileMessage {
JFrame jf2;
JPanel jp;// ,jp2;
JTextArea area;
JButton jb1, jb2, jb3, jb0;
public showAllAutomobileMessage() {
jf2 = new JFrame("汽车租赁状态详细信息");
jf2.setLayout(new BorderLayout());
jp = new JPanel();
jp.setLayout(new GridLayout(3, 1));
jb1 = new JButton("正常待租");
jb2 = new JButton("已租赁");
jb3 = new JButton("维修中");
jb0 = new JButton("返回");
jp.add(jb1);
jp.add(jb2);
jp.add(jb3);
// jp2=new JPanel();
area = new JTextArea();
area.setEditable(false);
Font f = new Font("楷体",Font.PLAIN,20);
area.setFont(f);
JScrollPane js = new JScrollPane(area);
js.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
js.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
jf2.add(BorderLayout.CENTER, js);
jf2.add(BorderLayout.WEST, jp);
jf2.add(BorderLayout.SOUTH, jb0);
int width = 550;
int height = 210;
jf2.setBounds((d.width - width) / 2, (d.height - height) / 2, width, height);
jf2.setVisible(true);
jb0.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
jf2.dispose();
}
});
jb1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent a) {
area.setText("");
String sqlExpression = "select * from AutomobileMessage where conditions=\"正常待租\"";
try {
con = DriverManager.getConnection(dbUrl, dbUser, password);
stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(sqlExpression);
while (rs.next()) {
long Cnumber = rs.getLong("Cnumber");
String Cmodel = rs.getString("Cmodel");
String Ccolor = rs.getString("Ccolor");
String Cdate = rs.getString("Cdate");
String Cinsurance = rs.getString("Cinsurance");
int Coil = rs.getInt("Coil");
double Crent = rs.getDouble("Crent");
String conditions = rs.getString("conditions");
area.append("车号:" + Cnumber + ", 车型:" + Cmodel + ", 颜色:" + Ccolor + ", 购置年份:" + Cdate
+ ", 保险情况:" + Cinsurance + " ,现存油量:" + Coil + "mL, 一天租金:" + Crent + "元, 租赁状态:"
+ conditions + "\n");
}
stmt.close();
con.close();
if(area.getText().equals("")) {
JOptionPane.showMessageDialog(null, "目前没有正常待租的汽车哦!");
}
} catch (SQLException e) {
e.printStackTrace();
}
}
});
jb2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent a) {
area.setText("");
String sqlExpression = "select * from AutomobileMessage,lesseeMessage where AutomobileMessage.Cnumber=lesseeMessage.Cnumber and conditions=\"已租赁\"";
try {
con = DriverManager.getConnection(dbUrl, dbUser, password);
stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(sqlExpression);
while (rs.next()) {
long Cnumber = rs.getLong("Cnumber");
String Cmodel = rs.getString("Cmodel");
String Ccolor = rs.getString("Ccolor");
String Cdate = rs.getString("Cdate");
String Cinsurance = rs.getString("Cinsurance");
int Coil = rs.getInt("Coil");
double Crent = rs.getDouble("Crent");
String conditions = rs.getString("conditions");
String Lname = rs.getString("Lname");
String Lgender = rs.getString("Lgender");
String Lnation = rs.getString("Lnation");
Date Ldate = rs.getDate("Ldate");
String Laddress = rs.getString("Laddress");
String Lid = rs.getString("Lid");
String Lpay = rs.getString("Lpay");
area.append("车号:" + Cnumber + ", 车型:" + Cmodel + ", 颜色:" + Ccolor + ", 购置年份:" + Cdate + ", 保险情况:"
+ Cinsurance + " ,现存油量:" + Coil + "mL, 一天租金:" + Crent + "元, 租赁状态:" + conditions+", 客户姓名:" + Lname + ", 性别:" + Lgender + ", 民族:" + Lnation + ", 租车日期:" + Ldate
+ ", 家庭住址:" + Laddress + ", 身份证号码:" + Lid + ", 押金支付方式:" + Lpay
+ "\n");
area.validate();
}
if(area.getText().equals("")) {
JOptionPane.showMessageDialog(null, "目前没有已租赁的汽车哦!");
}
stmt.close();
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
});
jb3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent a) {
area.setText("");
String sqlExpression = "select * from AutomobileMessage where conditions=\"维修中\"";
try {
con = DriverManager.getConnection(dbUrl, dbUser, password);
stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(sqlExpression);
while (rs.next()) {
long Cnumber = rs.getLong("Cnumber");
String Cmodel = rs.getString("Cmodel");
String Ccolor = rs.getString("Ccolor");
String Cdate = rs.getString("Cdate");
String Cinsurance = rs.getString("Cinsurance");
int Coil = rs.getInt("Coil");
double Crent = rs.getDouble("Crent");
String conditions = rs.getString("conditions");
area.append("车号:" + Cnumber + ", 车型:" + Cmodel + ", 颜色:" + Ccolor + ", 购置年份:" + Cdate
+ ", 保险情况:" + Cinsurance + " ,现存油量:" + Coil + "mL, 一天租金:" + Crent + "元, 租赁状态:"
+ conditions + "\n");
area.validate();
}
stmt.close();
con.close();
if(area.getText().equals("")) {
JOptionPane.showMessageDialog(null, "目前没有维修中的汽车哦!");
}
} catch (SQLException e) {
e.printStackTrace();
}
}
});
}
}
void clearJTextField() {
t1.setText("");
t2.setText("");
t3.setText("");
t4.setText("");
t5.setText("");
t6.setText("");
t7.setText("");
}
public void actionPerformed(ActionEvent e) {
if (rb1.isSelected()) {
Lpay = "微信";
} else if (rb2.isSelected()) {
Lpay = "支付宝";
} else if (rb3.isSelected()) {
Lpay = "银联";
}
if (e.getSource() == showAll) {
new showAllAutomobileMessage();
} else if (e.getSource() == ensure) {
String sqlExpression1 = "select conditions from AutomobileMessage where Cnumber=" + t7.getText().trim();
try {
try {
if((t1.getText().equals(""))||(t2.getText().equals(""))||((!rb1.isSelected())&&(!rb2.isSelected())&&(!rb3.isSelected()))||(t5.getText().equals(""))||(t6.getText().equals(""))||(t7.getText().equals(""))) {
flag=false;
JOptionPane.showMessageDialog(null, "请将您的个人信息填完整——客户姓名、性别、租车日期、身份证号、所租车号、支付方式等均不能为空!");
return;
}
else {
flag=true;
}
con = DriverManager.getConnection(dbUrl, dbUser, password);
stmt = con.createStatement();
stmt.executeQuery(sqlExpression1);
} catch (SQLException se) {
se.printStackTrace();
JOptionPane.showMessageDialog(null, "未找到所要租赁的汽车信息!");
t7.setText("");
t7.requestFocus();
return;
}
ResultSet rs;
try {
rs = stmt.executeQuery(sqlExpression1);
rs.next();
if ((rs.getString("conditions").equals("已租赁"))) {
flag = false;
JOptionPane.showMessageDialog(null, "抱歉,该汽车已被租赁!");
t7.setText("");
t7.requestFocus();
return;
} else if ((rs.getString("conditions").equals("维修中"))) {
flag = false;
JOptionPane.showMessageDialog(null, "抱歉,该汽车正在维修中!");
t7.setText("");
t7.requestFocus();
return;
} else {
flag = true;
}
} catch (SQLException se) {
flag = false;
JOptionPane.showMessageDialog(null, "未找到所要租赁的汽车信息!");
t7.setText("");
t7.requestFocus();
return;
}
if (flag) {
PreparedStatement updateStmt = con.prepareStatement(
"update AutomobileMessage set conditions=? where Cnumber=" + t7.getText());
PreparedStatement addStmt = con.prepareStatement(
"insert into lesseeMessage(Lname,Lgender,Lnation,Ldate,Laddress,Lid,Cnumber,Lpay)values(?,?,?,?,?,?,?,?)");
String Lname = t1.getText().trim();
String Lgender = t2.getText().trim();
String Lnation = t3.getText().trim();
DateFormat df = DateFormat.getDateInstance();
Date Ldate = new java.sql.Date(df.parse(t4.getText().trim()).getTime());
String Laddress = t5.getText().trim();
String Lid = t6.getText().trim();
long Cnumber = Long.parseLong(t7.getText().trim());
addStmt.setString(1, Lname);
addStmt.setString(2, Lgender);
addStmt.setString(3, Lnation);
addStmt.setDate(4, Ldate);
addStmt.setString(5, Laddress);
addStmt.setString(6, Lid);
addStmt.setLong(7, Cnumber);
addStmt.setString(8, Lpay);
addStmt.execute();
updateStmt.setString(1, "已租赁");
updateStmt.execute();
addStmt.close();
updateStmt.close();
con.close();
JOptionPane.showMessageDialog(null, "已成功租赁该汽车!");
clearJTextField();
bg.clearSelection();
}
} catch (SQLException e1) {
e1.printStackTrace();
} catch (Exception e2) {
e2.printStackTrace();
}
} else if (e.getSource() == back) {
jf1.dispose();
}
}
5、租赁汽车回收
class AutomobileRecycle extends JFrame {
JLabel jl1, jl2, jl3;
JTextField jtf1, jtf2, jtf3;
JCheckBox jcb, jcb1;
JButton showDetail, sumRent, ensure, back;
JPanel p1, p2, p3;
JTextArea area;
Pattern pattern = Pattern
.compile("(^[1-9]\\d{5}(18|19|20)\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\d{3}[0-9Xx]$)|"
+ "(^[1-9]\\d{5}\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\d{3}$)");
Pattern pattern1 = Pattern.compile("^[+]{0,1}(\\d+)$");
Statement stmt;
Connection con;
private String dbUrl = "jdbc:mysql://localhost:3306/automobile?serverTimezone=UTC&useUnicode=true&characterEncoding=utf8&useSSL=false&allowPublicKeyRetrieval=true";
private String dbUser = "Alan";
private String password = "1234";
Matcher matcher;
Date rentDate=null;
Date backDate=null;
Double sumCost;
void tellTruth1() {
matcher = pattern.matcher(jtf1.getText().trim());
if (!matcher.matches()) {
JOptionPane.showMessageDialog(jtf1, "请您输入正确的身份证号!");
jtf1.setText("");
jtf1.requestFocus();
return;
}
if (jtf1.getText().equals("")) {
JOptionPane.showMessageDialog(jtf1, "身份证号不能为空,请您先填写正确的身份证号!");
jtf1.requestFocus();
return;
}
}
void tellTruth2() {
matcher = pattern1.matcher(jtf2.getText().trim());
if (!matcher.matches()) {
JOptionPane.showMessageDialog(jtf2, "请您输入正确格式的车号!");
jtf2.setText("");
jtf2.requestFocus();
return;
}
if (jtf2.getText().equals("")) {
JOptionPane.showMessageDialog(jtf2, "车号不能为空!");
jtf2.requestFocus();
return;
}
}
void tellTruth3() {
try {
backDate=new java.sql.Date( DateFormat.getDateInstance().parse(jtf3.getText().trim()).getTime());
} catch (ParseException e) {
JOptionPane.showMessageDialog(jtf3, "请您输入正确格式的日期,形式为“yyyy-mm-dd”!");
}
}
public AutomobileRecycle() {
super("汽车回收");
setLayout(new BorderLayout());
p1 = new JPanel();
p2 = new JPanel();
p3 = new JPanel();
p1.setLayout(new GridLayout(5, 4));
jl1 = new JLabel("承租人身份证号:");
jl2 = new JLabel("所要归还的车号:");
jl3 = new JLabel("归还日期(yyyy-mm-dd):");
jtf1 = new JTextField(15);
jtf2 = new JTextField(15);
jtf3 = new JTextField(15);
showDetail = new JButton("查看详细租单");
jcb = new JCheckBox("已确认租单信息无误");
jcb1 = new JCheckBox("需要维修");
ensure = new JButton("确认归还");
sumRent = new JButton("查看总租金");
back = new JButton("返回主菜单");
area = new JTextArea();
area.setEditable(false);
Font f = new Font("楷体",Font.PLAIN,20);
area.setFont(f);
JScrollPane js = new JScrollPane(area);
js.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
js.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
p1.add(new JLabel(""));
p1.add(new JLabel(""));
p1.add(new JLabel(""));
p1.add(new JLabel(""));
p1.add(new JLabel(new ImageIcon("src\\automobileLeasingManagementSystem\\cars1.png")));
p1.add(jl1);
p1.add(jtf1);
p1.add(new JLabel(new ImageIcon("src\\automobileLeasingManagementSystem\\cars1.png")));
p1.add(new JLabel(new ImageIcon("src\\automobileLeasingManagementSystem\\cars2.png")));
p1.add(jl2);
p1.add(jtf2);
p1.add(new JLabel(new ImageIcon("src\\automobileLeasingManagementSystem\\cars2.png")));
p1.add(new JLabel(new ImageIcon("src\\automobileLeasingManagementSystem\\cars3.png")));
p1.add(jl3);
p1.add(jtf3);
p1.add(new JLabel(new ImageIcon("src\\automobileLeasingManagementSystem\\cars3.png")));
p1.add(new JLabel(""));
p1.add(new JLabel(""));
p1.add(new JLabel(""));
p1.add(new JLabel(""));
p2.setLayout(new GridLayout(3, 2));
p2.add(sumRent);
p2.add(showDetail);
p2.add(jcb);
p2.add(jcb1);
p2.add(ensure);
p2.add(back);
p3.add(new JLabel(" "));
add(BorderLayout.NORTH, p1);
add(BorderLayout.CENTER, js);
add(BorderLayout.WEST, p2);
add(BorderLayout.SOUTH, p3);
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
int width = 710;
int height = 350;
setBounds((d.width - width) / 2, (d.height - height) / 2, width, height);
setVisible(true);
showDetail.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
tellTruth1();
String sqlExpression1 = "select * from lesseeMessage,AutomobileMessage where lesseeMessage.Cnumber=AutomobileMessage.Cnumber and Lid='" + jtf1.getText() + "'";
//ArrayList<String> list = new ArrayList<String>();
try {
con = DriverManager.getConnection(dbUrl, dbUser, password);
stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(sqlExpression1);
area.setText("");
while (rs.next()) {
long Cnumber = rs.getLong("Cnumber");
String Cmodel = rs.getString("Cmodel");
String Ccolor = rs.getString("Ccolor");
String Cdate = rs.getString("Cdate");
String Cinsurance = rs.getString("Cinsurance");
int Coil = rs.getInt("Coil");
double Crent = rs.getDouble("Crent");
String conditions = rs.getString("conditions");
String Lname = rs.getString("Lname");
String Lgender = rs.getString("Lgender");
String Lnation = rs.getString("Lnation");
Date Ldate = rs.getDate("Ldate");
String Laddress = rs.getString("Laddress");
String Lid = rs.getString("Lid");
String Lpay = rs.getString("Lpay");
area.append("车号:" + Cnumber + ", 车型:" + Cmodel + ", 颜色:" + Ccolor + ", 购置年份:" + Cdate + ", 保险情况:"
+ Cinsurance + " ,现存油量:" + Coil + "mL, 一天租金:" + Crent + "元, 租赁状态:" + conditions+", 客户姓名:" + Lname + ", 性别:" + Lgender + ", 民族:" + Lnation + ", 租车日期:" + Ldate
+ ", 家庭住址:" + Laddress + ", 身份证号码:" + Lid + ", 押金支付方式:" + Lpay
+ "\n");
area.validate();
}
if(area.getText().equals("")) {
JOptionPane.showMessageDialog(null, "未能找到个该承租人租车信息!");
jtf1.setText("");
jtf1.requestFocus();
return;
}
stmt.close();
con.close();
} catch (SQLException ex) {
JOptionPane.showMessageDialog(null, "未能找到个该承租人租车信息!");
jtf1.requestFocus();
return;
}
}
});
ensure.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
tellTruth1();
tellTruth2();
tellTruth3();
if(!jcb.isSelected()) {
JOptionPane.showMessageDialog(null,"请先确认您的租单无误!");
return;
}
String sqlExpression1 = "select * from lesseeMessage,AutomobileMessage where lesseeMessage.Cnumber=AutomobileMessage.Cnumber and Lid='" + jtf1.getText() + "'";
String sqlExpression2 = "delete from lesseeMessage where Cnumber='" + jtf2.getText().trim()+"'";
String sqlExpression3 = "update AutomobileMessage set conditions=? where Cnumber='" + jtf2.getText().trim()+"'";
ResultSet rs;
ArrayList<String> list= new ArrayList<String>();
try {
con = DriverManager.getConnection(dbUrl, dbUser, password);
stmt = con.createStatement();
rs = stmt.executeQuery(sqlExpression1);
} catch (SQLException se) {
se.printStackTrace();
JOptionPane.showMessageDialog(null, "未找到承租人信息!");
jtf2.setText("");
jtf2.requestFocus();
return;
}
try {
boolean flag=true;
while(rs.next()) {
long Cnumber = rs.getLong("Cnumber");
list.add(String.valueOf(Cnumber));
}
for(int i=0;i<list.size();i++) { //集合里存放的是根据承租人身份信息搜索到的所租车号,如果与用户输入的车号相同则说明可以归还
if(list.get(i).equals(jtf2.getText())) {
flag=false;
list.remove(i);
PreparedStatement updateStmt = con.prepareStatement(sqlExpression3);
if(jcb1.isSelected()) {
updateStmt.setString(1, "维修中");
}
else {
updateStmt.setString(1, "正常待租");
}
updateStmt.execute();
updateStmt.close();
}
}
if(flag) {
JOptionPane.showMessageDialog(null, "您没有租赁该汽车,请检查您输入的车号!");
jtf2.requestFocus();
return;
}else {
stmt = con.createStatement();
stmt.execute(sqlExpression2);
JOptionPane.showMessageDialog(null, "您已成功归还!");
}
stmt.close();
} catch (SQLException se) {
se.printStackTrace();
}
}
});
sumRent.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
tellTruth1();
tellTruth2();
tellTruth3();
String sqlExpression = "select * from lesseeMessage,AutomobileMessage where lesseeMessage.Cnumber=AutomobileMessage.Cnumber and Lid='" + jtf1.getText() + "'";
ResultSet rs;
ArrayList<String> listNumber= new ArrayList<String>();
ArrayList<Date> listDate= new ArrayList<Date>();
ArrayList<Double> listCost= new ArrayList<Double>();
try {
con = DriverManager.getConnection(dbUrl, dbUser, password);
stmt = con.createStatement();
rs = stmt.executeQuery(sqlExpression);
} catch (SQLException se) {
//se.printStackTrace();
JOptionPane.showMessageDialog(null, "未找到承租人信息!");
jtf2.setText("");
jtf2.requestFocus();
return;
}
try {
boolean flag=true;
area.setText("");
while(rs.next()) {
long Cnumber = rs.getLong("Cnumber");
rentDate=rs.getDate("Ldate");
double Crent=rs.getDouble("Crent");
listNumber.add(String.valueOf(Cnumber));
listDate.add(rentDate);
listCost.add(Crent);
}
for(int i=0;i<listNumber.size();i++) { //集合里存放的是根据承租人身份信息搜索到的所租车号,如果与用户输入的车号相同则说明可以归还
if(listNumber.get(i).equals(jtf2.getText())) {
flag=false;
rentDate=listDate.get(i);
int day=(int) ((backDate.getTime() - rentDate.getTime()) / (24 * 60 * 60 * 1000));
if(day<0) {
JOptionPane.showMessageDialog(null, "您输入的日期有误,请核查!");
jtf3.requestFocus();
return;
}
sumCost=day*listCost.get(i);
area.append("租车日期:"+listDate.get(i)+"\n租用天数:"+day+ "天\n 总租金:"+sumCost);
}
}
if(flag) {
JOptionPane.showMessageDialog(null, "你没有租赁该汽车,请检查您输入的车号!");
jtf2.requestFocus();
return;
}
} catch (SQLException se) {
JOptionPane.showMessageDialog(null, "抱歉,系统出错误了!");
se.printStackTrace();
}
catch(NullPointerException ne) {
JOptionPane.showMessageDialog(null, "请您先输入汽车归还日期!");
jtf3.requestFocus();
return;
}
}
});
back.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dispose();
}
});
}
}
六、亮点分析
亮点一:利用多线程实现了主页面字幕实时滚动
public void run() {
if(Thread.currentThread()==scrollWordsThread){
while(true){
int x=l2.getBounds().x;
//System.out.println(x);
int y=l2.getBounds().y;
x-=5;
l2.setLocation(x,y);
if(x<-720){
x=200;
l2.setLocation(x,y);
}
try {
Thread.sleep(100);
} catch (Exception ex) {
}
}
}
}
亮点二:利用正则表达式+FocusListener实时检测并提醒了用户输入数据的格式正误
class FocusHandler implements FocusListener {
@Override
public void focusGained(FocusEvent e) {
}
@Override
public void focusLost(FocusEvent f) {
if (f.getSource() == t4) {
try {
new java.sql.Date( DateFormat.getDateInstance().parse(t4.getText().trim()).getTime());
} catch (ParseException e) {
JOptionPane.showMessageDialog(t4, "请您输入正确格式的日期,形式为“yyyy-mm-dd”!");
}
}
else if (f.getSource() == t6) {
matcher = pattern.matcher(t6.getText().trim());
if (!matcher.matches()) {
JOptionPane.showMessageDialog(t6, "请您输入正确的身份证号!");
t6.setText("");
t6.requestFocus();
return;
}
}
else if (f.getSource() == t7) {
matcher = pattern1.matcher(t7.getText().trim());
if (!matcher.matches()) {
JOptionPane.showMessageDialog(t7, "请您输入一个大于等于0的整数数据!");
t7.setText("");
t7.requestFocus();
return;
}
}
}
}
亮点三:数据库插入语句使用了预编译,这样不容易产生SQL注入等安全隐患
PreparedStatement addStmt = con.prepareStatement(
"insert into AutomobileMessage(Cnumber,Cmodel,Ccolor,Cdate,Cinsurance,Coil,Crent,conditions)values(?,?,?,?,?,?,?,?)");
七、不足之处
不足一:利用java-GUI最大的不足之处就是难以连接互联网,这个项目只能够单机使用,用户体验比较差,而目前主流软件项目开发都是采用B/S架构,前端和后台分离。
不足二:连接数据库时的处理语句繁琐,没有封装到一个专用类中,或者没有使用数据库连接池,导致每进行一次增、删、改、查都要先重新进行数据库的连接,这样就会导致代码冗余、对系统资源的占用比较大。
不足三:没有租赁用户的登录和注册机制,这就容易导致租赁用户的个人信息及租赁订单的信息出现非常大的安全隐患,主要是存在信息完整性和机密性的隐患。
不足四:数据库结构设计不严谨,车号属性不应该设置成bigint型,而应该是char型,因为生活中车号会有汉字和字母,比如“鲁A 3322S3”。
不足五:文本区显示查询内容时不能把每条信息对齐后呈现在屏幕上,格式上不够工整;个别地方仍存在异常没有调试。
完整源代码链接:
更多推荐
所有评论(0)