Java Swing+Mysql实现汽车租赁系统

请添加图片描述

汽车租赁系统

功能结构图
在这里插入图片描述
界面设计
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
打包下载git地址:https://github.com/1070124410/Rent_car_control_system.git

代码如下:
Main入口

package Main;

import Log.Login;

public class Main {
    public static void main(String[] args) {
        new Login();
    }

}


extend

package Main;

import javax.swing.*;
import java.awt.*;

public class extend {
    public void image(JFrame jFrame, Container container, String url){
        // 设置背景
        JLabel lblBackground = new JLabel(); // 创建一个标签组件对象
        ImageIcon icon = new ImageIcon(url); // 创建背景图片对象
        lblBackground.setIcon(icon); // 设置标签组件要显示的图标
        lblBackground.setBounds(0, 0, icon.getIconWidth(), icon.getIconHeight()); // 设置组件的显示位置及大小
        jFrame.getContentPane().add(lblBackground); // 将组件添加到面板中
    }
    public void  changecoffee(JFrame jFrame){
        ImageIcon icon=new ImageIcon("src/Image/汽车.png");
        jFrame.setIconImage(icon.getImage());

    }
}

control接口

package Main;

public interface control {
    default void addCar() {
    }

    default void changeCar() {
    }

    default void removeCar() {
    }
}

Log

package Log;

import Page.PAGE;
import Main.extend;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.*;

public class Login extends JFrame{
    public Login(){
        setTitle("车辆租赁系统--管理员登录");
        setSize(450,300);
        new extend().changecoffee(this);
        setLayout(null);
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        //获取屏幕大小,让窗口居中显示
        Dimension screenSize =Toolkit.getDefaultToolkit().getScreenSize();
        setLocation(screenSize.width/2-450/2,screenSize.height/2-300/2);
        //设置窗口容器
        Container container1=getContentPane();
        container1.setBackground(Color.WHITE);

        //添加内容
        JLabel laber1=new JLabel("账户:");
        laber1.setFont(new Font("宋体",Font.BOLD,18));
        laber1.setBounds(100,50,80,30);
        JTextField account_text=new JTextField(16);
        account_text.setBounds(150,50,150,30);
        account_text.setFont(new Font("宋体",Font.BOLD,18));
        JLabel laber2=new JLabel("密码:");
        laber2.setFont(new Font("宋体",Font.BOLD,18));
        laber2.setBounds(100,100,80,30);
        JPasswordField passwordField=new JPasswordField(16);
        passwordField.setBounds(150,100,150,30);
        passwordField.setFont(new Font("宋体",Font.BOLD,18));
        container1.add(laber1);
        container1.add(account_text);
        container1.add(laber2);
        container1.add(passwordField);

        JButton log=new JButton("登录");
        log.setBounds(120,180,70,20);
        Font f=new Font("宋体",Font.BOLD,16);
        log.setFont(f);
        JButton reset=new JButton("重置");
        reset.setBounds(230,180,70,20);
        Font f1=new Font("宋体",Font.BOLD,16);
        reset.setFont(f1);
        container1.add(log);
        container1.add(reset);
        //监听登录系统
        log.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
            //调用数据库进行查询
                try {
                    Class.forName("com.mysql.cj.jdbc.Driver");
                    Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/data?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&useSSL=false","root","240443");
                    Statement statement = con.createStatement();
                    ResultSet resultset = statement.executeQuery("select * from admin");
                    int boo=0;
                    while(resultset.next()){
                     String u= resultset.getString("username");
                     String p= resultset.getString("password");
                     String ss=account_text.getText();

                     if(account_text.getText().equals(u) &&passwordField.getText().equals(p)){
                         boo=1;
                         break;
                     }
                    }
                    //如果匹配则登录成功
                    if(boo==1){
                        new PAGE();
                        con.close();
                        setVisible(false);
                    }
                    else{
                        JOptionPane.showMessageDialog(null, "用户不存在或密码错误", "登录失败",JOptionPane.WARNING_MESSAGE);
                        account_text.setText("");
                        passwordField.setText("");
                    }
                } catch (Exception e1) {
                    e1.printStackTrace();
                }
            }
        });
        reset.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                account_text.setText("");
                passwordField.setText("");
            }
        });
        //添加背景
        new extend().image(this,container1,"src/Image/大桥.png");
        setVisible(true);
    }
}

Image
在这里插入图片描述
图片在git下载,复制代码运行时需更换图片路径,自行添加修改。
PAGE

package Page;

import Main.*;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;

public class PAGE extends JFrame {
    public  PAGE() {

        setTitle("管理员已登录");
        setSize(650, 500);
        setLayout(null);
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        new extend().changecoffee(this);
        //获取屏幕大小,让窗口居中显示
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        setLocation(screenSize.width / 2 - 450 / 2, screenSize.height / 2 - 300 / 2);
        //设置窗口容器
        Container container2 = getContentPane();
        container2.setBackground(Color.WHITE);
        //添加标题
        JLabel laber1 = new JLabel("车辆管理系统");
        laber1.setFont(new Font("宋体", Font.BOLD, 24));
        laber1.setBounds(240, 60, 160, 40);
        container2.add(laber1);
        //添加按钮"车辆信息管理"
        JButton button1 = new JButton("车辆信息管理");
        button1.setBounds(120, 120, 150, 60);
        Font f1=new Font("宋体",Font.BOLD,18);
        button1.setFont(f1);
        container2.add(button1);
        button1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                try {
                    new vehicle_information_control();
                } catch (SQLException throwables) {
                    throwables.printStackTrace();
                }
            }
        });
        //添加按钮"租车信息管理"
        JButton button2 = new JButton("租车信息管理");
        button2.setBounds(360, 120, 150, 60);
        Font f2=new Font("宋体",Font.BOLD,18);
        button2.setFont(f2);
        container2.add(button2);
        button2.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                try {
                    new rent_information_control();
                } catch (SQLException throwables) {
                    throwables.printStackTrace();
                }
            }
        });
        //添加按钮"还车信息管理"
        JButton button3 = new JButton("还车信息管理");
        button3.setBounds(120, 240, 150, 60);
        Font f3=new Font("宋体",Font.BOLD,18);
        button3.setFont(f3);
        container2.add(button3);
        button3.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                try {
                    new repay_information_control();
                } catch (SQLException throwables) {
                    throwables.printStackTrace();
                }
            }
        });
        //添加按钮"修车信息管理"
        JButton button4 = new JButton("修车信息管理");
        button4.setBounds(360, 240, 150, 60);
        Font f4=new Font("宋体",Font.BOLD,18);
        button4.setFont(f4);
        container2.add(button4);
        button4.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                try {
                    new repair_information_control();
                } catch (SQLException throwables) {
                    throwables.printStackTrace();
                }
            }
        });
        //添加按钮"利润分析"
        JButton button5 = new JButton("利润分析");
        button5.setBounds(250, 360, 150, 60);
        Font f5=new Font("宋体",Font.BOLD,18);
        button5.setFont(f5);
        container2.add(button5);
        button5.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                try {
                    new profit_analyze();
                } catch (SQLException throwables) {
                    throwables.printStackTrace();
                }
            }
        });
        //添加背景
        new extend().image(this,container2,"src/Image/蓝天.jpg");

        setVisible(true);
    }

}

