java实现酒店管理系统
本文实例为大家分享了java实现酒店管理系统的具体代码,供大家参考,具体内容如下
编写环境:MyEclipse2014+sqlserver2014
系统功能:
1.登录验证
2.房态统计显示
3.预定登记并入库
4.入住登记并入库
5.换房登记并入库
6.客人信息查询
7.退房并入库
运行界面如下:
=====登录界面======
=====主界面=====
=====为每个房间设置弹出菜单======
=====登记界面======
=====换房界面=====
=====退房界面=====
界面之间相关关系:
主界面主要由菜单条,按钮,标签等组成,一个JButton是一个房间,其Test从数据库中获取,颜色由房态决定。
登记-换房-查看信息-退房等界面皆继承一个父类而来,简单快捷。
主要代码目录:
1.数据库操作类
/**====================================================** *项目名:酒店管理系统 *模块名:数据库连接 *文件名:DataBaseConnct.java *相关文件: *实现功能:jdbc连接数据库 *函数说明: *[##publicVectorgetId(){}]: *功能:获取数据库中系统登录ID * *[##publicvoidsetId(){}]: *功能:设置数据库中系统登录ID * *[##publicVectorgetPassword(){}]: *功能:获取数据库中系统登录密码 * *[##publicvoidsetPassword(){}]: *功能:设置数据库中系统登录密码 * *[##publicVectorgetRoonnum(){}]: *功能:获取数据库中房间号 * *[##publicvoidsetRoonnum(){}]: *功能:设置数据库中房间号 * *[##publicVectorgetRoomtype(){}]: *功能:获取数据库中房间类型 * *[##publicvoidseRoomtype(){}]: *功能:设置数据库中房间类型 * *[##publicvoidSql(Stringsql){}]: *功能:执行sql语句进行查询 * **===================================================**/ packagecom.common; importjava.sql.*; importjava.util.Vector; importjavax.swing.JOptionPane; importjavax.xml.crypto.dsig.keyinfo.RetrievalMethod; publicclassDataBaseConnect{ privateStringdriverName="com.microsoft.sqlserver.jdbc.SQLServerDriver"; privateStringdbURL="jdbc:sqlserver://localhost:1433;DatabaseName=hotel_mangerment_system"; privateStringuserName="sa"; privateStringuserPwd="1451171"; privateConnectionct=null; privateResultSetrs=null; privateStatementst; privateVectorid=newVector(); privateVectorpassword=newVector(); /**====================================================** *获取数据库中系统登录ID **===================================================**/ publicVectorgetId(){ returnid; } /**====================================================** *设置数据库中系统登录ID **===================================================**/ publicvoidsetId(Vectorid){ this.id=id; } /**====================================================** *获取数据库中系统登录密码 **===================================================**/ publicVectorgetPassword(){ returnpassword; } /**====================================================** *设置数据库中系统登录ID **===================================================**/ publicvoidsetPassword(Vectorpassword){ this.password=password; } /**====================================================** *[##publicvoidSql(Stringsql){}] *参数:Stringsql *返回值:无 *修饰符:public *功能:创建sql查询,从数据库里查询登陆账号与密码 **===================================================**/ publicvoidSql(Stringsql)throwsException { Class.forName(driverName); ct=DriverManager.getConnection(dbURL,userName,userPwd); st=ct.createStatement(); rs=st.executeQuery(sql); while(rs.next()) { id.add(rs.getInt(1)); password.add(rs.getInt(2)); } if(rs!=null) rs.close(); if(st!=null) st.close(); if(ct!=null) ct.close(); } /**====================================================** *[##publicVectorRoomOperation(introom_num){}]查询房间信息 *参数:introom_num *返回值:无 *修饰符:public *功能:创建sql查询房间号与类型,类外可使用 **===================================================**/ publicVectorRoomOperation(introom_num)throwsException { Vector
2.登录界面类
/**====================================================** *项目名:酒店管理系统 *模块名:系统登录窗口 *文件名:HotelLoginGui.java *相关文件:DataBaseConnct.javaHotelMainGui.java *实现功能:系统登录界面 *函数说明: *[##publicMyJframe(){}]: *功能:构造函数组建登录窗口 *[##publicvoidenevtOperation(finalMyLoginJframemj){}] *功能:登录界面的事件监听处理 *[##privatebooleanloginCheck(){}]: *功能:登录验证,仅类内使用 *[##privatevoidquit(){}]: *功能:关闭系统函数,仅类内使用 **===================================================**/ packagecom.HotelGui; importcom.common.*;//引入包 importjava.awt.*; importjava.awt.event.ActionEvent; importjava.awt.event.ActionListener; importjava.awt.event.ItemEvent; importjava.awt.event.ItemListener; importjavax.jws.soap.SOAPBinding.Style; importjavax.swing.*; importjava.net.*; importjava.util.*; publicclassHotelLoginGui{ publicstaticvoidmain(String[]args){ //TODOAuto-generatedmethodstub MyLoginJframelogingui=newMyLoginJframe(); logingui.enevtOperation(logingui); } } //登录界面MyJframe classMyLoginJframeextendsJFrameimplementsActionListener { DataBaseConnectdc; JPasswordFieldpasswordnum; JTextFieldaccountnum; JLabelpassword,account,login,backimg,backimg1; JLabeltiplabel; JComboBoxloginchoice; JButtonloginbutton,resetbutton,exitbutton; JPaneljp,jp0,jp1,jp2,jp3,jp4,jp5; Vector dept=newVector (); privateStringid_now,user_type; /**=======================================================** *设置当前成功登录的ID **========================================================*/ publicvoidsetId_now(Stringid_now){ this.id_now=id_now; } /**=======================================================** *获得当前成功登录的ID **========================================================*/ publicStringgetId_now(){ returnid_now; } /**====================================================** ***[##publicMyJframe(){}]组建登录窗口 *参数:无 *返回值:无 *修饰符:public *功能:组建登录窗口 **===================================================**/ publicMyLoginJframe() {dc=newDataBaseConnect();//连接数据库实例 jp=newJPanel(); jp.setBounds(0,-5,550,200); jp0=newJPanel(); jp0.setBounds(0,180,250,250); jp1=newJPanel(); jp1.setBounds(270,215,250,30); jp2=newJPanel(); jp2.setBounds(270,250,250,30); jp3=newJPanel(); jp3.setBounds(270,280,250,30); jp4=newJPanel(); jp4.setBounds(270,335,250,40); jp5=newJPanel(); jp5.setBounds(270,380,250,30); dept.add("经理"); dept.add("部门主管"); dept.add("普通员工"); account=newJLabel("账户"); password=newJLabel("密码"); login=newJLabel("用户"); backimg=newJLabel(newImageIcon("images\\back.jpg")); backimg1=newJLabel(newImageIcon("images\\back1.jpg")); tiplabel=newJLabel(); tiplabel.setFont(newFont("宋体",Font.PLAIN,12)); tiplabel.setForeground(Color.red); tiplabel.setVisible(false); passwordnum=newJPasswordField(12); accountnum=newJTextField(12); loginbutton=newJButton("登录"); loginbutton.setOpaque(false); loginbutton.setContentAreaFilled(false); resetbutton=newJButton("重置"); resetbutton.setOpaque(false); resetbutton.setContentAreaFilled(false); exitbutton=newJButton("退出"); exitbutton.setOpaque(false); exitbutton.setContentAreaFilled(false); loginchoice=newJComboBox(dept); jp.add(backimg); jp0.add(backimg1); jp1.add(account); jp1.add(accountnum); jp2.add(password); jp2.add(passwordnum); jp3.add(login); jp3.add(loginchoice); jp4.add(loginbutton); jp4.add(resetbutton); jp4.add(exitbutton); jp5.add(tiplabel); this.add(jp); this.add(jp0); this.add(jp1); this.add(jp2); this.add(jp3); this.add(jp4); this.add(jp5); this.setTitle("系统登录"); this.setLayout(null); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setResizable(false); this.setBounds(320,160,550,450); this.setIconImage(newImageIcon("images\\icon.jpg").getImage()); this.setVisible(true); } /**====================================================** ***[##privatevoidenevtOperation(){}]事件处理 *参数:无 *返回值:无 *修饰符:public *功能:登录窗口的事件操作 **===================================================**/ publicvoidenevtOperation(finalMyLoginJframemj) { /**=======================================================** *登录按钮监听事件 **========================================================*/ loginbutton.addActionListener(newActionListener(){ @Override publicvoidactionPerformed(ActionEvente){ //TODOAuto-generatedmethodstub if(loginCheck()) { tiplabel.setText("正在登录..."); //记录当前的操作记录 id_now=accountnum.getText(); user_type=loginchoice.getSelectedItem().toString(); MyHotelMainGuimm=newMyHotelMainGui();//登录到主界面 mj.dispose(); //显示当前的操作人员信息 mm.setId_now(id_now); mm.setUser_type(user_type); mm.enevtOpration(); mm.updateRoomState(); Threadth=newThread(mm); th.start(); } elseif(accountnum.getText().isEmpty()&&passwordnum.getPassword().length==0) tiplabel.setText("密码与账号不能为空!"); elseif(accountnum.getText().isEmpty()&&passwordnum.getPassword().length!=0) tiplabel.setText("请输入账号..."); elseif(accountnum.getText().isEmpty()==false&&passwordnum.getPassword().length==0) tiplabel.setText("请输入密码..."); else tiplabel.setText("请检查后重新输入!"); tiplabel.setVisible(true); } }); /**=======================================================** *重置按钮监听事件 **========================================================*/ resetbutton.addActionListener(newActionListener(){ @Override publicvoidactionPerformed(ActionEvente){ //TODOAuto-generatedmethodstub accountnum.setText(""); passwordnum.setText(""); loginchoice.setSelectedIndex(0); } }); /**=======================================================** *退出按钮监听事件 **========================================================*/ exitbutton.addActionListener(newActionListener(){ @Override publicvoidactionPerformed(ActionEvente){ //TODOAuto-generatedmethodstub quit(); } }); } /**====================================================** ***[##privatebooleanloginCheck(){}]登陆验证 *参数:无 *返回值:flag *修饰符:private *功能:登录验证,仅类内使用 **===================================================**/ publicbooleanloginCheck() { booleanflag=false; if(loginchoice.getSelectedIndex()==0) { try{ dc.Sql("selectid,pass_wordfrommangerers_table"); }catch(Exceptione){ //TODOAuto-generatedcatchblock e.printStackTrace(); } } if(loginchoice.getSelectedIndex()==1) { try{ dc.Sql("selectid,pass_wordfromdept_table"); }catch(Exceptione){ //TODOAuto-generatedcatchblock e.printStackTrace(); } } if(loginchoice.getSelectedIndex()==2) { try{ dc.Sql("selectid,pass_wordfromcommon_table"); }catch(Exceptione){ //TODOAuto-generatedcatchblock e.printStackTrace(); } } for(inti=0;i 3.主界面类
/**====================================================** *项目名:酒店管理系统 *模块名:系统登录成功后的主窗口 *文件名:HotelMainGui.java *相关文件:HotelLoginGui.javaDataBaseConnect.java *实现功能:系统登录成功后主界面 *函数说明: *[##publicMyHotelMainGui(inti){}]: *功能:构造函数 *[##publicMyHotelMainGui(){}]: *功能:构造函数组建登陆窗口 *[##privatebooleanloginCheck(){}]: *功能:登录验证,仅类内使用 *[##privatevoidquit(){}]: *功能:关闭系统函数,仅类内使用 *[##publicvoidrun(){}] *功能:线程执行刷新界面 *[##publicvoidsetLabelText(JLabeljl,introw)] *功能:为JLabel设置text **===================================================**/ packagecom.HotelGui; importjava.awt.*; importcom.common.DataBaseConnect; importcom.databasejdbc.*; importjavax.swing.*; importjava.text.SimpleDateFormat; importjava.util.*; importjava.awt.event.*; publicclassMyHotelMainGuiextendsJFrameimplementsActionListener,Runnable { publicMyHotelMainGui(inti) { } privatestaticfinalFocusListenerFocusListener=null; Stringroomnum,roomtype; JPopupMenupopupMenu; JMenuBarjmb; JPaneljp1,jp2,room_jp1; JLabeltime_jl,order_jl,login_jl,change_jl,checkout_jl,relogin_jl,money_jl,exit_jl,emploer_jl; JMenujm1,jm2,jm3,jm4,jm5,jm6,jm7,jm8,bt_jm; JButtontime_bt,order_bt,login_bt,change_bt,checkout_bt,relogin_bt,money_bt,exit_bt,emploer_bt,oneF_bt,twoF_bt,threeF_bt,fourF_bt; Vectorroomjb=newVector (); Vector popupVector=newVector (); JLabelstatelabel,state,staticsstate; JButtonjj; JLabelallroom_jl,empty_jl,ordered_jl,isliv_jl,else_jl,allroom_jl1,empty_jl1,ordered_jl1,isliv_jl1,else_jl1; Stringid_now,user_type; /**=======================================================** *获取当前成功登录的ID **========================================================*/ publicStringgetId_now(){ returnid_now; } /**=======================================================** *获取当前成功登录的用户类型 **========================================================*/ publicStringgetUser_type(){ returnuser_type; } /**=======================================================** *设置当前成功登录的ID **========================================================*/ publicvoidsetId_now(Stringid_now){ this.id_now=id_now; } /**=======================================================** *设置当前成功登录的用户类型 **========================================================*/ publicvoidsetUser_type(Stringuser_type){ this.user_type=user_type; } /**====================================================** ***[##publicMyHotelMainGui(){}]构造函数 *参数:无 *返回值:无 *修饰符:public *功能:构造函数,初始化主界面 **===================================================**/ publicMyHotelMainGui() { //为每个房间设置点击事件 for(inti=0;i<32;i++) { finalStringstr; if(i<10) { str="40"+(i+1); } else { str="4"+(i+1); } popupMenu=newJPopupMenu(); popupVector.add(popupMenu); JMenuItemorderMenuItem=newJMenuItem("新预定"); orderMenuItem.setFont(newFont("宋体",Font.ITALIC,14)); popupVector.get(i).add(orderMenuItem); //添加事件 orderMenuItem.addActionListener(newActionListener(){ @Override publicvoidactionPerformed(ActionEvente){ //TODOAuto-generatedmethodstub CheckInck=newCheckIn("预订登记","images\\checkin_bt.jpg"); ck.room_num_jf.setText(str); ck.cancelButton(); //登記入住 ck.checkinButton(1); updateRoomState(); } }); JMenuItemcheckinMenuItem=newJMenuItem("入住登记"); checkinMenuItem.setFont(newFont("宋体",Font.ITALIC,14)); popupVector.get(i).add(checkinMenuItem); checkinMenuItem.addActionListener(newActionListener(){ @Override publicvoidactionPerformed(ActionEvente){ //TODOAuto-generatedmethodstub CheckInck=newCheckIn("入住登记","images\\checkin_bt.jpg"); ck.room_num_jf.setText(str); ck.cancelButton(); //登記入住 ck.checkinButton(2); updateRoomState(); } }); //Separator popupMenu.addSeparator(); JMenuItemchangeMenuItem=newJMenuItem("客人换房"); changeMenuItem.setFont(newFont("宋体",Font.ITALIC,14)); popupVector.get(i).add(changeMenuItem); changeMenuItem.addActionListener(newActionListener(){ @Override publicvoidactionPerformed(ActionEvente){ //TODOAuto-generatedmethodstub ChangeRoomcr=newChangeRoom("客人换房","images\\change_bt.jpg"); cr.check_bt.setVisible(false); cr.jtf.setText(str); try{ cr.check_Bt("房间未入住!"); }catch(Exceptione1){ //TODOAuto-generatedcatchblock e1.printStackTrace(); } } }); JMenuItemmsgMenuItem=newJMenuItem("客人信息"); msgMenuItem.setFont(newFont("宋体",Font.ITALIC,14)); popupVector.get(i).add(msgMenuItem); msgMenuItem.addActionListener(newActionListener(){ @Override publicvoidactionPerformed(ActionEvente){ //TODOAuto-generatedmethodstub CheckMsgcm=newCheckMsg("客人信息","images\\"); cm.check_bt.setVisible(false); cm.jtf.setText(str); try{ cm.check_Bt("房间未入住!"); }catch(Exceptione1){ //TODOAuto-generatedcatchblock e1.printStackTrace(); } } }); JMenuItemreckMenuItem=newJMenuItem("客人续住"); reckMenuItem.setFont(newFont("宋体",Font.ITALIC,14)); popupVector.get(i).add(reckMenuItem); popupMenu.addSeparator(); JMenuItemcheckoutMenuItem=newJMenuItem("客人退房"); checkoutMenuItem.setFont(newFont("宋体",Font.ITALIC,14)); popupVector.get(i).add(checkoutMenuItem); checkoutMenuItem.addActionListener(newActionListener(){ @Override publicvoidactionPerformed(ActionEvente){ //TODOAuto-generatedmethodstub CheckOutco=newCheckOut("客人退房","images\\checkout_bt.jpg"); co.check_bt.setVisible(false); co.jtf.setText(str); try{ co.check_Bt("房间未入住!"); }catch(Exceptione1){ //TODOAuto-generatedcatchblock e1.printStackTrace(); } } }); } oneF_bt=newJButton(newImageIcon("images\\1F.jpg")); oneF_bt.setBounds(20,170,60,50); twoF_bt=newJButton(newImageIcon("images\\2F.jpg")); twoF_bt.setBounds(20,250,60,50); threeF_bt=newJButton(newImageIcon("images\\3F.jpg")); threeF_bt.setBounds(20,330,60,50); fourF_bt=newJButton(newImageIcon("images\\4F.jpg")); fourF_bt.setBounds(20,410,60,50); for(inti=0;i<32;i++) { JButtonjb=newJButton(); roomjb.add(jb); if(i<8) roomjb.get(i).setBounds(90*i,0,90,90); elseif(i<16) roomjb.get(i).setBounds(90*(i-8),90,90,90); elseif(i<24) roomjb.get(i).setBounds(90*(i-16),180,90,90); else roomjb.get(i).setBounds(90*(i-24),270,90,90); roomjb.get(i).setContentAreaFilled(false); roomjb.get(i).setComponentPopupMenu(popupVector.get(i)); } //放置房间的JPanel room_jp1=newJPanel(); room_jp1.setLayout(null); room_jp1.setBounds(120,150,730,367); allroom_jl=newJLabel(newImageIcon("images\\all.jpg")); allroom_jl1=newJLabel(); allroom_jl.setBounds(950,150,75,30); allroom_jl1.setBounds(1110,150,75,30); empty_jl=newJLabel(newImageIcon("images\\empty.jpg")); empty_jl1=newJLabel(); empty_jl.setBounds(950,200,75,30); empty_jl1.setBounds(1110,200,75,30); ordered_jl=newJLabel(newImageIcon("images\\order.jpg")); ordered_jl1=newJLabel(); ordered_jl.setBounds(950,250,75,30); ordered_jl1.setBounds(1110,250,75,30); isliv_jl=newJLabel(newImageIcon("images\\isliv.jpg")); isliv_jl1=newJLabel(); isliv_jl.setBounds(950,300,75,30); isliv_jl1.setBounds(1110,300,75,30); else_jl=newJLabel(newImageIcon("images\\else.jpg")); else_jl1=newJLabel(); else_jl1.setBounds(1110,350,75,30); else_jl.setBounds(950,350,75,30); state=newJLabel("实时房态统计"); state.setFont(newFont("宋体",Font.PLAIN,14)); state.setBounds(1000,90,100,40); staticsstate=newJLabel(); staticsstate.setFont(newFont("宋体",Font.PLAIN,25)); staticsstate.setBounds(970,420,250,60); staticsstate.setForeground(Color.red); jp2=newJPanel(); jp2.setBounds(10,570,950,50);//底部登录状态显示 statelabel=newJLabel(); statelabel.setFont(newFont("宋体",Font.CENTER_BASELINE,12)); jp2.add(statelabel); time_jl=newJLabel("实时房态"); time_jl.setFont(newFont("宋体",Font.LAYOUT_NO_LIMIT_CONTEXT,10)); time_jl.setBounds(10,53,40,10); time_bt=newJButton(newImageIcon("images\\实时房态.jpg")); time_bt.setBounds(10,10,40,40); time_bt.setBorderPainted(false); order_bt=newJButton(newImageIcon("images\\预定登记.jpg")); order_bt.setBounds(65,10,40,40); order_bt.setBorderPainted(false); order_jl=newJLabel("预定登记"); order_jl.setFont(newFont("宋体",Font.LAYOUT_NO_LIMIT_CONTEXT,10)); order_jl.setBounds(65,53,40,10); login_bt=newJButton(newImageIcon("images\\入住登记.jpg")); login_bt.setBounds(120,10,40,40); login_bt.setBorderPainted(false); login_jl=newJLabel("入住登记"); login_jl.setFont(newFont("宋体",Font.LAYOUT_NO_LIMIT_CONTEXT,10)); login_jl.setBounds(120,53,40,10); change_bt=newJButton(newImageIcon("images\\客人换房.jpg")); change_bt.setBounds(175,10,40,40); change_bt.setBorderPainted(false); change_jl=newJLabel("客人换房"); change_jl.setFont(newFont("宋体",Font.LAYOUT_NO_LIMIT_CONTEXT,10)); change_jl.setBounds(175,53,40,10); relogin_bt=newJButton(newImageIcon("images\\客房续住.jpg")); relogin_bt.setBounds(230,10,40,40); relogin_bt.setBorderPainted(false); relogin_jl=newJLabel("客人续住"); relogin_jl.setFont(newFont("宋体",Font.LAYOUT_NO_LIMIT_CONTEXT,10)); relogin_jl.setBounds(230,53,40,10); checkout_jl=newJLabel("客人退房"); checkout_jl.setFont(newFont("宋体",Font.LAYOUT_NO_LIMIT_CONTEXT,10)); checkout_jl.setBounds(285,53,40,10); checkout_bt=newJButton(newImageIcon("images\\客人退房.jpg")); checkout_bt.setBounds(285,10,40,40); checkout_bt.setBorderPainted(false); money_bt=newJButton(newImageIcon("images\\收银报表.jpg")); money_bt.setBounds(340,10,40,40); money_bt.setBorderPainted(false); money_jl=newJLabel("财务报表"); money_jl.setFont(newFont("宋体",Font.LAYOUT_NO_LIMIT_CONTEXT,10)); money_jl.setBounds(340,53,40,10); exit_bt=newJButton(newImageIcon("images\\退出系统.png")); exit_bt.setBounds(450,10,40,40); exit_bt.setBorderPainted(false); exit_jl=newJLabel("退出系统"); exit_jl.setFont(newFont("宋体",Font.LAYOUT_NO_LIMIT_CONTEXT,10)); exit_jl.setBounds(450,53,40,10); emploer_bt=newJButton(newImageIcon("images\\员工管理.jpg")); emploer_bt.setBounds(395,10,40,40); emploer_bt.setBorderPainted(false); emploer_jl=newJLabel("员工管理"); emploer_jl.setFont(newFont("宋体",Font.LAYOUT_NO_LIMIT_CONTEXT,10)); emploer_jl.setBounds(395,53,40,10); jm1=newJMenu("预订接待(A)"); jm1.setFont(newFont("宋体",Font.LAYOUT_NO_LIMIT_CONTEXT,12)); jm2=newJMenu("前台营业(B)"); jm2.setFont(newFont("宋体",Font.LAYOUT_NO_LIMIT_CONTEXT,12)); jm3=newJMenu("客户管理(C)"); jm3.setFont(newFont("宋体",Font.LAYOUT_NO_LIMIT_CONTEXT,12)); jm4=newJMenu("员工管理(D)"); jm4.setFont(newFont("宋体",Font.LAYOUT_NO_LIMIT_CONTEXT,12)); jm5=newJMenu("财务报表(E)"); jm5.setFont(newFont("宋体",Font.LAYOUT_NO_LIMIT_CONTEXT,12)); jm6=newJMenu("综合查询(Z)"); jm6.setFont(newFont("宋体",Font.LAYOUT_NO_LIMIT_CONTEXT,12)); jm7=newJMenu("窗口(P)"); jm7.setFont(newFont("宋体",Font.LAYOUT_NO_LIMIT_CONTEXT,12)); jm8=newJMenu("帮助(H)"); jm8.setFont(newFont("宋体",Font.LAYOUT_NO_LIMIT_CONTEXT,12)); jmb=newJMenuBar(); jmb.add(jm1); jmb.add(jm2); jmb.add(jm3); jmb.add(jm4); jmb.add(jm5); jmb.add(jm6); jmb.add(jm7); jmb.add(jm8); for(inti=0;i<32;i++) { room_jp1.add(roomjb.get(i)); } this.add(oneF_bt); this.add(twoF_bt); this.add(threeF_bt); this.add(fourF_bt); this.add(time_bt); this.add(order_bt); this.add(login_bt); this.add(change_bt); this.add(relogin_bt); this.add(change_bt); this.add(checkout_bt); this.add(money_bt); this.add(exit_bt); this.add(emploer_bt); this.add(time_jl); this.add(order_jl); this.add(login_jl); this.add(change_jl); this.add(relogin_jl); this.add(change_jl); this.add(checkout_jl); this.add(money_jl); this.add(exit_jl); this.add(emploer_jl); this.add(jp2); this.add(state); this.add(allroom_jl); this.add(empty_jl); this.add(isliv_jl); this.add(ordered_jl); this.add(else_jl); this.add(allroom_jl1); this.add(empty_jl1); this.add(isliv_jl1); this.add(ordered_jl1); this.add(else_jl1); this.add(staticsstate); this.setResizable(false); this.setIconImage(newImageIcon("images\\icon.jpg").getImage()); this.setTitle("I酒店管理系统"+"——"+"["+"实时房态"+"]"); this.setFont(newFont("宋体",Font.LAYOUT_NO_LIMIT_CONTEXT,12)); this.setJMenuBar(jmb); this.setLocation(50,50); this.setLayout(null); this.add(room_jp1); this.setSize(Toolkit.getDefaultToolkit().getScreenSize().width-100,Toolkit.getDefaultToolkit().getScreenSize().height-100); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setVisible(true); } @Override publicvoidactionPerformed(ActionEvente){ //TODOAuto-generatedmethodstub } /**====================================================** ***[##publicvoidenevtOpration{}]主窗体上的事件监听 *参数:无 *返回值:无 *修饰符:public *功能:监听用户在主窗体中的操作 **===================================================**/ publicvoidenevtOpration() { order_bt.addMouseListener(newMouseListener(){ @Override publicvoidmouseClicked(MouseEvente){ //TODOAuto-generatedmethodstub CheckInck=newCheckIn("预订登记","images\\checkin_bt.jpg"); ck.cancelButton(); //登記入住 ck.checkinButton(1); updateRoomState(); } @Override publicvoidmousePressed(MouseEvente){ //TODOAuto-generatedmethodstub } @Override publicvoidmouseReleased(MouseEvente){ //TODOAuto-generatedmethodstub } @Override publicvoidmouseEntered(MouseEvente){ //TODOAuto-generatedmethodstub order_bt.setBorderPainted(true); } @Override publicvoidmouseExited(MouseEvente){ //TODOAuto-generatedmethodstub order_bt.setBorderPainted(false); } }); login_bt.addMouseListener(newMouseListener(){ @Override publicvoidmouseClicked(MouseEvente){ //TODOAuto-generatedmethodstub CheckInck=newCheckIn("入住登记","images\\checkin_bt.jpg"); ck.cancelButton(); //登記入住 ck.checkinButton(2); updateRoomState(); } @Override publicvoidmousePressed(MouseEvente){ //TODOAuto-generatedmethodstub } @Override publicvoidmouseReleased(MouseEvente){ //TODOAuto-generatedmethodstub } @Override publicvoidmouseEntered(MouseEvente){ //TODOAuto-generatedmethodstub login_bt.setBorderPainted(true); } @Override publicvoidmouseExited(MouseEvente){ //TODOAuto-generatedmethodstub login_bt.setBorderPainted(false); } }); change_bt.addMouseListener(newMouseListener(){ @Override publicvoidmouseClicked(MouseEvente){ //TODOAuto-generatedmethodstub ChangeRoomcr=newChangeRoom("客人换房","images\\change_bt.jpg"); updateRoomState(); repaint(); } @Override publicvoidmousePressed(MouseEvente){ //TODOAuto-generatedmethodstub } @Override publicvoidmouseReleased(MouseEvente){ //TODOAuto-generatedmethodstub } @Override publicvoidmouseEntered(MouseEvente){ //TODOAuto-generatedmethodstub change_bt.setBorderPainted(true); } @Override publicvoidmouseExited(MouseEvente){ //TODOAuto-generatedmethodstub change_bt.setBorderPainted(false); } }); relogin_bt.addMouseListener(newMouseListener(){ @Override publicvoidmouseClicked(MouseEvente){ //TODOAuto-generatedmethodstub } @Override publicvoidmousePressed(MouseEvente){ //TODOAuto-generatedmethodstub } @Override publicvoidmouseReleased(MouseEvente){ //TODOAuto-generatedmethodstub } @Override publicvoidmouseEntered(MouseEvente){ //TODOAuto-generatedmethodstub relogin_bt.setBorderPainted(true); } @Override publicvoidmouseExited(MouseEvente){ //TODOAuto-generatedmethodstub relogin_bt.setBorderPainted(false); } }); checkout_bt.addMouseListener(newMouseListener(){ @Override publicvoidmouseClicked(MouseEvente){ //TODOAuto-generatedmethodstub CheckOutco=newCheckOut("客人退房","images\\checkout_bt.jpg"); } @Override publicvoidmousePressed(MouseEvente){ //TODOAuto-generatedmethodstub } @Override publicvoidmouseReleased(MouseEvente){ //TODOAuto-generatedmethodstub } @Override publicvoidmouseEntered(MouseEvente){ //TODOAuto-generatedmethodstub checkout_bt.setBorderPainted(true); } @Override publicvoidmouseExited(MouseEvente){ //TODOAuto-generatedmethodstub checkout_bt.setBorderPainted(false); } }); money_bt.addMouseListener(newMouseListener(){ @Override publicvoidmouseClicked(MouseEvente){ //TODOAuto-generatedmethodstub } @Override publicvoidmousePressed(MouseEvente){ //TODOAuto-generatedmethodstub } @Override publicvoidmouseReleased(MouseEvente){ //TODOAuto-generatedmethodstub } @Override publicvoidmouseEntered(MouseEvente){ //TODOAuto-generatedmethodstub money_bt.setBorderPainted(true); } @Override publicvoidmouseExited(MouseEvente){ //TODOAuto-generatedmethodstub money_bt.setBorderPainted(false); } }); emploer_bt.addMouseListener(newMouseListener(){ @Override publicvoidmouseClicked(MouseEvente){ //TODOAuto-generatedmethodstub } @Override publicvoidmousePressed(MouseEvente){ //TODOAuto-generatedmethodstub } @Override publicvoidmouseReleased(MouseEvente){ //TODOAuto-generatedmethodstub } @Override publicvoidmouseEntered(MouseEvente){ //TODOAuto-generatedmethodstub emploer_bt.setBorderPainted(true); } @Override publicvoidmouseExited(MouseEvente){ //TODOAuto-generatedmethodstub emploer_bt.setBorderPainted(false); } }); exit_bt.addMouseListener(newMouseListener(){ @Override publicvoidmouseClicked(MouseEvente){ //TODOAuto-generatedmethodstub quit(); } @Override publicvoidmousePressed(MouseEvente){ //TODOAuto-generatedmethodstub } @Override publicvoidmouseReleased(MouseEvente){ //TODOAuto-generatedmethodstub } @Override publicvoidmouseEntered(MouseEvente){ //TODOAuto-generatedmethodstub exit_bt.setBorderPainted(true); } @Override publicvoidmouseExited(MouseEvente){ //TODOAuto-generatedmethodstub exit_bt.setBorderPainted(false); } }); time_bt.addMouseListener(newMouseListener(){ @Override publicvoidmouseClicked(MouseEvente){ //TODOAuto-generatedmethodstub updateRoomState(); } @Override publicvoidmousePressed(MouseEvente){ //TODOAuto-generatedmethodstub } @Override publicvoidmouseReleased(MouseEvente){ //TODOAuto-generatedmethodstub } @Override publicvoidmouseEntered(MouseEvente){ //TODOAuto-generatedmethodstub time_bt.setBorderPainted(true); } @Override publicvoidmouseExited(MouseEvente){ //TODOAuto-generatedmethodstub time_bt.setBorderPainted(false); } }); } /**====================================================** ***[##publicvoidrun(){}]线程执行,随着系统改变当前时间 *参数:无 *返回值:无 *修饰符:public *功能:使用线程使当前界面时间随着系统改变当 **===================================================**/ publicvoidrun(){ //TODOAuto-generatedmethodstub SimpleDateFormatdf=newSimpleDateFormat("yyyy-MM-ddHH:mm:ss"); while(true) { statelabel.setText("当前时间为:"+df.format(newDate())+""+"当前登录的用户为:"+id_now+""+"用户类型为:"+user_type); statelabel.repaint(); this.repaint(); } } /**====================================================** ***[##privatevoidquit(){}]系统退出 *参数:无 *返回值:无 *修饰符:private *功能:关闭系统函数,仅类内使用 **===================================================**/ privatevoidquit() { intflag=0; Stringmsg="你确定要关闭系统吗?"; flag=JOptionPane.showConfirmDialog(null,msg,"提示",JOptionPane.YES_NO_OPTION); if(flag==JOptionPane.YES_OPTION) { this.setVisible(false); System.exit(0); } return; } /**====================================================** ***[##publicvoidsetLabelText(JLabeljl,introw){}]为JLabel设置text *返回值:无 *修饰符:public *功能:为JLabel设置text **===================================================**/ publicvoidsetLabelText(JLabeljl,introw) { try{ jl.setText(Integer.toString(row)+""+"间"); }catch(Exceptione){} } /**====================================================** ***[##publicvoidupdateRoomState{}]更新入住状态 *返回值:无 *修饰符:public *功能:更新入住统计情况 **=================================================== *@throwsException**/ publicvoidupdateRoomState() { DataBaseConnectns=newDataBaseConnect(); Vector returndata=null; try{ setLabelText(allroom_jl1,ns.getRow("select*fromroom_table")); }catch(Exceptione){ //TODOAuto-generatedcatchblock e.printStackTrace(); } inttol=1; try{ tol=ns.getRow("select*fromroom_table"); }catch(Exceptione){ //TODOAuto-generatedcatchblock e.printStackTrace(); } try{ setLabelText(empty_jl1,ns.getRow("select*fromroom_tablewhereroomatate=0")); }catch(Exceptione){ //TODOAuto-generatedcatchblock e.printStackTrace(); } try{ setLabelText(ordered_jl1,ns.getRow("select*fromroom_tablewhereroomatate=1")); }catch(Exceptione){ //TODOAuto-generatedcatchblock e.printStackTrace(); } try{ setLabelText(isliv_jl1,ns.getRow("select*fromroom_tablewhereroomatate=2")); }catch(Exceptione){ //TODOAuto-generatedcatchblock e.printStackTrace(); } intisl=1; try{ isl=ns.getRow("select*fromroom_tablewhereroomatate=2"); }catch(Exceptione){ //TODOAuto-generatedcatchblock e.printStackTrace(); } try{ setLabelText(else_jl1,ns.getRow("select*fromroom_tablewhereroomatate=3")); }catch(Exceptione){ //TODOAuto-generatedcatchblock e.printStackTrace(); } try{ staticsstate.setText("入住率:"+""+(int)(isl*100/tol)+"%"); returndata=ns.RoomOperation(); }catch(Exceptione){ //TODOAuto-generatedcatchblock e.printStackTrace(); } for(inti=0;i "+returndata.get(0).get(i)+"
"+returndata.get(1).get(i)+"