阅读 120

Eclipse+Java+Swing+Mysql实现电影购票系统(详细代码)

这篇文章主要介绍了Eclipse+Java+Swing+Mysql实现电影购票系统并附详细的代码详解,需要的小伙伴可以参考一下

目录
  • 一、系统介绍

    • 1.开发环境

    • 2.技术选型

    • 3.系统功能

      • 3.1.用户

      • 3.2.管理员

    • 4.数据库

      • 5.工程截图

      • 二、系统展示 

        • 1.注册系统

          • 2.登录系统

            • 3.用户-欢迎界面

              • 4.用户-影片排行榜

                • 5.用户-购票信息

                  • 6.用户-场次信息

                    • 8.用户-搜索电影

                      • 9.管理员-首页

                        • 10.管理员-对用户进行操作

                          • 11.管理员-对影院进行操作

                            • 12.管理员-对场厅进行操作

                              • 13.管理员-对场次进行操作

                                • 14.管理员-对电影进行操作

                                • 三、部分代码

                                  • AdminMainView.java

                                    • MovieInfoView.java

                                      • operCinemaView.java

                                        • operHallView.java

                                        一、系统介绍

                                        1.开发环境

                                        开发工具:Eclipse2021

                                        JDK版本:jdk1.8

                                        Mysql版本:8.0.13

                                        2.技术选型

                                        Java+Swing+Mysql

                                        3.系统功能

                                        注册系统,登录系统;

                                        3.1.用户

                                        • 1.欢迎页:修改用户姓名和密码;

                                        • 2.碟片排行榜:影片的详细信息;

                                        • 3.购票信息:已购买车票的信息;

                                        • 4.场次信息:电影场次的详细信息;

                                        • 5.充值:充值余额;

                                        • 6.搜索电影:搜索电影的详细信息;

                                        3.2.管理员

                                        • 1.对用户进行操作:用户信息的查询、删除;

                                        • 2.对影院进行操作:影院信息的查询、删除、增加;

                                        • 3.对场厅进行操作:场厅信息的查询、删除、增加;

                                        • 4.对场次进行操作:场次信息的查询、删除、增加;

                                        • 5.对电影进行操作:电影信息的查询、删除、增加;

                                        4.数据库

                                        1
                                        2
                                        3
                                        4
                                        5
                                        6
                                        7
                                        8
                                        9
                                        10
                                        11
                                        12
                                        13
                                        14
                                        15
                                        16
                                        17
                                        18
                                        19
                                        20
                                        21
                                        22
                                        23
                                        24
                                        25
                                        26
                                        27
                                        28
                                        29
                                        30
                                        31
                                        32
                                        33
                                        34
                                        35
                                        36
                                        37
                                        38
                                        39
                                        40
                                        41
                                        42
                                        43
                                        44
                                        45
                                        46
                                        47
                                        48
                                        49
                                        50
                                        51
                                        52
                                        53
                                        54
                                        55
                                        56
                                        57
                                        58
                                        59
                                        60
                                        61
                                        62
                                        63
                                        64
                                        65
                                        66
                                        67
                                        68
                                        69
                                        70
                                        71
                                        72
                                        73
                                        74
                                        75
                                        76
                                        77
                                        78
                                        79
                                        80
                                        81
                                        82
                                        83
                                        84
                                        85
                                        86
                                        87
                                        88
                                        89
                                        90
                                        91
                                        92
                                        93
                                        94
                                        95
                                        96
                                        97
                                        98
                                        99
                                        100
                                        101
                                        102
                                        103
                                        104
                                        105
                                        106
                                        107
                                        108
                                        109
                                        110
                                        111
                                        112
                                        113
                                        114
                                        115
                                        116
                                        117
                                        118
                                        119
                                        120
                                        121
                                        122
                                        123
                                        124
                                        125
                                        126
                                        127
                                        128
                                        129
                                        130
                                        131
                                        132
                                        133
                                        134
                                        135
                                        136
                                        137
                                        138
                                        139
                                        140
                                        141
                                        142
                                        143
                                        144
                                        145
                                        146
                                        147
                                        148
                                        149
                                        150
                                        151
                                        152
                                        153
                                        154
                                        155
                                        156
                                        157
                                        158
                                        159
                                        160
                                        161
                                        162
                                        163
                                        164
                                        165
                                        /*
                                         Navicat Premium Data Transfer
                                         Source Server         : MySQL
                                         Source Server Type    : MySQL
                                         Source Server Version : 80013
                                         Source Host           : 127.0.0.1:3306
                                         Source Schema         : swing_movie_house
                                         Target Server Type    : MySQL
                                         Target Server Version : 80013
                                         File Encoding         : 65001
                                         Date: 21/09/2021 12:33:55
                                        */
                                          
                                        SET NAMES utf8mb4;
                                        SET FOREIGN_KEY_CHECKS = 0;
                                          
                                        -- ----------------------------
                                        -- Table structure for cinema
                                        -- ----------------------------
                                        DROP TABLE IF EXISTS `cinema`;
                                        CREATE TABLE `cinema`  (
                                          `cinema_id` int(11) NOT NULL AUTO_INCREMENT,
                                          `cname` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL,
                                          `address` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL,
                                          PRIMARY KEY (`cinema_id`) USING BTREE
                                        ) ENGINE = InnoDB AUTO_INCREMENT = 8 CHARACTER SET = utf8 COLLATE = utf8_bin ROW_FORMAT = Dynamic;
                                          
                                        -- ----------------------------
                                        -- Records of cinema
                                        -- ----------------------------
                                        INSERT INTO `cinema` VALUES (6, '光明影院', '湖北武汉');
                                        INSERT INTO `cinema` VALUES (7, '大同影院', '湖南长沙');
                                          
                                        -- ----------------------------
                                        -- Table structure for comment
                                        -- ----------------------------
                                        DROP TABLE IF EXISTS `comment`;
                                        CREATE TABLE `comment`  (
                                          `comment_id` int(11) NOT NULL AUTO_INCREMENT,
                                          `user_id` int(11) NOT NULL,
                                          `movie_id` int(11) NOT NULL,
                                          `content` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL,
                                          `datetime` datetime(0) NULL DEFAULT NULL,
                                          PRIMARY KEY (`comment_id`) USING BTREE,
                                          INDEX `comment_ibfk_1`(`user_id`) USING BTREE,
                                          INDEX `comment_ibfk_2`(`movie_id`) USING BTREE,
                                          CONSTRAINT `comment_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `user` (`user_id`) ON DELETE CASCADE ON UPDATE RESTRICT,
                                          CONSTRAINT `comment_ibfk_2` FOREIGN KEY (`movie_id`) REFERENCES `movie` (`movie_id`) ON DELETE CASCADE ON UPDATE RESTRICT
                                        ) ENGINE = InnoDB AUTO_INCREMENT = 10 CHARACTER SET = utf8 COLLATE = utf8_bin ROW_FORMAT = Dynamic;
                                          
                                        -- ----------------------------
                                        -- Records of comment
                                        -- ----------------------------
                                          
                                        -- ----------------------------
                                        -- Table structure for hall
                                        -- ----------------------------
                                        DROP TABLE IF EXISTS `hall`;
                                        CREATE TABLE `hall`  (
                                          `hall_id` int(11) NOT NULL AUTO_INCREMENT,
                                          `hname` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL,
                                          `capacity` int(11) NULL DEFAULT NULL,
                                          `cinema_id` int(11) NOT NULL,
                                          PRIMARY KEY (`hall_id`) USING BTREE,
                                          INDEX `hall_ibfk_1`(`cinema_id`) USING BTREE,
                                          CONSTRAINT `hall_ibfk_1` FOREIGN KEY (`cinema_id`) REFERENCES `cinema` (`cinema_id`) ON DELETE CASCADE ON UPDATE CASCADE
                                        ) ENGINE = InnoDB AUTO_INCREMENT = 12 CHARACTER SET = utf8 COLLATE = utf8_bin ROW_FORMAT = Dynamic;
                                          
                                        -- ----------------------------
                                        -- Records of hall
                                        -- ----------------------------
                                        INSERT INTO `hall` VALUES (12, '1厅', 50, 6);
                                          
                                        -- ----------------------------
                                        -- Table structure for movie
                                        -- ----------------------------
                                        DROP TABLE IF EXISTS `movie`;
                                        CREATE TABLE `movie`  (
                                          `movie_id` int(11) NOT NULL AUTO_INCREMENT,
                                          `mname` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL,
                                          `type` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL COMMENT '电影类型',
                                          `detail` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL,
                                          `duration` int(11) NULL DEFAULT NULL,
                                          `img` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL COMMENT '保存图片名称',
                                          PRIMARY KEY (`movie_id`) USING BTREE
                                        ) ENGINE = InnoDB AUTO_INCREMENT = 14 CHARACTER SET = utf8 COLLATE = utf8_bin ROW_FORMAT = Dynamic;
                                          
                                        -- ----------------------------
                                        -- Records of movie
                                        -- ----------------------------
                                        INSERT INTO `movie` VALUES (12, '八佰', '抗战', '八佰', 120, NULL);
                                        INSERT INTO `movie` VALUES (13, '春秋', '历史', '春秋', 150, NULL);
                                        INSERT INTO `movie` VALUES (15, '1', '1', '1', 1, NULL);
                                          
                                        -- ----------------------------
                                        -- Table structure for session
                                        -- ----------------------------
                                        DROP TABLE IF EXISTS `session`;
                                        CREATE TABLE `session`  (
                                          `session_id` int(11) NOT NULL AUTO_INCREMENT,
                                          `hall_id` int(11) NOT NULL,
                                          `cinema_id` int(11) NOT NULL,
                                          `movie_id` int(11) NOT NULL,
                                          `starttime` varchar(11) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL,
                                          `price` double NULL DEFAULT NULL,
                                          `remain` int(11) NULL DEFAULT NULL,
                                          PRIMARY KEY (`session_id`) USING BTREE,
                                          INDEX `hall_id`(`hall_id`) USING BTREE,
                                          INDEX `cinema_id`(`cinema_id`) USING BTREE,
                                          INDEX `movie_id`(`movie_id`) USING BTREE,
                                          CONSTRAINT `session_ibfk_1` FOREIGN KEY (`hall_id`) REFERENCES `hall` (`hall_id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
                                          CONSTRAINT `session_ibfk_2` FOREIGN KEY (`cinema_id`) REFERENCES `cinema` (`cinema_id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
                                          CONSTRAINT `session_ibfk_3` FOREIGN KEY (`movie_id`) REFERENCES `movie` (`movie_id`) ON DELETE RESTRICT ON UPDATE RESTRICT
                                        ) ENGINE = InnoDB AUTO_INCREMENT = 14 CHARACTER SET = utf8 COLLATE = utf8_bin ROW_FORMAT = Dynamic;
                                          
                                        -- ----------------------------
                                        -- Records of session
                                        -- ----------------------------
                                        INSERT INTO `session` VALUES (14, 12, 6, 12, '09:00:00', 50, 47);
                                          
                                        -- ----------------------------
                                        -- Table structure for ticket
                                        -- ----------------------------
                                        DROP TABLE IF EXISTS `ticket`;
                                        CREATE TABLE `ticket`  (
                                          `ticket_id` int(11) NOT NULL AUTO_INCREMENT,
                                          `user_id` int(11) NOT NULL,
                                          `movie_id` int(11) NOT NULL,
                                          `session_id` int(11) NOT NULL,
                                          `seat` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL,
                                          PRIMARY KEY (`ticket_id`) USING BTREE,
                                          INDEX `ticket_ibfk_1`(`user_id`) USING BTREE,
                                          INDEX `ticket_ibfk_2`(`movie_id`) USING BTREE,
                                          INDEX `ticket_ibfk_3`(`session_id`) USING BTREE,
                                          CONSTRAINT `ticket_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `user` (`user_id`) ON DELETE CASCADE ON UPDATE CASCADE,
                                          CONSTRAINT `ticket_ibfk_2` FOREIGN KEY (`movie_id`) REFERENCES `movie` (`movie_id`) ON DELETE CASCADE ON UPDATE CASCADE,
                                          CONSTRAINT `ticket_ibfk_3` FOREIGN KEY (`session_id`) REFERENCES `session` (`session_id`) ON DELETE CASCADE ON UPDATE CASCADE
                                        ) ENGINE = InnoDB AUTO_INCREMENT = 64 CHARACTER SET = utf8 COLLATE = utf8_bin ROW_FORMAT = Dynamic;
                                          
                                        -- ----------------------------
                                        -- Records of ticket
                                        -- ----------------------------
                                        INSERT INTO `ticket` VALUES (64, 1, 12, 14, '3');
                                          
                                        -- ----------------------------
                                        -- Table structure for user
                                        -- ----------------------------
                                        DROP TABLE IF EXISTS `user`;
                                        CREATE TABLE `user`  (
                                          `user_id` int(11) NOT NULL AUTO_INCREMENT,
                                          `uname` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL,
                                          `passwd` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL,
                                          `type` int(11) NULL DEFAULT 0 COMMENT '0代表普通用户,1代表管理员',
                                          `balance` double NULL DEFAULT NULL,
                                          `level` int(11) NULL DEFAULT NULL,
                                          PRIMARY KEY (`user_id`) USING BTREE
                                        ) ENGINE = InnoDB AUTO_INCREMENT = 11 CHARACTER SET = utf8 COLLATE = utf8_bin ROW_FORMAT = Dynamic;
                                          
                                        -- ----------------------------
                                        -- Records of user
                                        -- ----------------------------
                                        INSERT INTO `user` VALUES (1, 'user', 'user', 0, 161, 1);
                                        INSERT INTO `user` VALUES (2, 'admin', 'admin', 1, 1, 1);
                                          
                                        SET FOREIGN_KEY_CHECKS = 1;

                                        5.工程截图

                                        二、系统展示 

                                        1.注册系统

                                        2.登录系统

                                        3.用户-欢迎界面

                                        4.用户-影片排行榜

                                        5.用户-购票信息


                                        6.用户-场次信息

                                        7.用户-充值余额

                                        8.用户-搜索电影

                                        9.管理员-首页

                                        10.管理员-对用户进行操作

                                        11.管理员-对影院进行操作

                                        12.管理员-对场厅进行操作

                                        13.管理员-对场次进行操作

                                        14.管理员-对电影进行操作

                                        三、部分代码

                                        AdminMainView.java

                                        1
                                        2
                                        3
                                        4
                                        5
                                        6
                                        7
                                        8
                                        9
                                        10
                                        11
                                        12
                                        13
                                        14
                                        15
                                        16
                                        17
                                        18
                                        19
                                        20
                                        21
                                        22
                                        23
                                        24
                                        25
                                        26
                                        27
                                        28
                                        29
                                        30
                                        31
                                        32
                                        33
                                        34
                                        35
                                        36
                                        37
                                        38
                                        39
                                        40
                                        41
                                        42
                                        43
                                        44
                                        45
                                        46
                                        47
                                        48
                                        49
                                        50
                                        51
                                        52
                                        53
                                        54
                                        55
                                        56
                                        57
                                        58
                                        59
                                        60
                                        61
                                        62
                                        63
                                        64
                                        65
                                        66
                                        67
                                        68
                                        69
                                        70
                                        71
                                        72
                                        73
                                        74
                                        75
                                        76
                                        77
                                        78
                                        79
                                        80
                                        81
                                        82
                                        83
                                        84
                                        85
                                        86
                                        87
                                        88
                                        89
                                        90
                                        91
                                        92
                                        93
                                        94
                                        95
                                        96
                                        97
                                        98
                                        99
                                        100
                                        101
                                        102
                                        103
                                        104
                                        105
                                        106
                                        107
                                        108
                                        109
                                        110
                                        111
                                        112
                                        113
                                        114
                                        115
                                        116
                                        117
                                        118
                                        119
                                        120
                                        121
                                        122
                                        123
                                        124
                                        125
                                        126
                                        127
                                        128
                                        129
                                        130
                                        131
                                        132
                                        133
                                        134
                                        135
                                        136
                                        137
                                        138
                                        139
                                        140
                                        141
                                        142
                                        143
                                        144
                                        145
                                        146
                                        147
                                        148
                                        149
                                        150
                                        151
                                        152
                                        153
                                        154
                                        155
                                        156
                                        157
                                        158
                                        159
                                        160
                                        161
                                        162
                                        163
                                        164
                                        165
                                        166
                                        167
                                        168
                                        169
                                        170
                                        171
                                        172
                                        173
                                        174
                                        175
                                        176
                                        177
                                        178
                                        179
                                        180
                                        181
                                        182
                                        package view;
                                          
                                        import java.awt.BorderLayout;
                                        import java.awt.Color;
                                        import java.awt.EventQueue;
                                        import java.awt.Font;
                                        import java.awt.GridLayout;
                                        import java.awt.event.ActionEvent;
                                        import java.awt.event.ActionListener;
                                          
                                        import javax.swing.BorderFactory;
                                        import javax.swing.ImageIcon;
                                        import javax.swing.JButton;
                                        import javax.swing.JDesktopPane;
                                        import javax.swing.JFrame;