vehicle_information_control

package Page;

import Main.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.*;
import java.util.*;

public class vehicle_information_control extends JFrame implements control{
    //rowData用来存放行数据,columnNames存放列名
    Vector rowData,columnNames;
    //定义数据库需要的全局变量
    PreparedStatement ps=null;
    Connection ct=null;
    ResultSet rs=null;
    public vehicle_information_control() throws SQLException {
        setTitle("车辆信息管理");

        setSize(600,450);
        new extend().changecoffee(this);
        setLayout(null);
        setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
        //获取屏幕大小,让窗口居中显示
        Dimension screenSize =Toolkit.getDefaultToolkit().getScreenSize();
        setLocation(screenSize.width/2-450/2,screenSize.height/2-300/2);
        //设置窗口容器
        Container container1=getContentPane();
        container1.setBackground(Color.WHITE);

        //添加内容
        JLabel l1=new JLabel("车辆信息");
        JLabel l2=new JLabel("信息操作");
        //设置字体和位置
        l1.setFont(new Font("宋体", Font.BOLD, 12));
        l1.setBounds(12,1,80,40);
        l2.setFont(new Font("宋体", Font.BOLD, 12));
        l2.setBounds(400,1,80,40);
        container1.add(l1);
        container1.add(l2);
        //建表
        columnNames=new Vector();
        //设置列名
        columnNames.add("车辆编号");
        columnNames.add("车辆名称");
        columnNames.add("车辆颜色");
        columnNames.add("车辆类型");
        columnNames.add("车辆计价");
        rowData=new Vector();
        JTable table=new JTable(rowData,columnNames);
        table.setBounds(10,30,390,360);
        table.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
        JScrollPane scrollpane=new JScrollPane(table);
        scrollpane.setBounds(10,30,390,360);
        //连接数据库读取数据
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/data?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&useSSL=false","root","240443");
            Statement statement = con.createStatement();
            ResultSet resultset = statement.executeQuery("select * from car");
            while (resultset.next()){
                //rowData可以存放多行
                Vector<String> hang=new Vector();
                hang.add(resultset.getString(1));
                hang.add(resultset.getString(2));
                hang.add(resultset.getString(3));
                hang.add(resultset.getString(4));
                hang.add(resultset.getString(5));
                //加入到rowData
                rowData.add(hang);
            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        container1.add(scrollpane);
        //信息管理
        JButton button1=new JButton("添加");
        Font font=new Font("宋体",Font.BOLD,16);
        button1.setFont(font);
        button1.setBounds(450,80,100,70);
        container1.add(button1);
        button1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new addCar();
                setVisible(false);
            }
        });
        JButton button2=new JButton("修改");
        button2.setFont(font);
        button2.setBounds(450,160,100,70);
        container1.add(button2);
        button2.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
             new changeCar();
             setVisible(false);
            }
        });
        JButton button3=new JButton("删除");
        button3.setFont(font);
        button3.setBounds(450,240,100,70);
        container1.add(button3);
        button3.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
               new removeCar();
               setVisible(false);
            }
        });
        new extend().image(this,container1,"src/Image/动漫.jpg");
        setVisible(true);
    }

    public static class changeCar extends JFrame{
        public changeCar() {
            setTitle("修改信息");
            setSize(450, 300);
            new extend().changecoffee(this);
            setLayout(null);
            setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
            //获取屏幕大小,让窗口居中显示
            Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
            setLocation(screenSize.width / 2 - 450 / 2, screenSize.height / 2 - 300 / 2);
            //设置窗口容器
            Container container = getContentPane();
            container.setBackground(Color.WHITE);
            //添加内容
            JLabel laber0 = new JLabel("车辆编号:");
            laber0.setFont(new Font("宋体", Font.BOLD, 18));
            laber0.setBounds(80, 10, 120, 30);
            container.add(laber0);
            JTextField text0 = new JTextField(16);
            text0.setBounds(170, 10, 130, 30);
            text0.setFont(new Font("宋体", Font.BOLD, 18));
            container.add(text0);
            JLabel laber1 = new JLabel("车辆名称:");
            laber1.setFont(new Font("宋体", Font.BOLD, 18));
            laber1.setBounds(80, 50, 120, 30);
            container.add(laber1);
            JTextField text1 = new JTextField(16);
            text1.setBounds(170, 50, 130, 30);
            text1.setFont(new Font("宋体", Font.BOLD, 18));
            container.add(text1);
            JLabel laber2 = new JLabel("车辆颜色:");
            laber2.setFont(new Font("宋体", Font.BOLD, 18));
            laber2.setBounds(80, 90, 120, 30);
            container.add(laber2);
            JTextField text2 = new JTextField(16);
            text2.setBounds(170, 90, 130, 30);
            text2.setFont(new Font("宋体", Font.BOLD, 18));
            container.add(text2);
            JLabel laber3 = new JLabel("车辆类型:");
            laber3.setFont(new Font("宋体", Font.BOLD, 18));
            laber3.setBounds(80, 130, 120, 30);
            container.add(laber3);
            JTextField text3 = new JTextField(16);
            text3.setBounds(170, 130, 130, 30);
            text3.setFont(new Font("宋体", Font.BOLD, 18));
            container.add(text3);
            JLabel laber4 = new JLabel("车辆计价:");
            laber4.setFont(new Font("宋体", Font.BOLD, 18));
            laber4.setBounds(80, 170, 130, 30);
            container.add(laber4);
            JTextField text4 = new JTextField(16);
            text4.setBounds(170, 170, 130, 30);
            text4.setFont(new Font("宋体", Font.BOLD, 18));
            container.add(text4);
            JButton button = new JButton("确认");
            button.setBounds(180, 230, 80, 30);
            Font f = new Font("宋体", Font.BOLD, 16);
            button.setFont(f);
            container.add(button);
            new extend().image(this,container,"src/Image/蓝天.jpg");
            setVisible(true);

            button.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    String sql = "update car set Name='" + text1.getText() + "', Color = '"+text2.getText()+"',Type = '"+text3.getText()+"',Price = '"+text4.getText()+"' where ID='" + text0.getText() + "'";
                    PreparedStatement pstmt;
                    try {
                        Class.forName("com.mysql.cj.jdbc.Driver");
                        Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/data?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&useSSL=false", "root", "240443");
                        Statement statement = con.createStatement();
                        pstmt = (PreparedStatement) con.prepareStatement(sql);
                        pstmt.executeUpdate();
                        /*pstmt.close();
                        con.close();*/
                        setVisible(false);
                        new vehicle_information_control();
                    } catch (Exception e1) {
                        e1.printStackTrace();
                    }
                }
            });
        }
    }
    public static class addCar extends JFrame {
        public addCar() {
            setTitle("增加车辆");
            setSize(450, 300);
            new extend().changecoffee(this);
            setLayout(null);
            setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
            //获取屏幕大小,让窗口居中显示
            Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
            setLocation(screenSize.width / 2 - 450 / 2, screenSize.height / 2 - 300 / 2);
            //设置窗口容器
            Container container = getContentPane();
            container.setBackground(Color.WHITE);
            //添加内容
            JLabel laber0 = new JLabel("车辆编号:");
            laber0.setFont(new Font("宋体", Font.BOLD, 18));
            laber0.setBounds(80, 10, 120, 30);
            container.add(laber0);
            JTextField text0 = new JTextField(16);
            text0.setBounds(170, 10, 130, 30);
            text0.setFont(new Font("宋体", Font.BOLD, 18));
            container.add(text0);
            JLabel laber1 = new JLabel("车辆名称:");
            laber1.setFont(new Font("宋体", Font.BOLD, 18));
            laber1.setBounds(80, 50, 120, 30);
            container.add(laber1);
            JTextField text1 = new JTextField(16);
            text1.setBounds(170, 50, 130, 30);
            text1.setFont(new Font("宋体", Font.BOLD, 18));
            container.add(text1);
            JLabel laber2 = new JLabel("车辆颜色:");
            laber2.setFont(new Font("宋体", Font.BOLD, 18));
            laber2.setBounds(80, 90, 120, 30);
            container.add(laber2);
            JTextField text2 = new JTextField(16);
            text2.setBounds(170, 90, 130, 30);
            text2.setFont(new Font("宋体", Font.BOLD, 18));
            container.add(text2);
            JLabel laber3 = new JLabel("车辆类型:");
            laber3.setFont(new Font("宋体", Font.BOLD, 18));
            laber3.setBounds(80, 130, 120, 30);
            container.add(laber3);
            JTextField text3 = new JTextField(16);
            text3.setBounds(170, 130, 130, 30);
            text3.setFont(new Font("宋体", Font.BOLD, 18));
            container.add(text3);
            JLabel laber4 = new JLabel("车辆计价:");
            laber4.setFont(new Font("宋体", Font.BOLD, 18));
            laber4.setBounds(80, 170, 130, 30);
            container.add(laber4);
            JTextField text4 = new JTextField(16);
            text4.setBounds(170, 170, 130, 30);
            text4.setFont(new Font("宋体", Font.BOLD, 18));
            container.add(text4);
            JButton button = new JButton("确认");
            button.setBounds(180, 230, 80, 30);
            Font f = new Font("宋体", Font.BOLD, 16);
            button.setFont(f);
            container.add(button);
            setVisible(true);

            button.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    String sql = "insert into car (ID,Name,Color,Type,Price) values(?,?,?,?,?)";
                    PreparedStatement pstmt;
                    try {
                        Class.forName("com.mysql.cj.jdbc.Driver");
                        Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/data?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&useSSL=false", "root", "240443");
                        Statement statement = con.createStatement();
                        pstmt = (PreparedStatement) con.prepareStatement(sql);
                        pstmt.setString(1, text0.getText());
                        pstmt.setString(2, text1.getText());
                        pstmt.setString(3,  text2.getText());
                        pstmt.setString(4,  text3.getText());
                        pstmt.setString(5,  text4.getText());
                        pstmt.executeUpdate();
                        /*pstmt.close();
                        con.close();*/
                        setVisible(false);
                        new vehicle_information_control();
                    } catch (Exception e1) {
                        e1.printStackTrace();
                    }
                }
            });
        }
    }
    public static class removeCar extends JFrame {
        public removeCar() {
            setTitle("删除车辆");
            setSize(300, 200);
            new extend().changecoffee(this);
            setLayout(null);
            setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
            //获取屏幕大小,让窗口居中显示
            Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
            setLocation(screenSize.width / 2 - 450 / 2, screenSize.height / 2 - 300 / 2);
            //设置窗口容器
            Container container = getContentPane();
            container.setBackground(Color.WHITE);
            //添加内容
            JLabel laber = new JLabel("车辆ID:");
            laber.setFont(new Font("宋体", Font.BOLD, 18));
            laber.setBounds(50, 20, 80, 30);
            container.add(laber);
            JTextField text = new JTextField(16);
            text.setBounds(130, 20, 90, 30);
            text.setFont(new Font("宋体", Font.BOLD, 18));
            container.add(text);
            JButton button = new JButton("确认");
            button.setBounds(100, 100, 80, 30);
            Font f = new Font("宋体", Font.BOLD, 16);
            button.setFont(f);
            container.add(button);
            setVisible(true);
            button.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    int i = 0;
                    String sql = "delete from car where ID='" + text.getText() + "'";
                    PreparedStatement pstmt;
                    try {
                        Class.forName("com.mysql.cj.jdbc.Driver");
                        Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/data?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&useSSL=false", "root", "240443");
                        Statement statement = con.createStatement();
                        pstmt = (PreparedStatement) con.prepareStatement(sql);
                        pstmt.executeUpdate();
                        /*pstmt.close();
                        con.close();*/
                        setVisible(false);
                        new vehicle_information_control();
                    } catch (Exception e1) {
                        e1.printStackTrace();
                    }
                }
            });
        }
    }

}

