怎么用Eclipse+Java+Swing+Mysql实现电影购票系统(eclipse,java,swing,开发技术)

时间:2024-04-30 15:02:36 作者 : 石家庄SEO 分类 : 开发技术
  • TAG :

    一、系统介绍

    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.数据库

    /*NavicatPremiumDataTransferSourceServer:MySQLSourceServerType:MySQLSourceServerVersion:80013SourceHost:127.0.0.1:3306SourceSchema:swing_movie_houseTargetServerType:MySQLTargetServerVersion:80013FileEncoding:65001Date:21/09/202112:33:55*/SETNAMESutf8mb4;SETFOREIGN_KEY_CHECKS=0;--------------------------------Tablestructureforcinema------------------------------DROPTABLEIFEXISTS`cinema`;CREATETABLE`cinema`(`cinema_id`int(11)NOTNULLAUTO_INCREMENT,`cname`varchar(255)CHARACTERSETutf8COLLATEutf8_binNULLDEFAULTNULL,`address`varchar(255)CHARACTERSETutf8COLLATEutf8_binNULLDEFAULTNULL,PRIMARYKEY(`cinema_id`)USINGBTREE)ENGINE=InnoDBAUTO_INCREMENT=8CHARACTERSET=utf8COLLATE=utf8_binROW_FORMAT=Dynamic;--------------------------------Recordsofcinema------------------------------INSERTINTO`cinema`VALUES(6,'光明影院','湖北武汉');INSERTINTO`cinema`VALUES(7,'大同影院','湖南长沙');--------------------------------Tablestructureforcomment------------------------------DROPTABLEIFEXISTS`comment`;CREATETABLE`comment`(`comment_id`int(11)NOTNULLAUTO_INCREMENT,`user_id`int(11)NOTNULL,`movie_id`int(11)NOTNULL,`content`varchar(255)CHARACTERSETutf8COLLATEutf8_binNULLDEFAULTNULL,`datetime`datetime(0)NULLDEFAULTNULL,PRIMARYKEY(`comment_id`)USINGBTREE,INDEX`comment_ibfk_1`(`user_id`)USINGBTREE,INDEX`comment_ibfk_2`(`movie_id`)USINGBTREE,CONSTRAINT`comment_ibfk_1`FOREIGNKEY(`user_id`)REFERENCES`user`(`user_id`)ONDELETECASCADEONUPDATERESTRICT,CONSTRAINT`comment_ibfk_2`FOREIGNKEY(`movie_id`)REFERENCES`movie`(`movie_id`)ONDELETECASCADEONUPDATERESTRICT)ENGINE=InnoDBAUTO_INCREMENT=10CHARACTERSET=utf8COLLATE=utf8_binROW_FORMAT=Dynamic;--------------------------------Recordsofcomment--------------------------------------------------------------Tablestructureforhall------------------------------DROPTABLEIFEXISTS`hall`;CREATETABLE`hall`(`hall_id`int(11)NOTNULLAUTO_INCREMENT,`hname`varchar(255)CHARACTERSETutf8COLLATEutf8_binNULLDEFAULTNULL,`capacity`int(11)NULLDEFAULTNULL,`cinema_id`int(11)NOTNULL,PRIMARYKEY(`hall_id`)USINGBTREE,INDEX`hall_ibfk_1`(`cinema_id`)USINGBTREE,CONSTRAINT`hall_ibfk_1`FOREIGNKEY(`cinema_id`)REFERENCES`cinema`(`cinema_id`)ONDELETECASCADEONUPDATECASCADE)ENGINE=InnoDBAUTO_INCREMENT=12CHARACTERSET=utf8COLLATE=utf8_binROW_FORMAT=Dynamic;--------------------------------Recordsofhall------------------------------INSERTINTO`hall`VALUES(12,'1厅',50,6);--------------------------------Tablestructureformovie------------------------------DROPTABLEIFEXISTS`movie`;CREATETABLE`movie`(`movie_id`int(11)NOTNULLAUTO_INCREMENT,`mname`varchar(255)CHARACTERSETutf8COLLATEutf8_binNULLDEFAULTNULL,`type`varchar(255)CHARACTERSETutf8COLLATEutf8_binNULLDEFAULTNULLCOMMENT'电影类型',`detail`varchar(255)CHARACTERSETutf8COLLATEutf8_binNULLDEFAULTNULL,`duration`int(11)NULLDEFAULTNULL,`img`varchar(255)CHARACTERSETutf8COLLATEutf8_binNULLDEFAULTNULLCOMMENT'保存图片名称',PRIMARYKEY(`movie_id`)USINGBTREE)ENGINE=InnoDBAUTO_INCREMENT=14CHARACTERSET=utf8COLLATE=utf8_binROW_FORMAT=Dynamic;--------------------------------Recordsofmovie------------------------------INSERTINTO`movie`VALUES(12,'八佰','抗战','八佰',120,NULL);INSERTINTO`movie`VALUES(13,'春秋','历史','春秋',150,NULL);INSERTINTO`movie`VALUES(15,'1','1','1',1,NULL);--------------------------------Tablestructureforsession------------------------------DROPTABLEIFEXISTS`session`;CREATETABLE`session`(`session_id`int(11)NOTNULLAUTO_INCREMENT,`hall_id`int(11)NOTNULL,`cinema_id`int(11)NOTNULL,`movie_id`int(11)NOTNULL,`starttime`varchar(11)CHARACTERSETutf8COLLATEutf8_binNULLDEFAULTNULL,`price`doubleNULLDEFAULTNULL,`remain`int(11)NULLDEFAULTNULL,PRIMARYKEY(`session_id`)USINGBTREE,INDEX`hall_id`(`hall_id`)USINGBTREE,INDEX`cinema_id`(`cinema_id`)USINGBTREE,INDEX`movie_id`(`movie_id`)USINGBTREE,CONSTRAINT`session_ibfk_1`FOREIGNKEY(`hall_id`)REFERENCES`hall`(`hall_id`)ONDELETERESTRICTONUPDATERESTRICT,CONSTRAINT`session_ibfk_2`FOREIGNKEY(`cinema_id`)REFERENCES`cinema`(`cinema_id`)ONDELETERESTRICTONUPDATERESTRICT,CONSTRAINT`session_ibfk_3`FOREIGNKEY(`movie_id`)REFERENCES`movie`(`movie_id`)ONDELETERESTRICTONUPDATERESTRICT)ENGINE=InnoDBAUTO_INCREMENT=14CHARACTERSET=utf8COLLATE=utf8_binROW_FORMAT=Dynamic;--------------------------------Recordsofsession------------------------------INSERTINTO`session`VALUES(14,12,6,12,'09:00:00',50,47);--------------------------------Tablestructureforticket------------------------------DROPTABLEIFEXISTS`ticket`;CREATETABLE`ticket`(`ticket_id`int(11)NOTNULLAUTO_INCREMENT,`user_id`int(11)NOTNULL,`movie_id`int(11)NOTNULL,`session_id`int(11)NOTNULL,`seat`varchar(255)CHARACTERSETutf8COLLATEutf8_binNULLDEFAULTNULL,PRIMARYKEY(`ticket_id`)USINGBTREE,INDEX`ticket_ibfk_1`(`user_id`)USINGBTREE,INDEX`ticket_ibfk_2`(`movie_id`)USINGBTREE,INDEX`ticket_ibfk_3`(`session_id`)USINGBTREE,CONSTRAINT`ticket_ibfk_1`FOREIGNKEY(`user_id`)REFERENCES`user`(`user_id`)ONDELETECASCADEONUPDATECASCADE,CONSTRAINT`ticket_ibfk_2`FOREIGNKEY(`movie_id`)REFERENCES`movie`(`movie_id`)ONDELETECASCADEONUPDATECASCADE,CONSTRAINT`ticket_ibfk_3`FOREIGNKEY(`session_id`)REFERENCES`session`(`session_id`)ONDELETECASCADEONUPDATECASCADE)ENGINE=InnoDBAUTO_INCREMENT=64CHARACTERSET=utf8COLLATE=utf8_binROW_FORMAT=Dynamic;--------------------------------Recordsofticket------------------------------INSERTINTO`ticket`VALUES(64,1,12,14,'3');--------------------------------Tablestructureforuser------------------------------DROPTABLEIFEXISTS`user`;CREATETABLE`user`(`user_id`int(11)NOTNULLAUTO_INCREMENT,`uname`varchar(255)CHARACTERSETutf8COLLATEutf8_binNULLDEFAULTNULL,`passwd`varchar(255)CHARACTERSETutf8COLLATEutf8_binNULLDEFAULTNULL,`type`int(11)NULLDEFAULT0COMMENT'0代表普通用户,1代表管理员',`balance`doubleNULLDEFAULTNULL,`level`int(11)NULLDEFAULTNULL,PRIMARYKEY(`user_id`)USINGBTREE)ENGINE=InnoDBAUTO_INCREMENT=11CHARACTERSET=utf8COLLATE=utf8_binROW_FORMAT=Dynamic;--------------------------------Recordsofuser------------------------------INSERTINTO`user`VALUES(1,'user','user',0,161,1);INSERTINTO`user`VALUES(2,'admin','admin',1,1,1);SETFOREIGN_KEY_CHECKS=1;

    5.工程截图

    怎么用Eclipse+Java+Swing+Mysql实现电影购票系统

    二、系统展示

    1.注册系统

    怎么用Eclipse+Java+Swing+Mysql实现电影购票系统

    2.登录系统

    怎么用Eclipse+Java+Swing+Mysql实现电影购票系统

    3.用户-欢迎界面

    怎么用Eclipse+Java+Swing+Mysql实现电影购票系统

    4.用户-影片排行榜

    怎么用Eclipse+Java+Swing+Mysql实现电影购票系统

    5.用户-购票信息

    怎么用Eclipse+Java+Swing+Mysql实现电影购票系统

    6.用户-场次信息

    怎么用Eclipse+Java+Swing+Mysql实现电影购票系统

    7.用户-充值余额

    怎么用Eclipse+Java+Swing+Mysql实现电影购票系统

    8.用户-搜索电影

    怎么用Eclipse+Java+Swing+Mysql实现电影购票系统

    9.管理员-首页

    怎么用Eclipse+Java+Swing+Mysql实现电影购票系统

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

    怎么用Eclipse+Java+Swing+Mysql实现电影购票系统

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

    怎么用Eclipse+Java+Swing+Mysql实现电影购票系统

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

    怎么用Eclipse+Java+Swing+Mysql实现电影购票系统

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

    怎么用Eclipse+Java+Swing+Mysql实现电影购票系统

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

    怎么用Eclipse+Java+Swing+Mysql实现电影购票系统

    三、部分代码

    AdminMainView.java

    packageview;importjava.awt.BorderLayout;importjava.awt.Color;importjava.awt.EventQueue;importjava.awt.Font;importjava.awt.GridLayout;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjavax.swing.BorderFactory;importjavax.swing.ImageIcon;importjavax.swing.JButton;importjavax.swing.JDesktopPane;importjavax.swing.JFrame;importjavax.swing.JLabel;importjavax.swing.JPanel;importentity.User;publicclassAdminMainViewextendsJFrame{privateJPanelmain_panel=null;privateJPanelfun_panel=null;privateJDesktopPanefundesk=null;privateJButtonoper_User=null;privateJButtonoper_Cinema=null;privateJButtonoper_Hall=null;privateJButtonoper_Session=null;privateJButtonoper_Movie=null;privateJButtonback=null;privateJLabellb_welcome=null;privateJLabellb_image=null;privateUseradmin=null;publicAdminMainView(){init();RegisterListener();}publicAdminMainView(Useradmin){this.admin=admin;init();RegisterListener();}privatevoidinit(){main_panel=newJPanel(newBorderLayout());fun_panel=newJPanel(newGridLayout(8,1,0,18));oper_User=newJButton("对用户进行操作");oper_Cinema=newJButton("对影院进行操作");oper_Hall=newJButton("对场厅进行操作");oper_Session=newJButton("对场次进行操作");oper_Movie=newJButton("对电影进行操作");back=newJButton("返回");fun_panel.add(newJLabel());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(newJLabel());//设置面板外观fun_panel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createRaisedBevelBorder(),"功能区"));lb_welcome=newJLabel("欢迎"+admin.getUname()+"进入管理员功能界面");lb_welcome.setFont(newFont("楷体",Font.BOLD,34));lb_welcome.setForeground(Color.BLUE);fundesk=newJDesktopPane();ImageIconimg=newImageIcon(ClassLoader.getSystemResource("image/beijjing3.jpg"));lb_image=newJLabel(img);lb_image.setBounds(10,10,img.getIconWidth(),img.getIconHeight());fundesk.add(lb_image,newInteger(Integer.MIN_VALUE));main_panel.add(lb_welcome,BorderLayout.NORTH);main_panel.add(fun_panel,BorderLayout.EAST);main_panel.add(fundesk,BorderLayout.CENTER);//为了不让线程阻塞,来调用线程//放入队列当中EventQueue.invokeLater(newRunnable(){publicvoidrun(){newThread(newthread()).start();}});this.setTitle("管理员功能界面");this.getContentPane().add(main_panel);this.setSize(880,600);this.setResizable(false);this.setVisible(true);this.setLocationRelativeTo(null);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}//开启线程使得欢迎标签动起来//这是单线程privateclassthreadimplementsRunnable{@Overridepublicvoidrun(){while(true){//死循环让其一直移动for(inti=900;i>-700;i--){//for(inti=-100;i<900;i++){try{Thread.sleep(10);//让线程休眠100毫秒}catch(InterruptedExceptione){e.printStackTrace();}lb_welcome.setLocation(i,5);}}}}privatevoidRegisterListener(){oper_User.addActionListener(newActionListener(){@OverridepublicvoidactionPerformed(ActionEvente){operUserViewouv=newoperUserView();fundesk.add(ouv);ouv.toFront();}});oper_Cinema.addActionListener(newActionListener(){@OverridepublicvoidactionPerformed(ActionEvente){operCinemaViewocv=newoperCinemaView();fundesk.add(ocv);ocv.toFront();}});oper_Hall.addActionListener(newActionListener(){@OverridepublicvoidactionPerformed(ActionEvente){operHallViewohv=newoperHallView();fundesk.add(ohv);ohv.toFront();}});oper_Session.addActionListener(newActionListener(){@OverridepublicvoidactionPerformed(ActionEvente){operSessionViewosv=newoperSessionView();fundesk.add(osv);osv.toFront();}});oper_Movie.addActionListener(newActionListener(){@OverridepublicvoidactionPerformed(ActionEvente){operMovieViewomv=newoperMovieView();fundesk.add(omv);omv.toFront();}});back.addActionListener(newActionListener(){@OverridepublicvoidactionPerformed(ActionEvente){newLogin();AdminMainView.this.dispose();}});}}

    MovieInfoView.java

    packageview;importjava.awt.Color;importjava.awt.Font;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjava.text.SimpleDateFormat;importjava.util.List;importjavax.swing.GroupLayout;importjavax.swing.GroupLayout.Alignment;importjavax.swing.ImageIcon;importjavax.swing.JButton;importjavax.swing.JFrame;importjavax.swing.JLabel;importjavax.swing.JPanel;importjavax.swing.JScrollPane;importjavax.swing.JTable;importjavax.swing.JTextField;importjavax.swing.LayoutStyle.ComponentPlacement;importjavax.swing.border.EmptyBorder;importjavax.swing.table.DefaultTableModel;importentity.Comment;importentity.Movie;importentity.User;importservice.CommentService;importservice.MovieService;importservice.UserService;importserviceimpl.CommentServiceImpl;importserviceimpl.MovieServiceImpl;importserviceimpl.UserServiceImpl;publicclassMovieInfoViewextendsJFrame{privateJPanelcontentPane;privateJTabletable;JScrollPanescrollPane=null;Moviemovie=null;Useruser=null;MovieServicems=null;CommentServicecs=null;UserServiceus=null;publicMovieInfoView(Moviemovie,Useruser){this.movie=movie;this.user=user;ms=newMovieServiceImpl();cs=newCommentServiceImpl();us=newUserServiceImpl();setTitle("用户选票界面");setBounds(260,130,620,600);this.setLocationRelativeTo(null);contentPane=newJPanel();contentPane.setBorder(newEmptyBorder(5,5,5,5));setContentPane(contentPane);JLabellblNewLabel=newJLabel("Newlabel");lblNewLabel.setIcon(newImageIcon("image/"+movie.getImg()));JLabellabel=newJLabel("正在热映···");JLabellblNewLabel_1=newJLabel("影片名:");lblNewLabel_1.setFont(newFont("楷体",Font.BOLD,18));JLabellabel_1=newJLabel("类型:");JLabellabel_2=newJLabel("时长:");JLabellabel_3=newJLabel("电影详情:");JLabellabel_4=newJLabel(movie.getMname());label_4.setFont(newFont("楷体",Font.BOLD,18));JButtonbtnNewButton=newJButton("购买");btnNewButton.setForeground(Color.BLUE);btnNewButton.addActionListener(newActionListener(){@OverridepublicvoidactionPerformed(ActionEvente){newUserUi(user,3);movie.getMovie_id();List<Movie>movieByName=ms.getMovieByName(movie.getMname());for(Moviemovie2:movieByName){System.out.println(movie2);}MovieInfoView.this.dispose();}});JButtonbutton=newJButton("取消");button.setForeground(Color.RED);button.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){MovieInfoView.this.dispose();}});scrollPane=newJScrollPane();scrollPane.setEnabled(false);scrollPane.setVisible(false);JButtonbutton_1=newJButton("查看评论");button_1.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){scrollPane.setVisible(true);showComment();table.repaint();}});button_1.setForeground(Color.MAGENTA);JLabellblNewLabel_2=newJLabel("欢迎来到电影详情界面");lblNewLabel_2.setFont(newFont("新宋体",Font.BOLD,20));lblNewLabel_2.setForeground(Color.BLACK);JLabellabel_5=newJLabel(movie.getType());JLabellabel_6=newJLabel(movie.getDuration()+"分钟");JLabellabel_7=newJLabel(movie.getDetail());GroupLayoutgl_contentPane=newGroupLayout(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);}publicvoidshowComment(){List<Comment>commlist=cs.getAllCommentByMovieId(movie.getMovie_id());intrecordrow=0;if(commlist!=null){recordrow=commlist.size();}String[][]rinfo=newString[recordrow][3];SimpleDateFormatsdf=newSimpleDateFormat("yy-MM-ddhh:mm");for(inti=0;i<recordrow;i++){for(intj=0;j<3;j++){rinfo[i][j]=newString();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={"用户名","评论内容","评论时间"};table=newJTable(rinfo,tbheadnames);table.setBorder(null);table.setRowHeight(20);table.setEnabled(false);table.getColumnModel().getColumn(0).setPreferredWidth(30);table.getTableHeader().setFont(newFont("楷体",1,20));table.getTableHeader().setBackground(Color.CYAN);table.getTableHeader().setReorderingAllowed(false);//不可交换顺序table.getTableHeader().setResizingAllowed(true);//不可拉动表格scrollPane.add(table);scrollPane.setBorder(null);table.repaint();}}

    operCinemaView.java

    packageview;importjava.awt.BorderLayout;importjava.awt.GridLayout;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjava.awt.event.MouseAdapter;importjava.awt.event.MouseEvent;importjava.util.ArrayList;importjava.util.List;importjavax.swing.BorderFactory;importjavax.swing.JButton;importjavax.swing.JComboBox;importjavax.swing.JInternalFrame;importjavax.swing.JLabel;importjavax.swing.JOptionPane;importjavax.swing.JPanel;importjavax.swing.JTable;importjavax.swing.JTextField;importjavax.swing.event.TableModelListener;importjavax.swing.table.TableModel;importentity.Cinema;importservice.CinemaService;importserviceimpl.CinemaServiceImpl;publicclassoperCinemaViewextendsJInternalFrame{privateJPanelpl_main=null;privateJPanelpl_button=null;privateJPanelpl_text=null;privateJTabletable=null;privateJButtonbtn_add=null;privateJButtonbtn_query=null;privateJButtonbtn_del=null;privateJComboBox<String>cb_query=null;privateJButtonbtn_back=null;privateJLabellb_name=null;privateJLabellb_address=null;privateJTextFieldtf_qname=null;//查询时输入的名称privateJTextFieldtf_name=null;//添加输入的名称privateJTextFieldtf_address=null;privateCinemaServicecinemabiz=null;privateList<Cinema>cinemaList=null;privateCinemaInfoTableModelinfoTableModel=null;//privateList<Hall>hallList=null;//privateList<Session>sessionList=null;//privateHallBizhallbiz=null;//privateSessionBizsessionbiz=null;publicoperCinemaView(){cinemabiz=newCinemaServiceImpl();//hallbiz=newHallBizImpl();//sessionbiz=newSessionBizImpl();init();RegisterListener();}privatevoidinit(){pl_main=newJPanel(newBorderLayout());pl_button=newJPanel(newGridLayout(8,1,0,40));pl_text=newJPanel(newGridLayout(1,4));cinemaList=newArrayList<Cinema>();table=newJTable();refreshTable(cinemaList);cb_query=newJComboBox<String>(newString[]{"查询所有影院","按名字查找影院"});tf_qname=newJTextField(8);tf_qname.setEnabled(false);btn_query=newJButton("查询");btn_add=newJButton("增添影院");btn_del=newJButton("删除影院");btn_del.setEnabled(false);btn_back=newJButton("退出窗口");lb_name=newJLabel("影院名称:");tf_name=newJTextField(8);lb_address=newJLabel("影院地址:");tf_address=newJTextField(12);pl_main.add(table.getTableHeader(),BorderLayout.PAGE_START);pl_main.add(table);pl_main.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(null,null),"查询信息"));pl_button.add(newJLabel());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(newJLabel());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("影院操作界面");this.setSize(700,530);this.setIconifiable(true);this.setClosable(true);this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);}privatevoidRegisterListener(){table.addMouseListener(newMouseAdapter(){@OverridepublicvoidmouseClicked(MouseEvente){if(table.getSelectedRow()!=-1){btn_del.setEnabled(true);}introw=table.getSelectedRow();Stringname=table.getValueAt(row,1).toString();Stringaddress=table.getValueAt(row,2).toString();tf_name.setText(name);tf_address.setText(address);}});cb_query.addActionListener(newActionListener(){@OverridepublicvoidactionPerformed(ActionEvente){if(cb_query.getSelectedIndex()+1==2){tf_qname.setEnabled(true);}else{tf_qname.setEnabled(false);}}});btn_query.addActionListener(newActionListener(){@OverridepublicvoidactionPerformed(ActionEvente){if(cb_query.getSelectedIndex()+1==1){cinemaList=cinemabiz.queryAllCinema();refreshTable(cinemaList);}else{Stringname=tf_qname.getText().trim();cinemaList=cinemabiz.queryCinemaByName(name);refreshTable(cinemaList);}}});btn_add.addActionListener(newActionListener(){@OverridepublicvoidactionPerformed(ActionEvente){Stringname=tf_name.getText().trim();Stringaddress=tf_address.getText().trim();if(name.equals("")){JOptionPane.showMessageDialog(operCinemaView.this,"影院名称不能为空!");}elseif(address.equals("")){JOptionPane.showMessageDialog(operCinemaView.this,"影院地址不能为空!");}else{intflag=JOptionPane.showConfirmDialog(operCinemaView.this,"确认是否添加?","确认信息",JOptionPane.YES_NO_OPTION);if(flag==JOptionPane.YES_OPTION){Cinemacinema=newCinema(name,address);booleanres=cinemabiz.addCinema(cinema);if(res){cinemaList=cinemabiz.queryAllCinema();refreshTable(cinemaList);JOptionPane.showMessageDialog(operCinemaView.this,"添加成功!");}else{JOptionPane.showMessageDialog(operCinemaView.this,"添加失败!");}}}}});btn_del.addActionListener(newActionListener(){@OverridepublicvoidactionPerformed(ActionEvente){introw=table.getSelectedRow();intid=(Integer)table.getValueAt(row,0);intflag=JOptionPane.showConfirmDialog(operCinemaView.this,"确认是否删除此影院?","确认信息",JOptionPane.YES_NO_OPTION);if(flag==JOptionPane.YES_OPTION){booleanres=cinemabiz.deleteCinemaById(id);/**if(res){//更新数据hallList=hallbiz.queryAllHall();inthid=0;for(inti=*0;i<hallList.size();i++){if(id==hallList.get(i).getCid()){hid=*hallList.get(i).getId();hallbiz.delHall(hid);}}sessionList=*sessionbiz.queryAllSession();for(inti=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(newActionListener(){@OverridepublicvoidactionPerformed(ActionEvente){operCinemaView.this.dispose();}});}publicclassCinemaInfoTableModelimplementsTableModel{publicList<Cinema>cinemaList=null;publicCinemaInfoTableModel(List<Cinema>cinemaList){this.cinemaList=cinemaList;}@OverridepublicintgetRowCount(){returncinemaList.size();}@OverridepublicintgetColumnCount(){return3;}@OverridepublicStringgetColumnName(intcolumnIndex){if(columnIndex==0){return"影院ID";}elseif(columnIndex==1){return"影院名称";}elseif(columnIndex==2){return"影院地址";}else{return"出错";}}@OverridepublicClass<?>getColumnClass(intcolumnIndex){returnString.class;}@OverridepublicbooleanisCellEditable(introwIndex,intcolumnIndex){returnfalse;}@OverridepublicObjectgetValueAt(introwIndex,intcolumnIndex){Cinemacinema=cinemaList.get(rowIndex);if(columnIndex==0){returncinema.getCinema_id();}elseif(columnIndex==1){returncinema.getCname();}elseif(columnIndex==2){returncinema.getAddress();}else{return"出错";}}@OverridepublicvoidsetValueAt(ObjectaValue,introwIndex,intcolumnIndex){//TODOAuto-generatedmethodstub}@OverridepublicvoidaddTableModelListener(TableModelListenerl){//TODOAuto-generatedmethodstub}@OverridepublicvoidremoveTableModelListener(TableModelListenerl){//TODOAuto-generatedmethodstub}}privatevoidrefreshTable(List<Cinema>cinemaList){infoTableModel=newCinemaInfoTableModel(cinemaList);table.setModel(infoTableModel);table.setRowHeight(20);}}

    operHallView.java

    packageview;importjava.awt.BorderLayout;importjava.awt.GridLayout;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjava.awt.event.MouseAdapter;importjava.awt.event.MouseEvent;importjava.util.ArrayList;importjava.util.List;importjavax.swing.BorderFactory;importjavax.swing.JButton;importjavax.swing.JInternalFrame;importjavax.swing.JLabel;importjavax.swing.JOptionPane;importjavax.swing.JPanel;importjavax.swing.JTable;importjavax.swing.JTextField;importjavax.swing.event.TableModelListener;importjavax.swing.table.TableModel;importentity.Cinema;importentity.Hall;importentity.Session;importservice.CinemaService;importservice.HallService;importserviceimpl.CinemaServiceImpl;importserviceimpl.HallServiceImpl;importserviceimpl.SessionServiceImpl;importutil.Check;publicclassoperHallViewextendsJInternalFrame{privateJPanelpl_main=null;privateJPanelpl_button=null;privateJPanelpl_text=null;privateJTabletable=null;privateJButtonbtn_add=null;privateJButtonbtn_del=null;privateJButtonbtn_query=null;privateJButtonbtn_back=null;privateJLabellb_name=null;privateJLabellb_cid=null;privateJLabellb_capacity=null;privateJTextFieldtf_name=null;//添加输入的名称privateJTextFieldtf_cid=null;//添加时输入的所属影院idprivateJTextFieldtf_capacity=null;//添加输入的名称privateHallServicehallbiz=null;privateCinemaServicecinemabiz=null;privateSessionServiceImplsessionbiz=null;privateList<Hall>hallList=null;privateHallInfoTableModelinfoTableModel=null;publicoperHallView(){hallbiz=newHallServiceImpl();cinemabiz=newCinemaServiceImpl();//查询出所有的影院与cid进行匹配,显示影院名称sessionbiz=newSessionServiceImpl();init();RegisterListener();}privatevoidinit(){pl_main=newJPanel(newBorderLayout());pl_button=newJPanel(newGridLayout(6,1,0,40));pl_text=newJPanel(newGridLayout(1,6));hallList=newArrayList<Hall>();table=newJTable();//绑定JTabel,呈现数据refreshTable(hallList);btn_query=newJButton("查询所有场厅");btn_add=newJButton("增添场厅");btn_del=newJButton("删除场厅");btn_del.setEnabled(false);btn_back=newJButton("退出窗口");tf_name=newJTextField(8);tf_cid=newJTextField(8);tf_capacity=newJTextField(8);lb_name=newJLabel("场厅名称");lb_cid=newJLabel("所属影院id");lb_capacity=newJLabel("场厅容量");pl_main.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(null,null),"查询信息"));pl_main.add(table.getTableHeader(),BorderLayout.PAGE_START);pl_main.add(table);this.add(pl_main,BorderLayout.CENTER);pl_button.add(newJLabel());pl_button.add(btn_query);pl_button.add(btn_add);pl_button.add(btn_del);pl_button.add(newJLabel());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("场厅操作界面");this.setSize(700,530);this.setIconifiable(true);this.setClosable(true);this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);}privatevoidRegisterListener(){table.addMouseListener(newMouseAdapter(){@OverridepublicvoidmouseClicked(MouseEvente){//加入选中一行,删除按钮变为可用if(table.getSelectedRow()!=-1){btn_del.setEnabled(true);}introw=table.getSelectedRow();Stringname=table.getValueAt(row,1).toString();Stringcid=table.getValueAt(row,2).toString();Stringcapacity=table.getValueAt(row,3).toString();tf_name.setText(name);tf_cid.setText(cid);tf_capacity.setText(capacity);}});btn_add.addActionListener(newActionListener(){@OverridepublicvoidactionPerformed(ActionEvente){Stringname=tf_name.getText().trim();Stringcid=tf_cid.getText().trim();Stringcapacity=tf_capacity.getText().trim();if(name.equals("")){JOptionPane.showMessageDialog(operHallView.this,"场厅名称不能为空!");}elseif(cid.equals("")){JOptionPane.showMessageDialog(operHallView.this,"所属影院id不能为空!");}elseif(capacity.equals("")){JOptionPane.showMessageDialog(operHallView.this,"场厅容量不能为空!");}elseif(!Check.isNumber(cid)){JOptionPane.showMessageDialog(operHallView.this,"所属影院id只能为数字!");}elseif(!Check.isNumber(capacity)){JOptionPane.showMessageDialog(operHallView.this,"场厅容量只能为数字!");}else{intflag=JOptionPane.showConfirmDialog(operHallView.this,"是否添加此场厅?","确认信息",JOptionPane.YES_NO_OPTION);if(flag==JOptionPane.YES_OPTION){Hallhall=newHall(name,newInteger(capacity),newInteger(cid));booleanres=hallbiz.addHall(hall);hallList=hallbiz.queryAllHall();refreshTable(hallList);if(res){JOptionPane.showMessageDialog(operHallView.this,"添加成功!");}else{JOptionPane.showMessageDialog(operHallView.this,"添加失败!");}}}}});btn_query.addActionListener(newActionListener(){@OverridepublicvoidactionPerformed(ActionEvente){//清除数据,防止累加if(hallList!=null){hallList.clear();}hallList=hallbiz.queryAllHall();refreshTable(hallList);}});btn_del.addActionListener(newActionListener(){@OverridepublicvoidactionPerformed(ActionEvente){introw=table.getSelectedRow();intid=(Integer)table.getValueAt(row,0);intflag=JOptionPane.showConfirmDialog(operHallView.this,"确认是否删除此场厅?","确认信息",JOptionPane.YES_NO_OPTION);if(flag==JOptionPane.YES_OPTION){booleanres=hallbiz.delHall(id);if(res){JOptionPane.showMessageDialog(operHallView.this,"删除成功!");//更新数据List<Session>sessionList=newArrayList<Session>();sessionList=sessionbiz.queryAllSession();//删除某场厅后,对应的场次也进行删除intsid=0;for(inti=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);//更新显示数据}else{JOptionPane.showMessageDialog(operHallView.this,"删除失败!");}}}});btn_back.addActionListener(newActionListener(){@OverridepublicvoidactionPerformed(ActionEvente){operHallView.this.dispose();}});}privateclassHallInfoTableModelimplementsTableModel{publicList<Hall>hallList=null;publicHallInfoTableModel(List<Hall>hallList){this.hallList=hallList;}//JTable显示的行数@OverridepublicintgetRowCount(){returnhallList.size();}//JTable显示的列数@OverridepublicintgetColumnCount(){return4;}//JTable显示各行的名称@OverridepublicStringgetColumnName(intcolumnIndex){if(columnIndex==0){return"场厅ID";}elseif(columnIndex==1){return"场厅名称";}elseif(columnIndex==2){return"所属影院";}elseif(columnIndex==3){return"场厅容量";}else{return"出错";}}//JTable列的数据类型@OverridepublicClass<?>getColumnClass(intcolumnIndex){returnString.class;}//单元格是否可编辑@OverridepublicbooleanisCellEditable(introwIndex,intcolumnIndex){returnfalse;}//每行单元格显示的数据@OverridepublicObjectgetValueAt(introwIndex,intcolumnIndex){Hallhall=hallList.get(rowIndex);Cinemacinema=null;if(columnIndex==0){returnhall.getHall_id();}elseif(columnIndex==1){returnhall.getHname();}elseif(columnIndex==2){List<Cinema>cinemaList=cinemabiz.queryAllCinema();for(inti=0;i<cinemaList.size();i++){if(hall.getCinema_id()==cinemaList.get(i).getCinema_id()){cinema=cinemaList.get(i);break;}}returncinema.getCname();//returnhall.getCid();}elseif(columnIndex==3){returnhall.getCapacity();}else{return"出错";}}@OverridepublicvoidsetValueAt(ObjectaValue,introwIndex,intcolumnIndex){//TODOAuto-generatedmethodstub}@OverridepublicvoidaddTableModelListener(TableModelListenerl){//TODOAuto-generatedmethodstub}@OverridepublicvoidremoveTableModelListener(TableModelListenerl){//TODOAuto-generatedmethodstub}}privatevoidrefreshTable(List<Hall>hallList){infoTableModel=newHallInfoTableModel(hallList);table.setModel(infoTableModel);table.setRowHeight(20);}}
     </div> <div class="zixun-tj-product adv-bottom"></div> </div> </div> <div class="prve-next-news">
    本文:怎么用Eclipse+Java+Swing+Mysql实现电影购票系统的详细内容,希望对您有所帮助,信息来源于网络。
    上一篇:python中的jsonpath提取器怎么用下一篇:

    3 人围观 / 0 条评论 ↓快速评论↓

    (必须)

    (必须,保密)

    阿狸1 阿狸2 阿狸3 阿狸4 阿狸5 阿狸6 阿狸7 阿狸8 阿狸9 阿狸10 阿狸11 阿狸12 阿狸13 阿狸14 阿狸15 阿狸16 阿狸17 阿狸18