The complete source code of the java train ticket sales and purchase system, with functions such as ticket purchase, refund, and rebooking 436

Some time ago, the company was too busy, and the CSDN blog stopped updating for almost two months. Today I would like to share with you a java train ticket reservation system 436. At present, the system has very comprehensive functions, including ticket purchase, refund, rebooking and other functions, which are very close to the actual purchase of train tickets. The interface of the whole system is beautiful, with complete source code, I hope everyone can like it. Help like and follow. Program together and progress together.

development environment

The development language is Java, and the development environment is Eclipse or IDEA. Database used: MySQL. Run the main program, or execute and open the JAR file to run the program.

system framework

Developed using the SWING framework that comes with the JDK, there is no need to install third-party JAR packages. MySQL database, pure form mode, just run the Main file directly. At the same time with detailed design documents. The running method can directly run as appliaiton or JAR --.jar

The main function

The train ticket sales system is written in Java language. It is a typical window program written in the swing framework. The system involves operations such as files, UI, database operations, and events. The system is divided into system administrators and ordinary users:

1 The main functions of the system administrator are as follows:

User management: perform daily maintenance on users in the system. Including adding users, deleting users, modifying users

Train management: perform daily maintenance on the train information in the system. Including increasing number, capacity

Fare management: daily maintenance of train types, including adding, deleting, and modifying operations. Including high-speed rail, express, ordinary cars

 Ticket price management: set the prices of hard seats, sleepers, first-class seats, business seats, etc.

2 The main functions of ordinary users include the following functions

User login: Enter the user name and password to log in to the system

Train ticket purchase: Find out the eligible cities according to the conditions, and then click to book. Train tickets: hardware tickets, sleeper tickets, no-seat tickets

Order query: query the train ticket information ordered by the user

Refund and rebooking: Rebooking and refunding the purchased train tickets is a common function and one of the main features of the system.

Contacts: Manage your main contacts, including adding, deleting, and modifying contacts. The contact person needs to enter: name, ID card, phone number and other information.

running result

1 user login

2 user registration

3 Line maintenance and management

4 Price management and maintenance

5 User Management

 6 User purchases tickets

 

7 Order View

 8 Contact Management

key code

 public LoginWindow(String title) {
        //设置登录界面题头和符号
        setTitle(title);
        String iconSrc = "picture/logo1.jpg";
        ImageIcon icon = new ImageIcon(iconSrc);
        setIconImage(icon.getImage());

        //自定义设置主界面主面板的背景
        String bgdSrc = "picture/rail5.jpg";
        ImageIcon background = new ImageIcon(bgdSrc);
        Background.setBackgroundPicture(this, background);

        //界面显示信息面板
        JLabel lbl_show = new JLabel("售票登陆系统");
        lbl_show.setForeground(Color.WHITE);
        lbl_show.setFont(new Font("楷体", Font.PLAIN, 65));
        lbl_show.setHorizontalAlignment(JLabel.CENTER);
        JPanel jp_show = new JPanel();
        jp_show.setOpaque(false);
        jp_show.add(lbl_show);

        //用户信息模块
        //1.手机号
        JLabel lbl_tel;
        lbl_tel = new JLabel("手机号:");
        lbl_tel.setForeground(Color.WHITE);
        lbl_tel.setFont(new Font("楷体", Font.BOLD, 30));
        lbl_tel.setHorizontalAlignment(SwingConstants.CENTER);
        //2.密码
        JLabel lbl_password = new JLabel("密  码:");
        lbl_password.setForeground(Color.WHITE);
        lbl_password.setFont(new Font("楷体", Font.BOLD, 30));
        lbl_password.setHorizontalAlignment(SwingConstants.CENTER);
        //3.身份选择
        JLabel lbl_role = new JLabel("身  份:");
        lbl_role.setForeground(Color.WHITE);
        lbl_role.setFont(new Font("楷体", Font.BOLD, 30));
        lbl_role.setHorizontalAlignment(SwingConstants.CENTER);
        //4.信息输入框
        txt_tel = new JTextField(15);
        txt_password = new JPasswordField(20);
        com_role = new JComboBox<>(new String[]{"乘客", "管理员"});
        //5.用户信息面板(排版)
        JPanel jp_userInfo = new JPanel();
        jp_userInfo.setOpaque(false);//将面板背景设计为透明,因为要显示自定义的背景图片
        jp_userInfo.setLayout(new GridLayout(7, 2));
        jp_userInfo.add(new JLabel());
        jp_userInfo.add(new JLabel());
        jp_userInfo.add(lbl_tel);
        jp_userInfo.add(txt_tel);
        jp_userInfo.add(new JLabel());
        jp_userInfo.add(new JLabel());
        jp_userInfo.add(lbl_password);
        jp_userInfo.add(txt_password);
        jp_userInfo.add(new JLabel());
        jp_userInfo.add(new JLabel());
        jp_userInfo.add(lbl_role);
        jp_userInfo.add(com_role);
        jp_userInfo.add(new JLabel());
        jp_userInfo.add(new JLabel());

        // 登录界面功能按钮模块
        //1.登录按钮
        btn_login = new JButton("登录");
        btn_login.setFont(new Font("楷体", Font.PLAIN, 20));
        btn_login.addActionListener(this);
        //2.注册按钮
        btn_register = new JButton("注册");
        btn_register.setFont(new Font("楷体", Font.PLAIN, 20));
        btn_register.addActionListener(this);
        //3.取消按钮
        btn_cancel = new JButton("取消");
        btn_cancel.setFont(new Font("楷体", Font.PLAIN, 20));
        btn_cancel.addActionListener(this);
        //4.功能按钮面板
        JPanel jp_functionBtn = new JPanel();
        jp_functionBtn.setOpaque(false);
        jp_functionBtn.add(btn_login);
        jp_functionBtn.add(btn_register);
        jp_functionBtn.add(btn_cancel);

        //设置主面板布局,并添加上面自定义的面板
        this.setLayout(new BorderLayout());
        this.add(jp_show, BorderLayout.NORTH);
        this.add(jp_userInfo, BorderLayout.CENTER);
        this.add(jp_functionBtn, BorderLayout.SOUTH);
        this.validate();
        this.setVisible(true);
        this.setSize(background.getIconWidth(), background.getIconHeight());
        this.setResizable(false);
        this.setLocationRelativeTo(null);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

project summary

(1) Before writing the code, the thinking must be clear in the brain, and the function diagram and flow chart must be drawn, and then each function block should be realized according to it. A good logical thinking ability.

(2) In the process of writing code, the principle of proximity must be adopted. Generally, the same function or the settings for the same component should be written together, so that the program written in this way is clearer, less prone to errors, and easier to find.

(3) To develop good commenting habits, first, it is beneficial for others to read your program, and it is also beneficial for yourself to read it later, so that you can quickly understand the program and improve efficiency.

(4) Modularize the function, that is, encapsulate the code segment that implements the same function into a class or a method, and call it when it is implemented, which can improve the readability of the code

(5) Create packages to store classes with different functions to make the system structure more modular and standardized.

(6) When writing code, you must debug while writing, set breakpoints in a timely manner, or output the value of some variables to the console, and observe and analyze the value of variables to facilitate the judgment of the problem. At the same time, If you need to catch an exception, you must print out the exception information to facilitate problem analysis.

Guess you like

Origin blog.csdn.net/bangxiecode/article/details/131385601