repay_information_control

package Page;

import Main.control;
import Main.extend;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.*;
import java.util.Vector;

public class repay_information_control extends JFrame  implements control {
    //rowData用来存放行数据,columnNames存放列名
    Vector rowData,columnNames;
    //定义数据库需要的全局变量
    PreparedStatement ps=null;
    Connection ct=null;
    ResultSet rs=null;
    public repay_information_control() throws SQLException {
        setTitle("还车信息管理");

        setSize(600,450);
        new extend().changecoffee(this);
        setLayout(null);
        setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
        //获取屏幕大小,让窗口居中显示
        Dimension screenSize =Toolkit.getDefaultToolkit().getScreenSize();
        setLocation(screenSize.width/2-450/2,screenSize.height/2-300/2);
        //设置窗口容器
        Container container1=getContentPane();
        container1.setBackground(Color.WHITE);

        //添加内容
        JLabel l1=new JLabel("车辆信息");
        JLabel l2=new JLabel("信息操作");
        //设置字体和位置
        l1.setFont(new Font("宋体", Font.BOLD, 12));
        l1.setBounds(12,1,80,40);
        l2.setFont(new Font("宋体", Font.BOLD, 12));
        l2.setBounds(400,1,80,40);
        container1.add(l1);
        container1.add(l2);
        //建表
        columnNames=new Vector();
        //设置列名
        columnNames.add("还车编号");
        columnNames.add("还车时间");
        columnNames.add("还车用户");
        columnNames.add("车辆ID");
        columnNames.add("还车状态");
        rowData=new Vector();
        JTable table=new JTable(rowData,columnNames);
        table.setBounds(10,30,390,360);
        table.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
        JScrollPane scrollpane=new JScrollPane(table);
        scrollpane.setBounds(10,30,390,360);
        //连接数据库读取数据
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/data?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&useSSL=false","root","240443");
            Statement statement = con.createStatement();
            ResultSet resultset = statement.executeQuery("select * from repaycar");
            while (resultset.next()){
                //rowData可以存放多行
                Vector hang=new Vector();
                hang.add(resultset.getString(1));
                hang.add(resultset.getString(2));
                hang.add(resultset.getString(3));
                hang.add(resultset.getString(4));
                hang.add(resultset.getString(5));
                //加入到rowData
                rowData.add(hang);
            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        container1.add(scrollpane);
        //信息管理
        JButton button1=new JButton("添加");
        Font font=new Font("宋体",Font.BOLD,16);
        button1.setFont(font);
        button1.setBounds(450,80,100,70);
        container1.add(button1);
        button1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new addCar();
                setVisible(false);
            }
        });
        JButton button2=new JButton("修改");
        button2.setFont(font);
        button2.setBounds(450,160,100,70);
        container1.add(button2);
        button2.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new changeCar();
                setVisible(false);
            }
        });
        JButton button3=new JButton("删除");
        button3.setFont(font);
        button3.setBounds(450,240,100,70);
        container1.add(button3);
        button3.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new removeCar();
                setVisible(false);
            }
        });
        new extend().image(this,container1,"src/Image/动漫.jpg");
        setVisible(true);
    }

    public static class changeCar extends JFrame{
        public changeCar() {
            setTitle("修改信息");
            setSize(450, 300);
            new extend().changecoffee(this);
            setLayout(null);
            setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
            //获取屏幕大小,让窗口居中显示
            Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
            setLocation(screenSize.width / 2 - 450 / 2, screenSize.height / 2 - 300 / 2);
            //设置窗口容器
            Container container = getContentPane();
            container.setBackground(Color.WHITE);
            //添加内容
            JLabel laber0 = new JLabel("还车编号:");
            laber0.setFont(new Font("宋体", Font.BOLD, 18));
            laber0.setBounds(80, 10, 120, 30);
            container.add(laber0);
            JTextField text0 = new JTextField(16);
            text0.setBounds(170, 10, 130, 30);
            text0.setFont(new Font("宋体", Font.BOLD, 18));
            container.add(text0);
            JLabel laber1 = new JLabel("还车用户:");
            laber1.setFont(new Font("宋体", Font.BOLD, 18));
            laber1.setBounds(80, 50, 120, 30);
            container.add(laber1);
            JTextField text1 = new JTextField(16);
            text1.setBounds(170, 50, 130, 30);
            text1.setFont(new Font("宋体", Font.BOLD, 18));
            container.add(text1);
            JLabel laber2 = new JLabel("还车时间:");
            laber2.setFont(new Font("宋体", Font.BOLD, 18));
            laber2.setBounds(80, 90, 120, 30);
            container.add(laber2);
            JTextField text2 = new JTextField(16);
            text2.setBounds(170, 90, 130, 30);
            text2.setFont(new Font("宋体", Font.BOLD, 18));
            container.add(text2);
            JLabel laber3 = new JLabel("车辆ID:");
            laber3.setFont(new Font("宋体", Font.BOLD, 18));
            laber3.setBounds(98, 130, 120, 30);
            container.add(laber3);
            JTextField text3 = new JTextField(16);
            text3.setBounds(170, 130, 130, 30);
            text3.setFont(new Font("宋体", Font.BOLD, 18));
            container.add(text3);
            JLabel laber4 = new JLabel("还车状态:");
            laber4.setFont(new Font("宋体", Font.BOLD, 18));
            laber4.setBounds(80, 170, 120, 30);
            container.add(laber4);
            JTextField text4 = new JTextField(16);
            text4.setBounds(170, 170, 130, 30);
            text4.setFont(new Font("宋体", Font.BOLD, 18));
            container.add(text4);
            JButton button = new JButton("确认");
            button.setBounds(180, 230, 80, 30);
            Font f = new Font("宋体", Font.BOLD, 16);
            button.setFont(f);
            container.add(button);
            setVisible(true);

            button.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    String sql = "update repaycar set RepayDate='" + text1.getText() + "', Name = '"+text2.getText()+"',CarID = '"+text3.getText()+"',Status = '"+text4.getText()+"' where ID='" + text0.getText() + "'";
                    PreparedStatement pstmt;
                    try {
                        Class.forName("com.mysql.cj.jdbc.Driver");
                        Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/data?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&useSSL=false", "root", "240443");
                        Statement statement = con.createStatement();
                        pstmt = (PreparedStatement) con.prepareStatement(sql);
                        pstmt.executeUpdate();
                        /*pstmt.close();
                        con.close();*/
                        setVisible(false);
                        new repay_information_control();
                    } catch (Exception e1) {
                        e1.printStackTrace();
                    }
                }
            });
        }
    }
    public static class addCar extends JFrame {
        public addCar() {
            setTitle("增加信息");
            setSize(450, 300);
            new extend().changecoffee(this);
            setLayout(null);
            setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
            //获取屏幕大小,让窗口居中显示
            Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
            setLocation(screenSize.width / 2 - 450 / 2, screenSize.height / 2 - 300 / 2);
            //设置窗口容器
            Container container = getContentPane();
            container.setBackground(Color.WHITE);
            //添加内容
            JLabel laber0 = new JLabel("还车编号:");
            laber0.setFont(new Font("宋体", Font.BOLD, 18));
            laber0.setBounds(80, 10, 120, 30);
            container.add(laber0);
            JTextField text0 = new JTextField(16);
            text0.setBounds(170, 10, 130, 30);
            text0.setFont(new Font("宋体", Font.BOLD, 18));
            container.add(text0);
            JLabel laber1 = new JLabel("还车用户:");
            laber1.setFont(new Font("宋体", Font.BOLD, 18));
            laber1.setBounds(80, 50, 120, 30);
            container.add(laber1);
            JTextField text1 = new JTextField(16);
            text1.setBounds(170, 50, 130, 30);
            text1.setFont(new Font("宋体", Font.BOLD, 18));
            container.add(text1);
            JLabel laber2 = new JLabel("还车时间:");
            laber2.setFont(new Font("宋体", Font.BOLD, 18));
            laber2.setBounds(80, 90, 120, 30);
            container.add(laber2);
            JTextField text2 = new JTextField(16);
            text2.setBounds(170, 90, 130, 30);
            text2.setFont(new Font("宋体", Font.BOLD, 18));
            container.add(text2);
            JLabel laber3 = new JLabel("车辆ID:");
            laber3.setFont(new Font("宋体", Font.BOLD, 18));
            laber3.setBounds(98, 130, 120, 30);
            container.add(laber3);
            JTextField text3 = new JTextField(16);
            text3.setBounds(170, 130, 130, 30);
            text3.setFont(new Font("宋体", Font.BOLD, 18));
            container.add(text3);
            JLabel laber4 = new JLabel("还车状态:");
            laber4.setFont(new Font("宋体", Font.BOLD, 18));
            laber4.setBounds(80, 170, 120, 30);
            container.add(laber4);
            JTextField text4 = new JTextField(16);
            text4.setBounds(170, 170, 130, 30);
            text4.setFont(new Font("宋体", Font.BOLD, 18));
            container.add(text4);
            JButton button = new JButton("确认");
            button.setBounds(180, 230, 80, 30);
            Font f = new Font("宋体", Font.BOLD, 16);
            button.setFont(f);
            container.add(button);
            setVisible(true);

            button.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    String sql = "insert into repaycar (ID,RepayDate,Name,CarID,Status) values(?,?,?,?,?)";
                    PreparedStatement pstmt;
                    try {
                        Class.forName("com.mysql.cj.jdbc.Driver");
                        Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/data?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&useSSL=false", "root", "240443");
                        Statement statement = con.createStatement();
                        pstmt = (PreparedStatement) con.prepareStatement(sql);
                        pstmt.setString(1, text0.getText());
                        pstmt.setString(2, text1.getText());
                        pstmt.setString(3,  text2.getText());
                        pstmt.setString(4,  text3.getText());
                        pstmt.setString(5,  text4.getText());
                        pstmt.executeUpdate();
                        /*pstmt.close();
                        con.close();*/
                        setVisible(false);
                        new repay_information_control();
                    } catch (Exception e1) {
                        e1.printStackTrace();
                    }
                }
            });
        }
    }
    public static class removeCar extends JFrame {
        public removeCar() {
            setTitle("删除信息");
            setSize(300, 200);
            new extend().changecoffee(this);
            setLayout(null);
            setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
            //获取屏幕大小,让窗口居中显示
            Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
            setLocation(screenSize.width / 2 - 450 / 2, screenSize.height / 2 - 300 / 2);
            //设置窗口容器
            Container container = getContentPane();
            container.setBackground(Color.WHITE);
            //添加内容
            JLabel laber = new JLabel("还车编号:");
            laber.setFont(new Font("宋体", Font.BOLD, 18));
            laber.setBounds(40, 20, 90, 30);
            container.add(laber);
            JTextField text = new JTextField(16);
            text.setBounds(130, 20, 90, 30);
            text.setFont(new Font("宋体", Font.BOLD, 18));
            container.add(text);
            JButton button = new JButton("确认");
            button.setBounds(100, 100, 80, 30);
            Font f = new Font("宋体", Font.BOLD, 16);
            button.setFont(f);
            container.add(button);
            new extend().image(this,container,"src/Image/蓝天.jpg");
            setVisible(true);
            button.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    int i = 0;
                    String sql = "delete from repaycar where ID='" + text.getText() + "'";
                    PreparedStatement pstmt;
                    try {
                        Class.forName("com.mysql.cj.jdbc.Driver");
                        Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/data?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&useSSL=false", "root", "240443");
                        Statement statement = con.createStatement();
                        pstmt = (PreparedStatement) con.prepareStatement(sql);
                        pstmt.executeUpdate();
                        /*pstmt.close();
                        con.close();*/
                        setVisible(false);
                        new repay_information_control();
                    } catch (Exception e1) {
                        e1.printStackTrace();
                    }
                }
            });
        }
    }

}

