catalogue
5. User - ticket purchase information
10. Administrator - operate on users
11. Administrator - operate the theater
12. Administrator - operate the hall
13. Administrator - operate the session
14. Administrator - operate the movie
1. Other system implementation
1. Java Web system series implementation
2.JavaSwing system series implementation
JavaSwing system implementation series
Realizing landlords fighting game with Java+Swing
Implementation of library management system with Java+Swing
Implementation of hospital management system with Java+Swing
Implementation of examination management system with Java+Swing
Implementation of warehouse management System-1 with Java+Swing
Implementation of warehouse management System-2 with Java+Swing
Implementation of self-service ATM system with Java+Swing
Implementation of address book management system with Java+Swing
Implementation of parking lot management system with Java+Swing
Implementation of student information management system with Java+Swing
Implementation of student dormitory management system with Java+Swing
Implementation of student course selection management system with Java+Swing
Implementation of student achievement management system with Java+Swing
Implementation of school textbook management system with Java+Swing
Implementation of school educational administration management system with Java+Swing
Implementation of enterprise personnel management system with Java+Swing
Implementation of electronic album management system with Java+Swing
Java+Swing to realize supermarket management system TXT to store data
Java+Swing to realize self-service ATM system - TXT to store data
Java+Swing to realize pet store management system TXT to store data
1, System introduction
1. Development environment
Development tool: Eclipse 2021
JDK version: jdk1.8
Mysql version: 8.0.13
2. Technical selection
Java+Swing+Mysql
3. System functions
Registration system, login system;
1. Users
1. Welcome page: modify user name and password;
2. Disc ranking: detailed information of the film;
3. Ticket purchase information: information of purchased tickets;
4. Scene information: detailed information of film scenes;
5. Recharge: recharge balance;
6. Search for movies: search for movie details;
2. Administrator
1. Operate on users: query and delete user information;
2. Operate the cinema: query, delete and add cinema information;
3. Operate the hall: query, delete and add the hall information;
4. Operation of the session: query, delete and add the session information;
5. Operate the movie: query, delete and add movie information;
4. Database
/* 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, 'Guangming cinema', 'Wuhan, Hubei'); INSERT INTO `cinema` VALUES (7, 'Datong cinema', 'Changsha, Hunan'); -- ---------------------------- -- 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 office', 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 'Film type', `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 'Save picture name', 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, 'eight hundred', 'war of resistance against aggression', 'eight hundred', 120, NULL); INSERT INTO `movie` VALUES (13, 'spring and autumn', 'history', 'spring and autumn', 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 On behalf of ordinary users, 1 on behalf of administrators', `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. Project screenshot
2, System display
1. Registration system
2. Log in to the system
3. User welcome interface
4. Users - Movie ranking
5. User - ticket purchase information
6. User session information
7. User - recharge balance
8. User - Search movies
9. Administrator - home page
10. Administrator - operate on users
11. Administrator - operate the theater
12. Administrator - operate the hall
13. Administrator - operate the session
14. Administrator - operate the movie
3, Partial code
AdminMainView.java
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; import javax.swing.JLabel; import javax.swing.JPanel; import entity.User; public class AdminMainView extends JFrame { private JPanel main_panel = null; private JPanel fun_panel = null; private JDesktopPane fundesk = null; private JButton oper_User = null; private JButton oper_Cinema = null; private JButton oper_Hall = null; private JButton oper_Session = null; private JButton oper_Movie = null; private JButton back = null; private JLabel lb_welcome = null; private JLabel lb_image = null; private User admin = null; public AdminMainView() { init(); RegisterListener(); } public AdminMainView(User admin) { this.admin = admin; init(); RegisterListener(); } private void init() { main_panel = new JPanel(new BorderLayout()); fun_panel = new JPanel(new GridLayout(8, 1, 0, 18)); oper_User = new JButton("Operate on users"); oper_Cinema = new JButton("Operate the theater"); oper_Hall = new JButton("Operate the hall"); oper_Session = new JButton("Operate the field"); oper_Movie = new JButton("Operate on movies"); back = new JButton("return"); fun_panel.add(new JLabel()); fun_panel.add(oper_User); fun_panel.add(oper_Cinema); fun_panel.add(oper_Hall); fun_panel.add(oper_Session); fun_panel.add(oper_Movie); fun_panel.add(back); fun_panel.add(new JLabel()); // Set panel appearance fun_panel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createRaisedBevelBorder(), "Functional area")); lb_welcome = new JLabel("welcome " + admin.getUname() + " Enter the administrator function interface"); lb_welcome.setFont(new Font("Regular script", Font.BOLD, 34)); lb_welcome.setForeground(Color.BLUE); fundesk = new JDesktopPane(); ImageIcon img = new ImageIcon(ClassLoader.getSystemResource("image/beijjing3.jpg")); lb_image = new JLabel(img); lb_image.setBounds(10, 10, img.getIconWidth(), img.getIconHeight()); fundesk.add(lb_image, new Integer(Integer.MIN_VALUE)); main_panel.add(lb_welcome, BorderLayout.NORTH); main_panel.add(fun_panel, BorderLayout.EAST); main_panel.add(fundesk, BorderLayout.CENTER); // In order not to block the thread, call the thread // Put in the queue EventQueue.invokeLater(new Runnable() { public void run() { new Thread(new thread()).start(); } }); this.setTitle("Administrator function interface"); this.getContentPane().add(main_panel); this.setSize(880, 600); this.setResizable(false); this.setVisible(true); this.setLocationRelativeTo(null); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } // Start the thread to make the welcome tag move // This is single threaded private class thread implements Runnable { @Override public void run() { while (true) {// The loop keeps it moving for (int i = 900; i > -700; i--) { // for(int i=-100;i<900;i++){ try { Thread.sleep(10);// Let the thread sleep for 100 milliseconds } catch (InterruptedException e) { e.printStackTrace(); } lb_welcome.setLocation(i, 5); } } } } private void RegisterListener() { oper_User.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { operUserView ouv = new operUserView(); fundesk.add(ouv); ouv.toFront(); } }); oper_Cinema.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { operCinemaView ocv = new operCinemaView(); fundesk.add(ocv); ocv.toFront(); } }); oper_Hall.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { operHallView ohv = new operHallView(); fundesk.add(ohv); ohv.toFront(); } }); oper_Session.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { operSessionView osv = new operSessionView(); fundesk.add(osv); osv.toFront(); } }); oper_Movie.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { operMovieView omv = new operMovieView(); fundesk.add(omv); omv.toFront(); } }); back.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { new Login(); AdminMainView.this.dispose(); } }); } }
MovieInfoView.java
package view; import java.awt.Color; import java.awt.Font; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.text.SimpleDateFormat; import java.util.List; import javax.swing.GroupLayout; import javax.swing.GroupLayout.Alignment; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.JTextField; import javax.swing.LayoutStyle.ComponentPlacement; import javax.swing.border.EmptyBorder; import javax.swing.table.DefaultTableModel; import entity.Comment; import entity.Movie; import entity.User; import service.CommentService; import service.MovieService; import service.UserService; import serviceimpl.CommentServiceImpl; import serviceimpl.MovieServiceImpl; import serviceimpl.UserServiceImpl; public class MovieInfoView extends JFrame { private JPanel contentPane; private JTable table; JScrollPane scrollPane = null; Movie movie = null; User user = null; MovieService ms = null; CommentService cs = null; UserService us = null; public MovieInfoView(Movie movie, User user) { this.movie = movie; this.user = user; ms = new MovieServiceImpl(); cs = new CommentServiceImpl(); us = new UserServiceImpl(); setTitle("User ballot interface"); setBounds(260, 130, 620, 600); this.setLocationRelativeTo(null); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); JLabel lblNewLabel = new JLabel("New label"); lblNewLabel.setIcon(new ImageIcon("image/" + movie.getImg())); JLabel label = new JLabel("It's showing···"); JLabel lblNewLabel_1 = new JLabel("Film name:"); lblNewLabel_1.setFont(new Font("Regular script", Font.BOLD, 18)); JLabel label_1 = new JLabel("Type:"); JLabel label_2 = new JLabel("duration:"); JLabel label_3 = new JLabel("Movie details:"); JLabel label_4 = new JLabel(movie.getMname()); label_4.setFont(new Font("Regular script", Font.BOLD, 18)); JButton btnNewButton = new JButton("purchase"); btnNewButton.setForeground(Color.BLUE); btnNewButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { new UserUi(user, 3); movie.getMovie_id(); List<Movie> movieByName = ms.getMovieByName(movie.getMname()); for (Movie movie2 : movieByName) { System.out.println(movie2); } MovieInfoView.this.dispose(); } }); JButton button = new JButton("cancel"); button.setForeground(Color.RED); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { MovieInfoView.this.dispose(); } }); scrollPane = new JScrollPane(); scrollPane.setEnabled(false); scrollPane.setVisible(false); JButton button_1 = new JButton("View comments"); button_1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scrollPane.setVisible(true); showComment(); table.repaint(); } }); button_1.setForeground(Color.MAGENTA); JLabel lblNewLabel_2 = new JLabel("Welcome to the movie details screen"); lblNewLabel_2.setFont(new Font("NSimSun ", Font.BOLD, 20)); lblNewLabel_2.setForeground(Color.BLACK); JLabel label_5 = new JLabel(movie.getType()); JLabel label_6 = new JLabel(movie.getDuration() + "minute"); JLabel label_7 = new JLabel(movie.getDetail()); GroupLayout gl_contentPane = new GroupLayout(contentPane); gl_contentPane.setHorizontalGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING).addGroup(gl_contentPane .createSequentialGroup() .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING) .addGroup(gl_contentPane.createSequentialGroup().addGap(218) .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING) .addGroup(gl_contentPane.createSequentialGroup().addComponent(label_3) .addPreferredGap(ComponentPlacement.RELATED).addComponent(label_7, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE)) .addGroup(gl_contentPane.createSequentialGroup().addComponent(lblNewLabel_1) .addPreferredGap(ComponentPlacement.RELATED) .addComponent(label_4, GroupLayout.PREFERRED_SIZE, 137, GroupLayout.PREFERRED_SIZE)) .addGroup(gl_contentPane.createSequentialGroup() .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING) .addComponent(label_2) .addGroup(gl_contentPane.createSequentialGroup() .addPreferredGap(ComponentPlacement.RELATED) .addComponent(label_1))) .addGap(4) .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING) .addComponent(label_6, GroupLayout.PREFERRED_SIZE, 55, GroupLayout.PREFERRED_SIZE) .addComponent(label_5, GroupLayout.PREFERRED_SIZE, 82, GroupLayout.PREFERRED_SIZE))) .addGroup(gl_contentPane.createSequentialGroup().addComponent(btnNewButton) .addGap(18) .addComponent(button, GroupLayout.PREFERRED_SIZE, 71, GroupLayout.PREFERRED_SIZE) .addGap(18).addComponent(button_1)))) .addGroup(gl_contentPane.createSequentialGroup().addGap(36).addComponent(label)) .addGroup(gl_contentPane.createSequentialGroup().addGap(170).addComponent(lblNewLabel_2)) .addComponent(lblNewLabel, GroupLayout.PREFERRED_SIZE, 200, GroupLayout.PREFERRED_SIZE) .addGroup(gl_contentPane.createSequentialGroup().addGap(84).addComponent(scrollPane, GroupLayout.PREFERRED_SIZE, 464, GroupLayout.PREFERRED_SIZE))) .addContainerGap(46, Short.MAX_VALUE))); gl_contentPane.setVerticalGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING) .addGroup(gl_contentPane.createSequentialGroup() .addGroup(gl_contentPane .createParallelGroup(Alignment.LEADING) .addGroup(gl_contentPane.createSequentialGroup().addGap(46).addComponent(label) .addPreferredGap(ComponentPlacement.UNRELATED) .addComponent(lblNewLabel, GroupLayout.DEFAULT_SIZE, 277, Short.MAX_VALUE)) .addGroup(gl_contentPane.createSequentialGroup().addContainerGap() .addComponent(lblNewLabel_2).addGap(58) .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING) .addComponent(lblNewLabel_1).addComponent(label_4, GroupLayout.PREFERRED_SIZE, 21, GroupLayout.PREFERRED_SIZE)) .addPreferredGap(ComponentPlacement.RELATED, 53, Short.MAX_VALUE) .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE) .addComponent(label_1).addComponent(label_5)) .addGap(18) .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE) .addComponent(label_2).addComponent(label_6)) .addGap(18) .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE) .addComponent(label_3).addComponent(label_7)) .addGap(125) .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE) .addComponent(btnNewButton).addComponent(button) .addComponent(button_1)))) .addGap(28) .addComponent(scrollPane, GroupLayout.PREFERRED_SIZE, 139, GroupLayout.PREFERRED_SIZE))); showComment(); scrollPane.setViewportView(table); contentPane.setLayout(gl_contentPane); this.setVisible(true); } public void showComment() { List<Comment> commlist = cs.getAllCommentByMovieId(movie.getMovie_id()); int recordrow = 0; if (commlist != null) { recordrow = commlist.size(); } String[][] rinfo = new String[recordrow][3]; SimpleDateFormat sdf = new SimpleDateFormat("yy-MM-dd hh:mm"); for (int i = 0; i < recordrow; i++) { for (int j = 0; j < 3; j++) { rinfo[i][j] = new String(); rinfo[i][0] = us.queryUserById(commlist.get(i).getUser_id()).getUname(); rinfo[i][1] = commlist.get(i).getContent(); rinfo[i][2] = sdf.format(commlist.get(i).getDatetime()); } } String[] tbheadnames = { "user name", "Comment content", "Comment time" }; table = new JTable(rinfo, tbheadnames); table.setBorder(null); table.setRowHeight(20); table.setEnabled(false); table.getColumnModel().getColumn(0).setPreferredWidth(30); table.getTableHeader().setFont(new Font("Regular script", 1, 20)); table.getTableHeader().setBackground(Color.CYAN); table.getTableHeader().setReorderingAllowed(false); // Non exchangeable order table.getTableHeader().setResizingAllowed(true); // Non pull table scrollPane.add(table); scrollPane.setBorder(null); table.repaint(); } }
operCinemaView.java
package view; import java.awt.BorderLayout; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.util.ArrayList; import java.util.List; import javax.swing.BorderFactory; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JInternalFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JTable; import javax.swing.JTextField; import javax.swing.event.TableModelListener; import javax.swing.table.TableModel; import entity.Cinema; import service.CinemaService; import serviceimpl.CinemaServiceImpl; public class operCinemaView extends JInternalFrame { private JPanel pl_main = null; private JPanel pl_button = null; private JPanel pl_text = null; private JTable table = null; private JButton btn_add = null; private JButton btn_query = null; private JButton btn_del = null; private JComboBox<String> cb_query = null; private JButton btn_back = null; private JLabel lb_name = null; private JLabel lb_address = null; private JTextField tf_qname = null;// Name entered when querying private JTextField tf_name = null;// Add the name entered private JTextField tf_address = null; private CinemaService cinemabiz = null; private List<Cinema> cinemaList = null; private CinemaInfoTableModel infoTableModel = null; // private List<Hall> hallList = null; // private List<Session> sessionList = null; // private HallBiz hallbiz = null; // private SessionBiz sessionbiz = null; public operCinemaView() { cinemabiz = new CinemaServiceImpl(); // hallbiz = new HallBizImpl(); // sessionbiz = new SessionBizImpl(); init(); RegisterListener(); } private void init() { pl_main = new JPanel(new BorderLayout()); pl_button = new JPanel(new GridLayout(8, 1, 0, 40)); pl_text = new JPanel(new GridLayout(1, 4)); cinemaList = new ArrayList<Cinema>(); table = new JTable(); refreshTable(cinemaList); cb_query = new JComboBox<String>(new String[] { "Query all theaters", "Find cinema by name" }); tf_qname = new JTextField(8); tf_qname.setEnabled(false); btn_query = new JButton("query"); btn_add = new JButton("Add cinema"); btn_del = new JButton("Delete Theater"); btn_del.setEnabled(false); btn_back = new JButton("Exit window"); lb_name = new JLabel("Cinema name: "); tf_name = new JTextField(8); lb_address = new JLabel("Cinema address: "); tf_address = new JTextField(12); pl_main.add(table.getTableHeader(), BorderLayout.PAGE_START); pl_main.add(table); pl_main.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(null, null), "Query information")); pl_button.add(new JLabel()); pl_button.add(cb_query); pl_button.add(tf_qname); pl_button.add(btn_query); pl_button.add(btn_add); pl_button.add(btn_del); pl_button.add(new JLabel()); pl_button.add(btn_back); pl_text.add(lb_name); pl_text.add(tf_name); pl_text.add(lb_address); pl_text.add(tf_address); this.add(pl_main, BorderLayout.CENTER); this.add(pl_button, BorderLayout.EAST); this.add(pl_text, BorderLayout.NORTH); this.setVisible(true); this.setTitle("Theater operation interface"); this.setSize(700, 530); this.setIconifiable(true); this.setClosable(true); this.setDefaultCloseOperation(DISPOSE_ON_CLOSE); } private void RegisterListener() { table.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (table.getSelectedRow() != -1) { btn_del.setEnabled(true); } int row = table.getSelectedRow(); String name = table.getValueAt(row, 1).toString(); String address = table.getValueAt(row, 2).toString(); tf_name.setText(name); tf_address.setText(address); } }); cb_query.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (cb_query.getSelectedIndex() + 1 == 2) { tf_qname.setEnabled(true); } else { tf_qname.setEnabled(false); } } }); btn_query.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (cb_query.getSelectedIndex() + 1 == 1) { cinemaList = cinemabiz.queryAllCinema(); refreshTable(cinemaList); } else { String name = tf_qname.getText().trim(); cinemaList = cinemabiz.queryCinemaByName(name); refreshTable(cinemaList); } } }); btn_add.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String name = tf_name.getText().trim(); String address = tf_address.getText().trim(); if (name.equals("")) { JOptionPane.showMessageDialog(operCinemaView.this, "Cinema name cannot be empty!"); } else if (address.equals("")) { JOptionPane.showMessageDialog(operCinemaView.this, "Cinema address cannot be empty!"); } else { int flag = JOptionPane.showConfirmDialog(operCinemaView.this, "Confirm whether to add?", "Confirmation information", JOptionPane.YES_NO_OPTION); if (flag == JOptionPane.YES_OPTION) { Cinema cinema = new Cinema(name, address); boolean res = cinemabiz.addCinema(cinema); if (res) { cinemaList = cinemabiz.queryAllCinema(); refreshTable(cinemaList); JOptionPane.showMessageDialog(operCinemaView.this, "Added successfully!"); } else { JOptionPane.showMessageDialog(operCinemaView.this, "Add failed!"); } } } } }); btn_del.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int row = table.getSelectedRow(); int id = (Integer) table.getValueAt(row, 0); int flag = JOptionPane.showConfirmDialog(operCinemaView.this, "Are you sure you want to delete this theater?", "Confirmation information", JOptionPane.YES_NO_OPTION); if (flag == JOptionPane.YES_OPTION) { boolean res = cinemabiz.deleteCinemaById(id); /* * if(res) { //Update data hallList = hallbiz.queryAllHall(); int hid = 0; for(int i = * 0; i < hallList.size(); i++) { if(id == hallList.get(i).getCid()) { hid = * hallList.get(i).getId(); hallbiz.delHall(hid); } } sessionList = * sessionbiz.queryAllSession(); for(int i = 0; i < sessionList.size(); i++) { * if(hid == sessionList.get(i).getHid()) { * sessionbiz.delSession(sessionList.get(i).getId()); } } } */ cinemaList = cinemabiz.queryAllCinema(); refreshTable(cinemaList); } } }); btn_back.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { operCinemaView.this.dispose(); } }); } public class CinemaInfoTableModel implements TableModel { public List<Cinema> cinemaList = null; public CinemaInfoTableModel(List<Cinema> cinemaList) { this.cinemaList = cinemaList; } @Override public int getRowCount() { return cinemaList.size(); } @Override public int getColumnCount() { return 3; } @Override public String getColumnName(int columnIndex) { if (columnIndex == 0) { return "cinema ID"; } else if (columnIndex == 1) { return "Cinema name"; } else if (columnIndex == 2) { return "Cinema address"; } else { return "error"; } } @Override public Class<?> getColumnClass(int columnIndex) { return String.class; } @Override public boolean isCellEditable(int rowIndex, int columnIndex) { return false; } @Override public Object getValueAt(int rowIndex, int columnIndex) { Cinema cinema = cinemaList.get(rowIndex); if (columnIndex == 0) { return cinema.getCinema_id(); } else if (columnIndex == 1) { return cinema.getCname(); } else if (columnIndex == 2) { return cinema.getAddress(); } else { return "error"; } } @Override public void setValueAt(Object aValue, int rowIndex, int columnIndex) { // TODO Auto-generated method stub } @Override public void addTableModelListener(TableModelListener l) { // TODO Auto-generated method stub } @Override public void removeTableModelListener(TableModelListener l) { // TODO Auto-generated method stub } } private void refreshTable(List<Cinema> cinemaList) { infoTableModel = new CinemaInfoTableModel(cinemaList); table.setModel(infoTableModel); table.setRowHeight(20); } }
operHallView.java
package view; import java.awt.BorderLayout; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.util.ArrayList; import java.util.List; import javax.swing.BorderFactory; import javax.swing.JButton; import javax.swing.JInternalFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JTable; import javax.swing.JTextField; import javax.swing.event.TableModelListener; import javax.swing.table.TableModel; import entity.Cinema; import entity.Hall; import entity.Session; import service.CinemaService; import service.HallService; import serviceimpl.CinemaServiceImpl; import serviceimpl.HallServiceImpl; import serviceimpl.SessionServiceImpl; import util.Check; public class operHallView extends JInternalFrame { private JPanel pl_main = null; private JPanel pl_button = null; private JPanel pl_text = null; private JTable table = null; private JButton btn_add = null; private JButton btn_del = null; private JButton btn_query = null; private JButton btn_back = null; private JLabel lb_name = null; private JLabel lb_cid = null; private JLabel lb_capacity = null; private JTextField tf_name = null;// Add the name entered private JTextField tf_cid = null;// Theater id entered when adding private JTextField tf_capacity = null;// Add the name entered private HallService hallbiz = null; private CinemaService cinemabiz = null; private SessionServiceImpl sessionbiz = null; private List<Hall> hallList = null; private HallInfoTableModel infoTableModel = null; public operHallView() { hallbiz = new HallServiceImpl(); cinemabiz = new CinemaServiceImpl();// Query all theaters to match cid and display the cinema name sessionbiz = new SessionServiceImpl(); init(); RegisterListener(); } private void init() { pl_main = new JPanel(new BorderLayout()); pl_button = new JPanel(new GridLayout(6, 1, 0, 40)); pl_text = new JPanel(new GridLayout(1, 6)); hallList = new ArrayList<Hall>(); table = new JTable(); // Bind JTabel to render data refreshTable(hallList); btn_query = new JButton("Query all halls"); btn_add = new JButton("Add Hall"); btn_del = new JButton("Delete Hall"); btn_del.setEnabled(false); btn_back = new JButton("Exit window"); tf_name = new JTextField(8); tf_cid = new JTextField(8); tf_capacity = new JTextField(8); lb_name = new JLabel("Hall name"); lb_cid = new JLabel("Cinema id"); lb_capacity = new JLabel("Hall capacity"); pl_main.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(null, null), "Query information")); pl_main.add(table.getTableHeader(), BorderLayout.PAGE_START); pl_main.add(table); this.add(pl_main, BorderLayout.CENTER); pl_button.add(new JLabel()); pl_button.add(btn_query); pl_button.add(btn_add); pl_button.add(btn_del); pl_button.add(new JLabel()); pl_button.add(btn_back); this.add(pl_button, BorderLayout.EAST); pl_text.add(lb_name); pl_text.add(tf_name); pl_text.add(lb_cid); pl_text.add(tf_cid); pl_text.add(lb_capacity); pl_text.add(tf_capacity); this.add(pl_text, BorderLayout.NORTH); this.setVisible(true); this.setTitle("Hall operation interface"); this.setSize(700, 530); this.setIconifiable(true); this.setClosable(true); this.setDefaultCloseOperation(DISPOSE_ON_CLOSE); } private void RegisterListener() { table.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { // Add a selected row and the delete button becomes available if (table.getSelectedRow() != -1) { btn_del.setEnabled(true); } int row = table.getSelectedRow(); String name = table.getValueAt(row, 1).toString(); String cid = table.getValueAt(row, 2).toString(); String capacity = table.getValueAt(row, 3).toString(); tf_name.setText(name); tf_cid.setText(cid); tf_capacity.setText(capacity); } }); btn_add.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String name = tf_name.getText().trim(); String cid = tf_cid.getText().trim(); String capacity = tf_capacity.getText().trim(); if (name.equals("")) { JOptionPane.showMessageDialog(operHallView.this, "Hall name cannot be empty!"); } else if (cid.equals("")) { JOptionPane.showMessageDialog(operHallView.this, "Cinema id Cannot be empty!"); } else if (capacity.equals("")) { JOptionPane.showMessageDialog(operHallView.this, "Hall capacity cannot be empty!"); } else if (!Check.isNumber(cid)) { JOptionPane.showMessageDialog(operHallView.this, "Cinema id Can only be numbers!"); } else if (!Check.isNumber(capacity)) { JOptionPane.showMessageDialog(operHallView.this, "Hall capacity can only be numeric!"); } else { int flag = JOptionPane.showConfirmDialog(operHallView.this, "Add this hall?", "Confirmation information", JOptionPane.YES_NO_OPTION); if (flag == JOptionPane.YES_OPTION) { Hall hall = new Hall(name, new Integer(capacity), new Integer(cid)); boolean res = hallbiz.addHall(hall); hallList = hallbiz.queryAllHall(); refreshTable(hallList); if (res) { JOptionPane.showMessageDialog(operHallView.this, "Added successfully!"); } else { JOptionPane.showMessageDialog(operHallView.this, "Add failed!"); } } } } }); btn_query.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // Clear data to prevent accumulation if (hallList != null) { hallList.clear(); } hallList = hallbiz.queryAllHall(); refreshTable(hallList); } }); btn_del.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int row = table.getSelectedRow(); int id = (Integer) table.getValueAt(row, 0); int flag = JOptionPane.showConfirmDialog(operHallView.this, "Are you sure you want to delete this hall?", "Confirmation information", JOptionPane.YES_NO_OPTION); if (flag == JOptionPane.YES_OPTION) { boolean res = hallbiz.delHall(id); if (res) { JOptionPane.showMessageDialog(operHallView.this, "Delete succeeded!"); // Update data List<Session> sessionList = new ArrayList<Session>(); sessionList = sessionbiz.queryAllSession(); // After deleting a certain venue, the corresponding venue will also be deleted int sid = 0; for (int i = 0; i < sessionList.size(); i++) { if (id == sessionList.get(i).getHall_id()) { sid = sessionList.get(i).getSession_id(); sessionbiz.delSession(sid); } } hallList = hallbiz.queryAllHall(); refreshTable(hallList);// Update display data } else { JOptionPane.showMessageDialog(operHallView.this, "Deletion failed!"); } } } }); btn_back.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { operHallView.this.dispose(); } }); } private class HallInfoTableModel implements TableModel { public List<Hall> hallList = null; public HallInfoTableModel(List<Hall> hallList) { this.hallList = hallList; } // Number of rows displayed by JTable @Override public int getRowCount() { return hallList.size(); } // Number of columns displayed by JTable @Override public int getColumnCount() { return 4; } // JTable displays the names of the rows @Override public String getColumnName(int columnIndex) { if (columnIndex == 0) { return "Field hall ID"; } else if (columnIndex == 1) { return "Hall name"; } else if (columnIndex == 2) { return "Cinema"; } else if (columnIndex == 3) { return "Hall capacity"; } else { return "error"; } } // Data type of JTable column @Override public Class<?> getColumnClass(int columnIndex) { return String.class; } // Is the cell editable @Override public boolean isCellEditable(int rowIndex, int columnIndex) { return false; } // Data displayed in each row of cells @Override public Object getValueAt(int rowIndex, int columnIndex) { Hall hall = hallList.get(rowIndex); Cinema cinema = null; if (columnIndex == 0) { return hall.getHall_id(); } else if (columnIndex == 1) { return hall.getHname(); } else if (columnIndex == 2) { List<Cinema> cinemaList = cinemabiz.queryAllCinema(); for (int i = 0; i < cinemaList.size(); i++) { if (hall.getCinema_id() == cinemaList.get(i).getCinema_id()) { cinema = cinemaList.get(i); break; } } return cinema.getCname(); // return hall.getCid(); } else if (columnIndex == 3) { return hall.getCapacity(); } else { return "error"; } } @Override public void setValueAt(Object aValue, int rowIndex, int columnIndex) { // TODO Auto-generated method stub } @Override public void addTableModelListener(TableModelListener l) { // TODO Auto-generated method stub } @Override public void removeTableModelListener(TableModelListener l) { // TODO Auto-generated method stub } } private void refreshTable(List<Hall> hallList) { infoTableModel = new HallInfoTableModel(hallList); table.setModel(infoTableModel); table.setRowHeight(20); } }
4, Other
1. Other system implementation
1. Java Web system series implementation
Implementation of student library management system with Java+JSP
Implementation of student information management system with Java+JSP
Implementation of user information management system with Java+JSP
Implementation of air booking system with Java+Servlet+JSP
Implementation of news release system with Java+Servlet+JSP
Implementation of library management system with Java+Servlet+JSP
Implementation of parking lot management system with Java+Servlet+JSP
Implementation of student information management system with Java+Servlet+JSP
Implementation of student course selection management system with Java+Servlet+JSP
Implementation of student achievement management System-1 with Java+Servlet+JSP
Java+Servlet+JSP to realize student achievement management System-2
Implementation of pet clinic management system with Java+Servlet+JSP
Implementation of online examination system with Java+SSM+JSP
Implementation of online examination system with Java+SSH+JSP
Implementation of hospital online registration system with Java+SSH+JSP
Java+Springboot+Mybatis+Bootstrap+Maven to realize the online mall system
2.JavaSwing system series implementation
Realizing landlords fighting game with Java+Swing
Implementation of library management system with Java+Swing
Implementation of hospital management system with Java+Swing
Implementation of examination management system with Java+Swing
Implementation of warehouse management System-1 with Java+Swing
Implementation of warehouse management System-2 with Java+Swing
Implementation of self-service ATM system with Java+Swing
Implementation of address book management system with Java+Swing
Implementation of parking lot management system with Java+Swing
Implementation of student information management system with Java+Swing
Implementation of student dormitory management system with Java+Swing
Implementation of student course selection management system with Java+Swing
Implementation of student achievement management system with Java+Swing
Implementation of school textbook management system with Java+Swing
Implementation of school educational administration management system with Java+Swing
Implementation of enterprise personnel management system with Java+Swing
Implementation of electronic album management system with Java+Swing
Java+Swing to realize supermarket management system TXT to store data
Java+Swing to realize self-service ATM system - TXT to store data
Java+Swing to realize pet store management system TXT to store data
2. Access to source code
Click the following link to get the source code. The database file is under the sql file.
Contact QQ:3079118617
3. Operation project
Please click the link below to deploy your project.
Eclipse how to import Java Swing project hyperdetailed graphic tutorial
Eclipse how to import Java Swing project super detailed video tutorial
4. Remarks
If there is infringement, please contact me to delete.
Source code link, thank you for sorting. I made some changes myself.
5. Support bloggers
If you think this article is helpful to you, please pay attention to it. I wish you a happy life! For other resources, you can focus on the official account of the left WeChat public.