repair_information_control
package Page;

import Main.control;
import Main.extend;

import javax.swing.;
import java.awt.
;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.*;
import java.util.Vector;

public class repair_information_control extends JFrame implements control {
//rowData用来存放行数据,columnNames存放列名
Vector rowData,columnNames;
//定义数据库需要的全局变量
PreparedStatement ps=null;
Connection ct=null;
ResultSet rs=null;
public repair_information_control() throws SQLException {
setTitle(“修车信息管理”);

    setSize(600,450);
    new extend().changecoffee(this);
    setLayout(null);
    setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
    //获取屏幕大小,让窗口居中显示
    Dimension screenSize =Toolkit.getDefaultToolkit().getScreenSize();
    setLocation(screenSize.width/2-450/2,screenSize.height/2-300/2);
    //设置窗口容器
    Container container1=getContentPane();
    container1.setBackground(Color.WHITE);

    //添加内容
    JLabel l1=new JLabel("车辆信息");
    JLabel l2=new JLabel("信息操作");
    //设置字体和位置
    l1.setFont(new Font("宋体", Font.BOLD, 12));
    l1.setBounds(12,1,80,40);
    l2.setFont(new Font("宋体", Font.BOLD, 12));
    l2.setBounds(400,1,80,40);
    container1.add(l1);
    container1.add(l2);
    //建表
    columnNames=new Vector();
    //设置列名
    columnNames.add("修车编号");
    columnNames.add("修车时间");
    columnNames.add("车辆故障");
    columnNames.add("车辆ID");
    columnNames.add("修车费用");
    rowData=new Vector();
    JTable table=new JTable(rowData,columnNames);
    table.setBounds(10,30,390,360);
    table.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
    JScrollPane scrollpane=new JScrollPane(table);
    scrollpane.setBounds(10,30,390,360);
    //连接数据库读取数据
    try {
        Class.forName("com.mysql.cj.jdbc.Driver");
        Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/data?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&useSSL=false","root","240443");
        Statement statement = con.createStatement();
        ResultSet resultset = statement.executeQuery("select * from repaircar");
        while (resultset.next()){
            //rowData可以存放多行
            Vector hang=new Vector();
            hang.add(resultset.getInt(1));
            hang.add(resultset.getString(2));
            hang.add(resultset.getString(3));
            hang.add(resultset.getString(4));
            hang.add(resultset.getInt(5));
            //加入到rowData
            rowData.add(hang);
        }
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }
    container1.add(scrollpane);
    //信息管理
    JButton button1=new JButton("添加");
    Font font=new Font("宋体",Font.BOLD,16);
    button1.setFont(font);
    button1.setBounds(450,80,100,70);
    container1.add(button1);
    button1.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            new addCar();
            setVisible(false);
        }
    });
    JButton button2=new JButton("修改");
    button2.setFont(font);
    button2.setBounds(450,160,100,70);
    container1.add(button2);
    button2.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            new changeCar();
            setVisible(false);
        }
    });
    JButton button3=new JButton("删除");
    button3.setFont(font);
    button3.setBounds(450,240,100,70);
    container1.add(button3);
    button3.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            new removeCar();
            setVisible(false);
        }
    });
    new extend().image(this,container1,"src/Image/动漫.jpg");
    setVisible(true);
}

public static class changeCar extends JFrame{
    public changeCar() {
        setTitle("修改信息");
        setSize(450, 300);
        new extend().changecoffee(this);
        setLayout(null);
        setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
        //获取屏幕大小,让窗口居中显示
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        setLocation(screenSize.width / 2 - 450 / 2, screenSize.height / 2 - 300 / 2);
        //设置窗口容器
        Container container = getContentPane();
        container.setBackground(Color.WHITE);
        //添加内容
        JLabel laber0 = new JLabel("修车编号:");
        laber0.setFont(new Font("宋体", Font.BOLD, 18));
        laber0.setBounds(80, 10, 120, 30);
        container.add(laber0);
        JTextField text0 = new JTextField(16);
        text0.setBounds(170, 10, 130, 30);
        text0.setFont(new Font("宋体", Font.BOLD, 18));
        container.add(text0);
        JLabel laber1 = new JLabel("修车时间:");
        laber1.setFont(new Font("宋体", Font.BOLD, 18));
        laber1.setBounds(80, 50, 120, 30);
        container.add(laber1);
        JTextField text1 = new JTextField(16);
        text1.setBounds(170, 50, 130, 30);
        text1.setFont(new Font("宋体", Font.BOLD, 18));
        container.add(text1);
        JLabel laber2 = new JLabel("车辆故障:");
        laber2.setFont(new Font("宋体", Font.BOLD, 18));
        laber2.setBounds(80, 90, 120, 30);
        container.add(laber2);
        JTextField text2 = new JTextField(16);
        text2.setBounds(170, 90, 130, 30);
        text2.setFont(new Font("宋体", Font.BOLD, 18));
        container.add(text2);
        JLabel laber3 = new JLabel("车辆ID:");
        laber3.setFont(new Font("宋体", Font.BOLD, 18));
        laber3.setBounds(98, 130, 120, 30);
        container.add(laber3);
        JTextField text3 = new JTextField(16);
        text3.setBounds(170, 130, 130, 30);
        text3.setFont(new Font("宋体", Font.BOLD, 18));
        container.add(text3);
        JLabel laber4 = new JLabel("修车费用:");
        laber4.setFont(new Font("宋体", Font.BOLD, 18));
        laber4.setBounds(80, 170, 120, 30);
        container.add(laber4);
        JTextField text4 = new JTextField(16);
        text4.setBounds(170, 170, 130, 30);
        text4.setFont(new Font("宋体", Font.BOLD, 18));
        container.add(text4);
        JButton button = new JButton("确认");
        button.setBounds(180, 230, 80, 30);
        Font f = new Font("宋体", Font.BOLD, 16);
        button.setFont(f);
        container.add(button);
        //new extend().image(this,container,"src/Image/动漫.jpg");
        setVisible(true);

        button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String sql = "update repaircar set FixDate='" + text1.getText() + "', Question = '"+text2.getText()+"',Price = '"+text3.getText()+"',CarID = '"+text4.getText()+"' where ID='" + text0.getText() + "'";
                PreparedStatement pstmt;
                try {
                    Class.forName("com.mysql.cj.jdbc.Driver");
                    Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/data?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&useSSL=false", "root", "240443");
                    Statement statement = con.createStatement();
                    pstmt = (PreparedStatement) con.prepareStatement(sql);
                    pstmt.executeUpdate();
                    /*pstmt.close();
                    con.close();*/
                    setVisible(false);
                    new repair_information_control();
                } catch (Exception e1) {
                    e1.printStackTrace();
                }
            }
        });
    }
}
public static class addCar extends JFrame {
    public addCar() {
        setTitle("增加信息");
        setSize(450, 300);
        new extend().changecoffee(this);
        setLayout(null);
        setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
        //获取屏幕大小,让窗口居中显示
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        setLocation(screenSize.width / 2 - 450 / 2, screenSize.height / 2 - 300 / 2);
        //设置窗口容器
        Container container = getContentPane();
        container.setBackground(Color.WHITE);
        //添加内容
        JLabel laber0 = new JLabel("修车编号:");
        laber0.setFont(new Font("宋体", Font.BOLD, 18));
        laber0.setBounds(80, 10, 120, 30);
        container.add(laber0);
        JTextField text0 = new JTextField(16);
        text0.setBounds(170, 10, 130, 30);
        text0.setFont(new Font("宋体", Font.BOLD, 18));
        container.add(text0);
        JLabel laber1 = new JLabel("修车时间:");
        laber1.setFont(new Font("宋体", Font.BOLD, 18));
        laber1.setBounds(80, 50, 120, 30);
        container.add(laber1);
        JTextField text1 = new JTextField(16);
        text1.setBounds(170, 50, 130, 30);
        text1.setFont(new Font("宋体", Font.BOLD, 18));
        container.add(text1);
        JLabel laber2 = new JLabel("车辆故障:");
        laber2.setFont(new Font("宋体", Font.BOLD, 18));
        laber2.setBounds(80, 90, 120, 30);
        container.add(laber2);
        JTextField text2 = new JTextField(16);
        text2.setBounds(170, 90, 130, 30);
        text2.setFont(new Font("宋体", Font.BOLD, 18));
        container.add(text2);
        JLabel laber3 = new JLabel("车辆ID:");
        laber3.setFont(new Font("宋体", Font.BOLD, 18));
        laber3.setBounds(98, 130, 120, 30);
        container.add(laber3);
        JTextField text3 = new JTextField(16);
        text3.setBounds(170, 130, 130, 30);
        text3.setFont(new Font("宋体", Font.BOLD, 18));
        container.add(text3);
        JLabel laber4 = new JLabel("修车费用:");
        laber4.setFont(new Font("宋体", Font.BOLD, 18));
        laber4.setBounds(80, 170, 120, 30);
        container.add(laber4);
        JTextField text4 = new JTextField(16);
        text4.setBounds(170, 170, 130, 30);
        text4.setFont(new Font("宋体", Font.BOLD, 18));
        container.add(text4);
        JButton button = new JButton("确认");
        button.setBounds(180, 230, 80, 30);
        Font f = new Font("宋体", Font.BOLD, 16);
        button.setFont(f);
        container.add(button);
        setVisible(true);

        button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String sql = "insert into repaircar (ID,FixDate,Question,Price,CarID) values(?,?,?,?,?)";
                PreparedStatement pstmt;
                try {
                    Class.forName("com.mysql.cj.jdbc.Driver");
                    Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/data?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&useSSL=false", "root", "240443");
                    Statement statement = con.createStatement();
                    pstmt = (PreparedStatement) con.prepareStatement(sql);
                    pstmt.setString(1, text0.getText());
                    pstmt.setString(2, text1.getText());
                    pstmt.setString(3,  text2.getText());
                    pstmt.setString(4,  text3.getText());
                    pstmt.setString(5,  text4.getText());
                    pstmt.executeUpdate();
                    /*pstmt.close();
                    con.close();*/
                    setVisible(false);
                    new repair_information_control();
                } catch (Exception e1) {
                    e1.printStackTrace();
                }
            }
        });
    }
}
public static class removeCar extends JFrame {
    public removeCar() {
        setTitle("删除信息");
        setSize(300, 200);
        new extend().changecoffee(this);
        setLayout(null);
        setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
        //获取屏幕大小,让窗口居中显示
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        setLocation(screenSize.width / 2 - 450 / 2, screenSize.height / 2 - 300 / 2);
        //设置窗口容器
        Container container = getContentPane();
        container.setBackground(Color.WHITE);
        //添加内容
        JLabel laber = new JLabel("修车编号:");
        laber.setFont(new Font("宋体", Font.BOLD, 18));
        laber.setBounds(40, 20, 90, 30);
        container.add(laber);
        JTextField text = new JTextField(16);
        text.setBounds(130, 20, 90, 30);
        text.setFont(new Font("宋体", Font.BOLD, 18));
        container.add(text);
        JButton button = new JButton("确认");
        button.setBounds(100, 100, 80, 30);
        Font f = new Font("宋体", Font.BOLD, 16);
        button.setFont(f);
        container.add(button);
        setVisible(true);
        button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                int i = 0;
                String sql = "delete from repaircar where ID='" + text.getText() + "'";
                PreparedStatement pstmt;
                try {
                    Class.forName("com.mysql.cj.jdbc.Driver");
                    Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/data?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&useSSL=false", "root", "240443");
                    Statement statement = con.createStatement();
                    pstmt = (PreparedStatement) con.prepareStatement(sql);
                    pstmt.executeUpdate();
                    /*pstmt.close();
                    con.close();*/
                    setVisible(false);
                    new repair_information_control();
                } catch (Exception e1) {
                    e1.printStackTrace();
                }
            }
        });
    }
}

}
rent_information_control

package Page;

import Main.control;
import Main.extend;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.*;
import java.util.Vector;

public class rent_information_control extends JFrame  implements control {
    //rowData用来存放行数据,columnNames存放列名
    Vector rowData,columnNames;
    //定义数据库需要的全局变量
    PreparedStatement ps=null;
    Connection ct=null;
    ResultSet rs=null;
    public rent_information_control() throws SQLException {
        setTitle("租车信息管理");

        setSize(600,450);
        new extend().changecoffee(this);
        setLayout(null);
        setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
        //获取屏幕大小,让窗口居中显示
        Dimension screenSize =Toolkit.getDefaultToolkit().getScreenSize();
        setLocation(screenSize.width/2-450/2,screenSize.height/2-300/2);
        //设置窗口容器
        Container container1=getContentPane();
        container1.setBackground(Color.WHITE);

        //添加内容
        JLabel l1=new JLabel("车辆信息");
        JLabel l2=new JLabel("信息操作");
        //设置字体和位置
        l1.setFont(new Font("宋体", Font.BOLD, 12));
        l1.setBounds(12,1,80,40);
        l2.setFont(new Font("宋体", Font.BOLD, 12));
        l2.setBounds(400,1,80,40);
        container1.add(l1);
        container1.add(l2);
        //建表
        columnNames=new Vector();
        //设置列名
        columnNames.add("租车编号");
        columnNames.add("租车时间");
        columnNames.add("租车用户");
        columnNames.add("车辆ID");
        columnNames.add("租车费用");
        rowData=new Vector();
        JTable table=new JTable(rowData,columnNames);
        table.setBounds(10,30,390,360);
        table.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
        JScrollPane scrollpane=new JScrollPane(table);
        scrollpane.setBounds(10,30,390,360);
        //连接数据库读取数据
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/data?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&useSSL=false","root","240443");
            Statement statement = con.createStatement();
            ResultSet resultset = statement.executeQuery("select * from rentcar");
            while (resultset.next()){
                //rowData可以存放多行
                Vector hang=new Vector();
                hang.add(resultset.getString(1));
                hang.add(resultset.getString(2));
                hang.add(resultset.getString(3));
                hang.add(resultset.getString(4));
                hang.add(resultset.getString(5));
                //加入到rowData
                rowData.add(hang);
            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        container1.add(scrollpane);
        //信息管理
        JButton button1=new JButton("添加");
        Font font=new Font("宋体",Font.BOLD,16);
        button1.setFont(font);
        button1.setBounds(450,80,100,70);
        container1.add(button1);
        button1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new addCar();
                setVisible(false);
            }
        });
        JButton button2=new JButton("修改");
        button2.setFont(font);
        button2.setBounds(450,160,100,70);
        container1.add(button2);
        button2.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new changeCar();
                setVisible(false);
            }
        });
        JButton button3=new JButton("删除");
        button3.setFont(font);
        button3.setBounds(450,240,100,70);
        container1.add(button3);
        button3.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new removeCar();
                setVisible(false);
            }
        });
        new extend().image(this,container1,"src/Image/动漫.jpg");
        setVisible(true);
    }

    public static class changeCar extends JFrame{
        public changeCar() {
            setTitle("修改信息");
            setSize(450, 300);
            new extend().changecoffee(this);
            setLayout(null);
            setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
            //获取屏幕大小,让窗口居中显示
            Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
            setLocation(screenSize.width / 2 - 450 / 2, screenSize.height / 2 - 300 / 2);
            //设置窗口容器
            Container container = getContentPane();
            container.setBackground(Color.WHITE);
            //添加内容
            JLabel laber0 = new JLabel("租车编号:");
            laber0.setFont(new Font("宋体", Font.BOLD, 18));
            laber0.setBounds(80, 10, 120, 30);
            container.add(laber0);
            JTextField text0 = new JTextField(16);
            text0.setBounds(170, 10, 130, 30);
            text0.setFont(new Font("宋体", Font.BOLD, 18));
            container.add(text0);
            JLabel laber1 = new JLabel("租车时间:");
            laber1.setFont(new Font("宋体", Font.BOLD, 18));
            laber1.setBounds(80, 50, 120, 30);
            container.add(laber1);
            JTextField text1 = new JTextField(16);
            text1.setBounds(170, 50, 130, 30);
            text1.setFont(new Font("宋体", Font.BOLD, 18));
            container.add(text1);
            JLabel laber2 = new JLabel("租车用户:");
            laber2.setFont(new Font("宋体", Font.BOLD, 18));
            laber2.setBounds(80, 90, 120, 30);
            container.add(laber2);
            JTextField text2 = new JTextField(16);
            text2.setBounds(170, 90, 130, 30);
            text2.setFont(new Font("宋体", Font.BOLD, 18));
            container.add(text2);
            JLabel laber3 = new JLabel("车辆ID:");
            laber3.setFont(new Font("宋体", Font.BOLD, 18));
            laber3.setBounds(98, 130, 120, 30);
            container.add(laber3);
            JTextField text3 = new JTextField(16);
            text3.setBounds(170, 130, 130, 30);
            text3.setFont(new Font("宋体", Font.BOLD, 18));
            container.add(text3);
            JLabel laber4 = new JLabel("租车费用:");
            laber4.setFont(new Font("宋体", Font.BOLD, 18));
            laber4.setBounds(80, 170, 120, 30);
            container.add(laber4);
            JTextField text4 = new JTextField(16);
            text4.setBounds(170, 170, 130, 30);
            text4.setFont(new Font("宋体", Font.BOLD, 18));
            container.add(text4);
            JButton button = new JButton("确认");
            button.setBounds(180, 230, 80, 30);
            Font f = new Font("宋体", Font.BOLD, 16);
            button.setFont(f);
            container.add(button);
            setVisible(true);

            button.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    String sql = "update rentcar set RentDate='" + text1.getText() + "', Name = '"+text2.getText()+"',CarId = '"+text3.getText()+"',Price = '"+text4.getText()+"' where ID='" + text0.getText() + "'";
                    PreparedStatement pstmt;
                    try {
                        Class.forName("com.mysql.cj.jdbc.Driver");
                        Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/data?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&useSSL=false", "root", "240443");
                        Statement statement = con.createStatement();
                        pstmt = (PreparedStatement) con.prepareStatement(sql);
                        pstmt.executeUpdate();
                        /*pstmt.close();
                        con.close();*/
                        setVisible(false);
                        new rent_information_control();
                    } catch (Exception e1) {
                        e1.printStackTrace();
                    }
                }
            });
        }
    }
    public static class addCar extends JFrame {
        public addCar() {
            setTitle("增加信息");
            setSize(450, 300);
            new extend().changecoffee(this);
            setLayout(null);
            setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
            //获取屏幕大小,让窗口居中显示
            Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
            setLocation(screenSize.width / 2 - 450 / 2, screenSize.height / 2 - 300 / 2);
            //设置窗口容器
            Container container = getContentPane();
            container.setBackground(Color.WHITE);
            //添加内容
            //添加内容
            JLabel laber0 = new JLabel("租车编号:");
            laber0.setFont(new Font("宋体", Font.BOLD, 18));
            laber0.setBounds(80, 10, 120, 30);
            container.add(laber0);
            JTextField text0 = new JTextField(16);
            text0.setBounds(170, 10, 130, 30);
            text0.setFont(new Font("宋体", Font.BOLD, 18));
            container.add(text0);
            JLabel laber1 = new JLabel("租车时间:");
            laber1.setFont(new Font("宋体", Font.BOLD, 18));
            laber1.setBounds(80, 50, 120, 30);
            container.add(laber1);
            JTextField text1 = new JTextField(16);
            text1.setBounds(170, 50, 130, 30);
            text1.setFont(new Font("宋体", Font.BOLD, 18));
            container.add(text1);
            JLabel laber2 = new JLabel("租车用户:");
            laber2.setFont(new Font("宋体", Font.BOLD, 18));
            laber2.setBounds(80, 90, 120, 30);
            container.add(laber2);
            JTextField text2 = new JTextField(16);
            text2.setBounds(170, 90, 130, 30);
            text2.setFont(new Font("宋体", Font.BOLD, 18));
            container.add(text2);
            JLabel laber3 = new JLabel("车辆ID:");
            laber3.setFont(new Font("宋体", Font.BOLD, 18));
            laber3.setBounds(98, 130, 120, 30);
            container.add(laber3);
            JTextField text3 = new JTextField(16);
            text3.setBounds(170, 130, 130, 30);
            text3.setFont(new Font("宋体", Font.BOLD, 18));
            container.add(text3);
            JLabel laber4 = new JLabel("租车费用:");
            laber4.setFont(new Font("宋体", Font.BOLD, 18));
            laber4.setBounds(80, 170, 120, 30);
            container.add(laber4);
            JTextField text4 = new JTextField(16);
            text4.setBounds(170, 170, 130, 30);
            text4.setFont(new Font("宋体", Font.BOLD, 18));
            container.add(text4);
            JButton button = new JButton("确认");
            button.setBounds(180, 230, 80, 30);
            Font f = new Font("宋体", Font.BOLD, 16);
            button.setFont(f);
            container.add(button);
            setVisible(true);

            button.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    String sql = "insert into rentcar (ID,RentDate,Name,CarId,Price) values(?,?,?,?,?)";
                    PreparedStatement pstmt;
                    try {
                        Class.forName("com.mysql.cj.jdbc.Driver");
                        Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/data?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&useSSL=false", "root", "240443");
                        Statement statement = con.createStatement();
                        pstmt = (PreparedStatement) con.prepareStatement(sql);
                        pstmt.setString(1, text0.getText());
                        pstmt.setString(2, text1.getText());
                        pstmt.setString(3,  text2.getText());
                        pstmt.setString(4,  text3.getText());
                        pstmt.setString(5,  text4.getText());
                        pstmt.executeUpdate();
                        /*pstmt.close();
                        con.close();*/
                        setVisible(false);
                        new rent_information_control();
                    } catch (Exception e1) {
                        e1.printStackTrace();
                    }
                }
            });
        }
    }
    public static class removeCar extends JFrame {
        public removeCar() {
            setTitle("删除信息");
            setSize(300, 200);
            new extend().changecoffee(this);
            setLayout(null);
            setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
            //获取屏幕大小,让窗口居中显示
            Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
            setLocation(screenSize.width / 2 - 450 / 2, screenSize.height / 2 - 300 / 2);
            //设置窗口容器
            Container container = getContentPane();
            container.setBackground(Color.WHITE);
            //添加内容
            JLabel laber = new JLabel("租车编号:");
            laber.setFont(new Font("宋体", Font.BOLD, 18));
            laber.setBounds(40, 20, 90, 30);
            container.add(laber);
            JTextField text = new JTextField(16);
            text.setBounds(130, 20, 90, 30);
            text.setFont(new Font("宋体", Font.BOLD, 18));
            container.add(text);
            JButton button = new JButton("确认");
            button.setBounds(100, 100, 80, 30);
            Font f = new Font("宋体", Font.BOLD, 16);
            button.setFont(f);
            container.add(button);
            new extend().image(this,container,"src/Image/蓝天.jpg");
            setVisible(true);
            button.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    int i = 0;
                    String sql = "delete from rentcar where ID='" + text.getText() + "'";
                    PreparedStatement pstmt;
                    try {
                        Class.forName("com.mysql.cj.jdbc.Driver");
                        Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/data?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&useSSL=false", "root", "240443");
                        Statement statement = con.createStatement();
                        pstmt = (PreparedStatement) con.prepareStatement(sql);
                        pstmt.executeUpdate();
                        /*pstmt.close();
                        con.close();*/
                        setVisible(false);
                        new rent_information_control();
                    } catch (Exception e1) {
                        e1.printStackTrace();
                    }
                }
            });
        }
    }

}

profit_analyze

package Page;

import Main.extend;

import javax.swing.*;
import java.awt.*;
import java.sql.*;
import java.text.DecimalFormat;

public class profit_analyze extends JFrame {
    profit_analyze() throws SQLException {
        setSize(300,200);
        setTitle("利润分析");
        new extend().changecoffee(this);
        setLayout(null);
        setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
        //获取屏幕大小,让窗口居中显示
        Dimension screenSize =Toolkit.getDefaultToolkit().getScreenSize();
        setLocation(screenSize.width/2-450/2,screenSize.height/2-300/2);
        //设置窗口容器
        Container container1=getContentPane();
        container1.setBackground(Color.WHITE);
        //new extend().image(this,container1,"src/Image/蓝天.png");
        double sum=0;
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/data?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&useSSL=false","root","240443");
            Statement statement = con.createStatement();
            ResultSet earn = statement.executeQuery("select * from rentcar");
            while(earn.next()){
                String s= earn.getString("Price");
                double d=Double.parseDouble(s);
                sum+=d;
            }
            ResultSet pay = statement.executeQuery("select * from repaircar");
            while(pay.next()){
                    String s1= pay.getString("Price");
                double d1=Double.parseDouble(s1);
                sum-=d1;
            }
            //保留两位小数
            DecimalFormat df = new DecimalFormat("#.00");
            String money=df.format(sum);
            //添加内容
            JLabel laber1=new JLabel(money);
            laber1.setFont(new Font("宋体",Font.BOLD,18));
            laber1.setBounds(160,60,80,30);
            container1.add(laber1);
            JLabel laber2=new JLabel("净利润:");
            laber2.setFont(new Font("宋体",Font.BOLD,18));
            laber2.setBounds(90,60,80,30);
            container1.add(laber2);

            setVisible(true);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
}

在这里插入图片描述
本系统写的比较简单,不需要每个单独做,都是相同的框架,数据库在git下载,git地址在代码前已经给出,仍有可以改进的地方,比如数据库的级联,请自行更改。得来不易,欢迎Git上给个小星星哦!

  • 22
    点赞
  • 83
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值