温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

java实现酒店管理系统

发布时间:2020-08-22 23:31:42 来源:脚本之家 阅读:212 作者:ccp5626 栏目:编程语言

本文实例为大家分享了java实现酒店管理系统的具体代码,供大家参考,具体内容如下

编写环境:MyEclipse2014+sql server2014

系统功能:

1.登录验证
2.房态统计显示
3.预定登记并入库
4.入住登记并入库
5.换房登记并入库
6.客人信息查询
7.退房并入库

运行界面如下:

=====登录界面======
=====主界面=====
=====为每个房间设置弹出菜单======
=====登记界面======

=====换房界面=====
=====退房界面=====

界面之间相关关系:

主界面主要由菜单条,按钮,标签等组成,一个JButton是一个房间,其Test从数据库中获取,颜色由房态决定。
登记-换房-查看信息-退房等界面皆继承一个父类而来,简单快捷。

主要代码目录:

1.数据库操作类

 /**====================================================**
 * 项目名 :酒店管理系统
 * 模块名 :数据库连接
 * 文件名 :DataBaseConnct.java
 * 相关文件 :
 * 实现功能 :jdbc连接数据库
 * 函数说明 :
 * [## public Vector getId(){}]:
 * 功能:获取数据库中系统登录ID
 * 
 * [## public void setId() {}]:
 * 功能:设置数据库中系统登录ID
 * 
 * [## public Vector getPassword(){}]:
 * 功能:获取数据库中系统登录密码
 * 
 * [## public void setPassword(){}]:
 * 功能:设置数据库中系统登录密码
 * 
 * [## public Vector getRoonnum(){}]:
 * 功能:获取数据库中房间号
 * 
 * [## public void setRoonnum() {}]:
 * 功能:设置数据库中房间号
 * 
 * [## public Vector getRoomtype(){}]:
 * 功能:获取数据库中房间类型
 * 
 * [## public void seRoomtype(){}]:
 * 功能:设置数据库中房间类型
 * 
 * [## public void Sql(String sql){}]:
 * 功能:执行sql语句进行查询
 * 
 **===================================================**/
package com.common;
import java.sql.*;
import java.util.Vector;
 
import javax.swing.JOptionPane;
import javax.xml.crypto.dsig.keyinfo.RetrievalMethod;
public class DataBaseConnect {
 private String driverName="com.microsoft.sqlserver.jdbc.SQLServerDriver";
 private String dbURL="jdbc:sqlserver://localhost:1433;DatabaseName=hotel_mangerment_system";
 private String userName="sa";
 private String userPwd="1451171";
 private Connection ct=null;
 private ResultSet rs=null;
 private Statement st;
 private Vector id =new Vector();
 private Vector password =new Vector();
 
 /**====================================================**
 * 获取数据库中系统登录ID
 **===================================================**/
 public Vector getId() {
 return id;
 }
 /**====================================================**
 * 设置数据库中系统登录ID
 **===================================================**/
 public void setId(Vector id) {
 this.id = id;
 }
 /**====================================================**
 * 获取数据库中系统登录密码
 **===================================================**/
 public Vector getPassword() {
 return password;
 }
 /**====================================================**
 * 设置数据库中系统登录ID
 **===================================================**/
 public void setPassword(Vector password) {
 this.password = password;
 }
 
 /**====================================================**
 * [## public void Sql(String sql) {}] 
 * 参数 :String sql
 * 返回值 :无
 * 修饰符 :public
 * 功能 :创建sql查询,从数据库里查询登陆账号与密码
 **===================================================**/
 public void Sql(String sql) throws Exception
 {
 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();
 }
 /**====================================================**
 * [## public Vector RoomOperation(int room_num) {}] 查询房间信息 
 * 参数 :int room_num
 * 返回值 :无
 * 修饰符 :public
 * 功能 :创建sql查询房间号与类型,类外可使用
 **===================================================**/
 public Vector RoomOperation(int room_num)throws Exception
 {
 Vector<Object> data=new Vector<Object>();
 Class.forName(driverName);
 ct=DriverManager.getConnection(dbURL,userName,userPwd);
 st=ct.createStatement();
 rs=st.executeQuery("select * from room_table where roomnum="+room_num);
 while(rs.next())
 {
 data.add(rs.getInt(1));
 data.add(rs.getString(2));
 data.add(rs.getInt(3));
 data.add(rs.getInt(4));
 }
 if(rs!=null)
 rs.close();
 if(st!=null)
 st.close();
 if(ct!=null)
 ct.close();
 return data;
 }
 /**====================================================**
 * [## public void RoomOperation(String sql) {}] 查询房间使用状态
 * 参数 :String sql
 * 返回值 :房间个数
 * 修饰符 :public
 * 功能 :创建sql查询满足条件房间使用状态,类外可使用
 **===================================================**/
 public int getRow(String sql)throws Exception
 {
 Class.forName(driverName);
 ct=DriverManager.getConnection(dbURL,userName,userPwd);
 int rowcount=0;
 st=ct.createStatement();
 rs=st.executeQuery(sql);
 while(rs.next())
 {
 rowcount++;
 }
 if(rs!=null)
 rs.close();
 if(st!=null)
 st.close();
 if(ct!=null)
 ct.close();
 return rowcount;
 }
 
 /**====================================================**
 * [## public void insertData(){}] 插入记录
 * 参数 :String table_name,String str
 * 返回值 :无
 * 修饰符 :public
 * 功能 :向数据库中插入记录
 **===================================================
 * @throws Exception **/
 public void insertData(String table_name,String str) throws Exception
 {
 Class.forName(driverName);
 ct=DriverManager.getConnection(dbURL,userName,userPwd);
 ct.setAutoCommit(false);
 st=ct.createStatement();
 String sql="insert into"+" "+table_name+" "+"values"+"("+str+")";
 st.executeUpdate(sql);
 ct.commit();
 if(st!=null)
 st.close();
 if(ct!=null)
 ct.close();
 
 } 
 /**====================================================**
 * [## public void updateData(String str){}] 更新记录
 * 参数 :String sql
 * 返回值 :无
 * 修饰符 :public
 * 功能 :向数据库中更新记录
 **===================================================*/
 public void updateData(String sql) throws Exception
 {
 Class.forName(driverName);
 ct=DriverManager.getConnection(dbURL,userName,userPwd);
 ct.setAutoCommit(false);
 st=ct.createStatement();
 st.executeUpdate(sql);
 ct.commit();
 if(st!=null)
 st.close();
 if(ct!=null)
 ct.close();
 }
 /**====================================================**
 * [## public void getDataFromCostomer(){}] 从Costomer_table中获取数据
 * 参数 :int room_num
 * 返回值 :Vector<object> data
 * 修饰符 :public
 * 功能 :根据房间号从Costomer_table中获取数据并返回
 **===================================================*/
 public Vector getDataFromCostomer(int room_num) throws Exception
 {
 Vector<Object> data=new Vector<Object>();
 Class.forName(driverName);
 ct=DriverManager.getConnection(dbURL,userName,userPwd);
 ct.setAutoCommit(false);
 st=ct.createStatement();
 rs=st.executeQuery("select * from costomer_table where roomnum="+room_num+"and isliving=1");
 while(rs.next())
 {
 data.add(rs.getInt(1));
 data.add(rs.getString(2));
 data.add(rs.getString(3));
 data.add(rs.getString(4));
 data.add(rs.getString(5));
 data.add(rs.getString(6));
 data.add(rs.getInt(7));
 data.add(rs.getInt(8));
 data.add(rs.getInt(9));
 }
 if(rs!=null)
 rs.close();
 if(st!=null)
 st.close();
 if(ct!=null)
 ct.close();
 return data;
 }
 
 /**====================================================**
 * [## public Vector RoomOperation(int room_num) {}] 查询房间信息 
 * 参数 :无
 * 返回值 :return returedata;
 * 修饰符 :public
 * 功能 :创建sql查询房间号与类型,与入住状态并返回,类外可使用
 **===================================================**/
 public Vector RoomOperation()throws Exception
 {
 Vector<Vector> returedata=new Vector<Vector>();
 Vector<Object> roomnum=new Vector<Object>();
 Vector<Object> roomtype=new Vector<Object>();
 Vector<Integer> roomstate=new Vector<Integer>();
 Class.forName(driverName);
 ct=DriverManager.getConnection(dbURL,userName,userPwd);
 st=ct.createStatement();
 rs=st.executeQuery("select roomnum,roomtype,roomatate from room_table");
 while(rs.next())
 {
 roomnum.add(rs.getInt(1));
 roomtype.add(rs.getString(2));
 roomstate.add(rs.getInt(3));
 }
 if(rs!=null)
 rs.close();
 if(st!=null)
 st.close();
 if(ct!=null)
 ct.close();
 returedata.add(roomnum);
 returedata.add(roomtype);
 returedata.add(roomstate);
 return returedata;
 }
}

2.登录界面类

 /**====================================================**
 * 项目名 :酒店管理系统
 * 模块名 :系统登录窗口
 * 文件名 :HotelLoginGui.java
 * 相关文件 :DataBaseConnct.java HotelMainGui.java
 * 实现功能 :系统登录界面
 * 函数说明 :
 * [## public MyJframe(){}]:
 * 功能:构造函数 组建登录窗口
 * [## public void enevtOperation(final MyLoginJframe mj){}]
 * 功能:登录界面的事件监听处理
 * [## private boolean loginCheck() {}]:
 * 功能:登录验证,仅类内使用
 * [## private void quit() {}]:
 * 功能:关闭系统函数,仅类内使用
 **===================================================**/
package com.HotelGui;
import com.common.*;//引入包
 
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
 
import javax.jws.soap.SOAPBinding.Style;
import javax.swing.*;
 
import java.net.*;
import java.util.*;
public class HotelLoginGui {
 public static void main(String[] args) {
 // TODO Auto-generated method stub
 MyLoginJframe logingui=new MyLoginJframe();
 logingui.enevtOperation(logingui);
}
}
//登录界面MyJframe
class MyLoginJframe extends JFrame implements ActionListener
{
 DataBaseConnect dc;
 JPasswordField passwordnum;
 JTextField accountnum;
 JLabel password,account,login,backimg,backimg1;
 JLabel tiplabel;
 JComboBox<String> loginchoice;
 JButton loginbutton,resetbutton,exitbutton;
 JPanel jp,jp0,jp1,jp2,jp3,jp4,jp5;
 Vector<String> dept=new Vector<String>();
 private String id_now,user_type;
 /**=======================================================**
 * 设置当前成功登录的ID
 **========================================================*/
 public void setId_now(String id_now) {
 this.id_now = id_now;
 }
 
 /**=======================================================**
 * 获得当前成功登录的ID
 **========================================================*/
 public String getId_now() {
 return id_now;
 }
 /**====================================================**
 * **[## public MyJframe() {}] 组建登录窗口
 * 参数 :无
 * 返回值 :无
 * 修饰符 :public
 * 功能 :组建登录窗口
 **===================================================**/
 
 public MyLoginJframe()
 { dc=new DataBaseConnect();//连接数据库实例
 jp=new JPanel();
 
 jp.setBounds(0, -5,550, 200);
 jp0=new JPanel();
 jp0.setBounds(0,180,250,250);
 jp1=new JPanel();
 jp1.setBounds(270, 215, 250, 30);
 jp2=new JPanel();
 jp2.setBounds(270, 250, 250, 30);
 jp3=new JPanel();
 jp3.setBounds(270, 280, 250, 30);
 jp4=new JPanel();
 jp4.setBounds(270, 335, 250, 40);
 jp5=new JPanel();
 jp5.setBounds(270, 380, 250, 30);
 dept.add("经理");
 dept.add("部门主管");
 dept.add("普通员工");
 account=new JLabel("账 户");
 password=new JLabel("密 码");
 login=new JLabel("用 户 ");
 backimg=new JLabel(new ImageIcon("images\\back.jpg"));
 backimg1=new JLabel(new ImageIcon("images\\back1.jpg"));
 tiplabel=new JLabel();
 tiplabel.setFont(new Font("宋体", Font.PLAIN, 12));
 tiplabel.setForeground(Color.red);
 tiplabel.setVisible(false);
 passwordnum=new JPasswordField(12);
 accountnum=new JTextField(12);
 loginbutton=new JButton("登 录");
 loginbutton.setOpaque(false);
 loginbutton.setContentAreaFilled(false);
 
 resetbutton=new JButton("重 置");
 resetbutton.setOpaque(false);
 resetbutton.setContentAreaFilled(false);
 
 exitbutton =new JButton("退 出");
 exitbutton.setOpaque(false);
 exitbutton.setContentAreaFilled(false);
 
 loginchoice =new JComboBox(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(new ImageIcon("images\\icon.jpg").getImage());
 this.setVisible(true);
 
 }
 /**====================================================**
 * **[## private void enevtOperation() {}] 事件处理
 * 参数 :无
 * 返回值 :无
 * 修饰符 :public
 * 功能 :登录窗口的事件操作
 **===================================================**/
 public void enevtOperation(final MyLoginJframe mj)
 {
 /**=======================================================**
 * 登录按钮监听事件
 **========================================================*/
 loginbutton.addActionListener(new ActionListener() {
 
 @Override
 public void actionPerformed(ActionEvent e) {
 // TODO Auto-generated method stub 
 if(loginCheck())
 {
 tiplabel.setText("正 在 登 录...");
 //记录当前的操作记录
 id_now=accountnum.getText();
 user_type=loginchoice.getSelectedItem().toString();
 MyHotelMainGui mm=new MyHotelMainGui(); //登录到主界面
 mj.dispose();
 //显示当前的操作人员信息
 mm.setId_now(id_now);
 mm.setUser_type(user_type);
 mm.enevtOpration();
 mm.updateRoomState();
 Thread th=new Thread(mm);
 th.start();
 
 }
 else if(accountnum.getText().isEmpty() && passwordnum.getPassword().length==0)
 tiplabel.setText("密码与账号不能为空!");
 else if(accountnum.getText().isEmpty() && passwordnum.getPassword().length!=0)
 tiplabel.setText("请输入账号...");
 else if(accountnum.getText().isEmpty()==false && passwordnum.getPassword().length==0)
 tiplabel.setText("请输入密码...");
 else
 tiplabel.setText("请检查后重新输入!");
 
 tiplabel.setVisible(true);
 }
 });
 /**=======================================================**
 * 重置按钮监听事件
 **========================================================*/
 resetbutton.addActionListener(new ActionListener() {
 
 @Override
 public void actionPerformed(ActionEvent e) {
 // TODO Auto-generated method stub
 accountnum.setText("");
 passwordnum.setText("");
 loginchoice.setSelectedIndex(0);
 }
 
 });
 /**=======================================================**
 * 退出按钮监听事件
 **========================================================*/
 exitbutton.addActionListener(new ActionListener() {
 
 @Override
 public void actionPerformed(ActionEvent e) {
 // TODO Auto-generated method stub
 quit();
 
 }
 });
 }
 
 /**====================================================**
 * **[## private boolean loginCheck() {}] 登陆验证
 * 参数 :无
 * 返回值 :flag
 * 修饰符 :private
 * 功能 :登录验证,仅类内使用
 **===================================================**/
 public boolean loginCheck()
 {
 boolean flag=false;
 if(loginchoice.getSelectedIndex()==0)
 {
 try {
 dc.Sql("select id,pass_word from mangerers_table");
 } catch (Exception e) {
 // TODO Auto-generated catch block
 e.printStackTrace();
 }
 }
 if(loginchoice.getSelectedIndex()==1)
 {
 try {
 dc.Sql("select id,pass_word from dept_table");
 } catch (Exception e) {
 // TODO Auto-generated catch block
 e.printStackTrace();
 }
 }
 if(loginchoice.getSelectedIndex()==2)
 {
 try {
 dc.Sql("select id,pass_word from common_table");
 } catch (Exception e) {
 // TODO Auto-generated catch block
 e.printStackTrace();
 }
 }
 for(int i=0;i<dc.getId().size();i++)
 {
 String password=new String(passwordnum.getPassword());
 if(accountnum.getText().equals(dc.getId().get(i).toString()) && password.equals(dc.getPassword().get(i).toString()))
 {
 flag=true;
 break;
 }
 
 }
 return flag;
 }
 /**====================================================**
 * **[## private void quit() {}] 系统退出
 * 参数 :无
 * 返回值 :无
 * 修饰符 :private
 * 功能 :关闭系统函数,仅类内使用
 **===================================================**/
 private void quit()
 {
 int flag=0;
 String msg="你 确 定 要 关 闭 系 统 吗?";
 flag=JOptionPane.showConfirmDialog(null, msg,"提示",JOptionPane.YES_NO_OPTION);
 if(flag==JOptionPane.YES_OPTION)
 {
 this.setVisible(false);
 System.exit(0);
 }
 return;
 }
 
 @Override
 public void actionPerformed(ActionEvent e) {
 // TODO Auto-generated method stub
 
 }
}

3.主界面类

 /**====================================================**
 * 项目名 :酒店管理系统
 * 模块名 :系统登录成功后的主窗口
 * 文件名 :HotelMainGui.java
 * 相关文件 :HotelLoginGui.java DataBaseConnect.java
 * 实现功能 :系统登录成功后主界面
 * 函数说明 :
 * [## public MyHotelMainGui(int i){}]:
 * 功能:构造函数 
 * [## public MyHotelMainGui(){}]:
 * 功能:构造函数 组建登陆窗口
 * [## private boolean loginCheck() {}]:
 * 功能:登录验证,仅类内使用
 * [## private void quit() {}]:
 * 功能:关闭系统函数,仅类内使用
 * [## public void run(){}]
 * 功能:线程执行刷新界面
 * [## public void setLabelText(JLabel jl,int row)]
 * 功能:为JLabel设置text
 **===================================================**/
package com.HotelGui;
import java.awt.*;
 
import com.common.DataBaseConnect;
import com.databasejdbc.*;
 
import javax.swing.*;
 
import java.text.SimpleDateFormat;
import java.util.*;
import java.awt.event.*;
public class MyHotelMainGui extends JFrame implements ActionListener,Runnable
{
 public MyHotelMainGui(int i)
 {
 
 } 
 private static final FocusListener FocusListener = null;
 String roomnum,roomtype;
 JPopupMenu popupMenu;
 JMenuBar jmb;
 JPanel jp1,jp2,room_jp1;
 JLabel time_jl,order_jl,login_jl,change_jl,checkout_jl,relogin_jl,money_jl,exit_jl,emploer_jl;
 JMenu jm1,jm2,jm3,jm4,jm5,jm6,jm7,jm8,bt_jm;
 JButton time_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;
 Vector<JButton> roomjb=new Vector<JButton>();
 Vector<JPopupMenu> popupVector=new Vector<JPopupMenu>();
 JLabel statelabel,state,staticsstate;
 JButton jj;
 JLabel allroom_jl,empty_jl,ordered_jl,isliv_jl,else_jl,allroom_jl1,empty_jl1,ordered_jl1,isliv_jl1,else_jl1;
 String id_now,user_type;
 /**=======================================================**
 * 获取当前成功登录的ID
 **========================================================*/
 public String getId_now() {
 return id_now;
 }
 /**=======================================================**
 * 获取当前成功登录的用户类型
 **========================================================*/
 public String getUser_type() {
 return user_type;
 }
 /**=======================================================**
 * 设置当前成功登录的ID
 **========================================================*/
 public void setId_now(String id_now) {
 this.id_now = id_now;
 }
 /**=======================================================**
 * 设置当前成功登录的用户类型
 **========================================================*/
 public void setUser_type(String user_type) {
 this.user_type = user_type;
 }
 /**====================================================**
 * **[## public MyHotelMainGui() {}] 构造函数
 * 参数 :无
 * 返回值 :无
 * 修饰符 :public
 * 功能 :构造函数,初始化主界面
 **===================================================**/
 public MyHotelMainGui()
 {
 //为每个房间设置点击事件
 
 for( int i=0;i<32;i++)
 {
 final String str;
 if(i<10)
 {
 str="40"+(i+1);
 }
 else
 {
 str="4"+(i+1);
 }
 popupMenu = new JPopupMenu ();
 popupVector.add(popupMenu);
 JMenuItem orderMenuItem = new JMenuItem ("新预定") ;
 orderMenuItem.setFont(new Font("宋体",Font.ITALIC,14));
 popupVector.get(i).add ( orderMenuItem ) ;
 //添加事件
 orderMenuItem.addActionListener(new ActionListener() {
 
 @Override
 public void actionPerformed(ActionEvent e) {
 // TODO Auto-generated method stub
 CheckIn ck=new CheckIn("预订登记","images\\checkin_bt.jpg");
 ck.room_num_jf.setText(str);
 ck.cancelButton();
 //登記入住
 ck.checkinButton(1);
 updateRoomState();
 }
 });
 JMenuItem checkinMenuItem = new JMenuItem ("入住登记") ;
 checkinMenuItem.setFont(new Font("宋体",Font.ITALIC,14));
 popupVector.get(i).add ( checkinMenuItem ) ;
 checkinMenuItem.addActionListener(new ActionListener() {
 
 @Override
 public void actionPerformed(ActionEvent e) {
 // TODO Auto-generated method stub
 CheckIn ck=new CheckIn("入住登记","images\\checkin_bt.jpg");
 ck.room_num_jf.setText(str);
 ck.cancelButton();
 //登記入住
 ck.checkinButton(2);
 updateRoomState();
 }
 });
 
 
 // Separator
 popupMenu.addSeparator () ;
 JMenuItem changeMenuItem = new JMenuItem ("客人换房") ;
 changeMenuItem.setFont(new Font("宋体",Font.ITALIC,14));
 popupVector.get(i).add ( changeMenuItem ) ;
 changeMenuItem.addActionListener(new ActionListener() {
 
 @Override
 public void actionPerformed(ActionEvent e) {
 // TODO Auto-generated method stub
 ChangeRoom cr=new ChangeRoom("客人换房","images\\change_bt.jpg");
 cr.check_bt.setVisible(false);
 cr.jtf.setText(str);
 try {
 cr.check_Bt("房间未入住!");
 } catch (Exception e1) {
 // TODO Auto-generated catch block
 e1.printStackTrace();
 }
 
 
 }
 });
 JMenuItem msgMenuItem = new JMenuItem ("客人信息") ;
 msgMenuItem.setFont(new Font("宋体",Font.ITALIC,14));
 popupVector.get(i).add ( msgMenuItem ) ;
 msgMenuItem.addActionListener(new ActionListener() {
 
 @Override
 public void actionPerformed(ActionEvent e) {
 // TODO Auto-generated method stub
 CheckMsg cm=new CheckMsg("客人信息","images\\");
 cm.check_bt.setVisible(false);
 cm.jtf.setText(str); 
 try {
 cm.check_Bt("房间未入住!");
 } catch (Exception e1) {
 // TODO Auto-generated catch block
 e1.printStackTrace();
 }
 }
 });
 JMenuItem reckMenuItem = new JMenuItem ("客人续住") ;
 reckMenuItem.setFont(new Font("宋体",Font.ITALIC,14));
 popupVector.get(i).add ( reckMenuItem ) ;
 popupMenu.addSeparator () ;
 JMenuItem checkoutMenuItem = new JMenuItem ("客人退房") ;
 checkoutMenuItem.setFont(new Font("宋体",Font.ITALIC,14));
 popupVector.get(i).add ( checkoutMenuItem ) ;
 checkoutMenuItem.addActionListener(new ActionListener() {
 
 @Override
 public void actionPerformed(ActionEvent e) {
 // TODO Auto-generated method stub
 CheckOut co=new CheckOut("客人退房","images\\checkout_bt.jpg");
 co.check_bt.setVisible(false);
 co.jtf.setText(str); 
 try {
 co.check_Bt("房间未入住!");
 } catch (Exception e1) {
 // TODO Auto-generated catch block
 e1.printStackTrace();
 }
 }
 });
 }
 oneF_bt=new JButton(new ImageIcon("images\\1F.jpg"));
 oneF_bt.setBounds(20, 170, 60,50);
 twoF_bt=new JButton(new ImageIcon("images\\2F.jpg"));
 twoF_bt.setBounds(20, 250, 60,50);
 threeF_bt=new JButton(new ImageIcon("images\\3F.jpg"));
 threeF_bt.setBounds(20, 330, 60,50);
 fourF_bt=new JButton(new ImageIcon("images\\4F.jpg"));
 fourF_bt.setBounds(20, 410, 60,50);
 for(int i=0;i<32;i++)
 {
 JButton jb=new JButton();
 roomjb.add(jb);
 if(i<8)
 roomjb.get(i).setBounds(90*i, 0, 90, 90);
 else if(i<16)
 roomjb.get(i).setBounds(90*(i-8), 90, 90, 90);
 else if(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=new JPanel();
 room_jp1.setLayout(null);
 room_jp1.setBounds(120, 150, 730, 367);
 
 allroom_jl=new JLabel(new ImageIcon("images\\all.jpg"));
 allroom_jl1=new JLabel();
 allroom_jl.setBounds(950, 150, 75, 30);
 allroom_jl1.setBounds(1110, 150, 75, 30);
 empty_jl=new JLabel(new ImageIcon("images\\empty.jpg"));
 empty_jl1=new JLabel();
 empty_jl.setBounds(950, 200, 75, 30);
 empty_jl1.setBounds(1110, 200, 75, 30);
 ordered_jl=new JLabel(new ImageIcon("images\\order.jpg"));
 ordered_jl1=new JLabel();
 ordered_jl.setBounds(950, 250, 75, 30);
 ordered_jl1.setBounds(1110, 250, 75, 30);
 isliv_jl=new JLabel(new ImageIcon("images\\isliv.jpg"));
 isliv_jl1=new JLabel();
 isliv_jl.setBounds(950, 300, 75, 30);
 isliv_jl1.setBounds(1110, 300, 75, 30);
 else_jl=new JLabel(new ImageIcon("images\\else.jpg"));
 else_jl1=new JLabel();
 else_jl1.setBounds(1110, 350, 75, 30);
 else_jl.setBounds(950, 350, 75, 30);
 state=new JLabel("实时房态统计");
 state.setFont(new Font("宋体",Font.PLAIN,14));
 state.setBounds(1000, 90, 100, 40);
 staticsstate=new JLabel();
 staticsstate.setFont(new Font("宋体",Font.PLAIN,25));
 staticsstate.setBounds(970, 420, 250, 60);
 staticsstate.setForeground(Color.red);
 
 jp2=new JPanel();
 jp2.setBounds(10, 570, 950, 50);//底部登录状态显示
 
 statelabel=new JLabel();
 statelabel.setFont(new Font("宋体",Font.CENTER_BASELINE,12));
 jp2.add(statelabel);
 
 time_jl=new JLabel("实时房态");
 time_jl.setFont(new Font("宋体",Font.LAYOUT_NO_LIMIT_CONTEXT,10));
 time_jl.setBounds(10, 53, 40, 10);
 time_bt=new JButton(new ImageIcon("images\\实时房态.jpg"));
 time_bt.setBounds(10, 10, 40, 40);
 time_bt.setBorderPainted(false);
 
 order_bt=new JButton(new ImageIcon("images\\预定登记.jpg"));
 order_bt.setBounds(65, 10, 40, 40);
 order_bt.setBorderPainted(false);
 
 order_jl=new JLabel("预定登记");
 order_jl.setFont(new Font("宋体",Font.LAYOUT_NO_LIMIT_CONTEXT,10));
 order_jl.setBounds(65, 53, 40, 10);
 
 login_bt=new JButton(new ImageIcon("images\\入住登记.jpg"));
 login_bt.setBounds(120, 10, 40, 40);
 login_bt.setBorderPainted(false);
 
 login_jl=new JLabel("入住登记");
 login_jl.setFont(new Font("宋体",Font.LAYOUT_NO_LIMIT_CONTEXT,10));
 login_jl.setBounds(120, 53, 40, 10);
 
 change_bt=new JButton(new ImageIcon("images\\客人换房.jpg"));
 change_bt.setBounds(175, 10, 40, 40);
 change_bt.setBorderPainted(false);
 
 change_jl=new JLabel("客人换房");
 change_jl.setFont(new Font("宋体",Font.LAYOUT_NO_LIMIT_CONTEXT,10));
 change_jl.setBounds(175, 53, 40, 10);
 
 relogin_bt=new JButton(new ImageIcon("images\\客房续住.jpg"));
 relogin_bt.setBounds(230, 10, 40, 40);
 relogin_bt.setBorderPainted(false);
 
 relogin_jl=new JLabel("客人续住");
 relogin_jl.setFont(new Font("宋体",Font.LAYOUT_NO_LIMIT_CONTEXT,10));
 relogin_jl.setBounds(230, 53, 40, 10);
 
 checkout_jl=new JLabel("客人退房");
 checkout_jl.setFont(new Font("宋体",Font.LAYOUT_NO_LIMIT_CONTEXT,10));
 checkout_jl.setBounds(285, 53, 40, 10);
 checkout_bt=new JButton(new ImageIcon("images\\客人退房.jpg"));
 checkout_bt.setBounds(285, 10, 40, 40);
 checkout_bt.setBorderPainted(false);
 
 
 money_bt=new JButton(new ImageIcon("images\\收银报表.jpg"));
 money_bt.setBounds(340, 10, 40, 40);
 money_bt.setBorderPainted(false);
 
 money_jl=new JLabel("财务报表");
 money_jl.setFont(new Font("宋体",Font.LAYOUT_NO_LIMIT_CONTEXT,10));
 money_jl.setBounds(340, 53, 40, 10);
 
 exit_bt=new JButton(new ImageIcon("images\\退出系统.png"));
 exit_bt.setBounds(450, 10, 40, 40);
 exit_bt.setBorderPainted(false);
 
 exit_jl=new JLabel("退出系统");
 exit_jl.setFont(new Font("宋体",Font.LAYOUT_NO_LIMIT_CONTEXT,10));
 exit_jl.setBounds(450, 53, 40, 10);
 
 emploer_bt=new JButton(new ImageIcon("images\\员工管理.jpg"));
 emploer_bt.setBounds(395, 10, 40, 40);
 emploer_bt.setBorderPainted(false);
 
 emploer_jl=new JLabel("员工管理");
 emploer_jl.setFont(new Font("宋体",Font.LAYOUT_NO_LIMIT_CONTEXT,10));
 emploer_jl.setBounds(395, 53, 40, 10);
 
 jm1=new JMenu("预订接待(A)");
 jm1.setFont(new Font("宋体",Font.LAYOUT_NO_LIMIT_CONTEXT,12));
 jm2=new JMenu("前台营业(B)");
 jm2.setFont(new Font("宋体",Font.LAYOUT_NO_LIMIT_CONTEXT,12));
 jm3=new JMenu("客户管理(C)");
 jm3.setFont(new Font("宋体",Font.LAYOUT_NO_LIMIT_CONTEXT,12));
 jm4=new JMenu("员工管理(D)");
 jm4.setFont(new Font("宋体",Font.LAYOUT_NO_LIMIT_CONTEXT,12));
 jm5=new JMenu("财务报表(E)");
 jm5.setFont(new Font("宋体",Font.LAYOUT_NO_LIMIT_CONTEXT,12));
 jm6=new JMenu("综合查询(Z)");
 jm6.setFont(new Font("宋体",Font.LAYOUT_NO_LIMIT_CONTEXT,12));
 jm7=new JMenu("窗口(P)");
 jm7.setFont(new Font("宋体",Font.LAYOUT_NO_LIMIT_CONTEXT,12));
 jm8=new JMenu("帮助(H)");
 jm8.setFont(new Font("宋体",Font.LAYOUT_NO_LIMIT_CONTEXT,12));
 
 jmb=new JMenuBar();
 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(int i=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(new ImageIcon("images\\icon.jpg").getImage());
 this.setTitle("I酒店管理系统"+"——"+"["+"实时房态"+"]");
 this.setFont(new Font("宋体",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
 public void actionPerformed(ActionEvent e) {
 // TODO Auto-generated method stub
 
 }
 /**====================================================**
 * **[## public void enevtOpration {}] 主窗体上的事件监听
 * 参数 :无
 * 返回值 :无
 * 修饰符 :public
 * 功能 :监听用户在主窗体中的操作
 **===================================================**/
 public void enevtOpration()
 {
 order_bt.addMouseListener(new MouseListener() {
 
 
 @Override
 public void mouseClicked(MouseEvent e) {
 // TODO Auto-generated method stub
 CheckIn ck=new CheckIn("预订登记","images\\checkin_bt.jpg");
 ck.cancelButton();
 //登記入住
 ck.checkinButton(1);
 updateRoomState();
 }
 
 @Override
 public void mousePressed(MouseEvent e) {
 // TODO Auto-generated method stub
 
 }
 
 @Override
 public void mouseReleased(MouseEvent e) {
 // TODO Auto-generated method stub
 
 }
 
 @Override
 public void mouseEntered(MouseEvent e) {
 // TODO Auto-generated method stub
 order_bt.setBorderPainted(true);
 }
 
 @Override
 public void mouseExited(MouseEvent e) {
 // TODO Auto-generated method stub
 order_bt.setBorderPainted(false);
 }
 });
 login_bt.addMouseListener(new MouseListener() {
 
 
 @Override
 public void mouseClicked(MouseEvent e) {
 // TODO Auto-generated method stub
 CheckIn ck=new CheckIn("入住登记","images\\checkin_bt.jpg");
 ck.cancelButton();
 //登記入住
 ck.checkinButton(2);
 updateRoomState();
 }
 
 @Override
 public void mousePressed(MouseEvent e) {
 // TODO Auto-generated method stub
 
 }
 
 @Override
 public void mouseReleased(MouseEvent e) {
 // TODO Auto-generated method stub
 
 }
 
 @Override
 public void mouseEntered(MouseEvent e) {
 // TODO Auto-generated method stub
 login_bt.setBorderPainted(true);
 }
 
 @Override
 public void mouseExited(MouseEvent e) {
 // TODO Auto-generated method stub
 login_bt.setBorderPainted(false);
 }
 });
 change_bt.addMouseListener(new MouseListener() {
 
 
 @Override
 public void mouseClicked(MouseEvent e) {
 // TODO Auto-generated method stub
 ChangeRoom cr=new ChangeRoom("客人换房", "images\\change_bt.jpg");
 updateRoomState();
 repaint();
 
 }
 
 @Override
 public void mousePressed(MouseEvent e) {
 // TODO Auto-generated method stub
 
 }
 
 @Override
 public void mouseReleased(MouseEvent e) {
 // TODO Auto-generated method stub
 
 }
 
 @Override
 public void mouseEntered(MouseEvent e) {
 // TODO Auto-generated method stub
 change_bt.setBorderPainted(true);
 }
 
 @Override
 public void mouseExited(MouseEvent e) {
 // TODO Auto-generated method stub
 change_bt.setBorderPainted(false);
 }
 });
 relogin_bt.addMouseListener(new MouseListener() {
 
 
 @Override
 public void mouseClicked(MouseEvent e) {
 // TODO Auto-generated method stub
 
 }
 
 @Override
 public void mousePressed(MouseEvent e) {
 // TODO Auto-generated method stub
 
 }
 
 @Override
 public void mouseReleased(MouseEvent e) {
 // TODO Auto-generated method stub
 
 }
 
 @Override
 public void mouseEntered(MouseEvent e) {
 // TODO Auto-generated method stub
 relogin_bt.setBorderPainted(true);
 }
 
 @Override
 public void mouseExited(MouseEvent e) {
 // TODO Auto-generated method stub
 relogin_bt.setBorderPainted(false);
 }
 });
 checkout_bt.addMouseListener(new MouseListener() {
 @Override
 public void mouseClicked(MouseEvent e) {
 // TODO Auto-generated method stub
 CheckOut co=new CheckOut("客人退房","images\\checkout_bt.jpg");
 }
 
 @Override
 public void mousePressed(MouseEvent e) {
 // TODO Auto-generated method stub
 
 }
 
 @Override
 public void mouseReleased(MouseEvent e) {
 // TODO Auto-generated method stub
 
 }
 
 @Override
 public void mouseEntered(MouseEvent e) {
 // TODO Auto-generated method stub
 checkout_bt.setBorderPainted(true);
 }
 
 @Override
 public void mouseExited(MouseEvent e) {
 // TODO Auto-generated method stub
 checkout_bt.setBorderPainted(false);
 }
 });
 money_bt.addMouseListener(new MouseListener() {
 
 
 @Override
 public void mouseClicked(MouseEvent e) {
 // TODO Auto-generated method stub
 
 }
 
 @Override
 public void mousePressed(MouseEvent e) {
 // TODO Auto-generated method stub
 
 }
 
 @Override
 public void mouseReleased(MouseEvent e) {
 // TODO Auto-generated method stub
 
 }
 
 @Override
 public void mouseEntered(MouseEvent e) {
 // TODO Auto-generated method stub
 money_bt.setBorderPainted(true);
 }
 
 @Override
 public void mouseExited(MouseEvent e) {
 // TODO Auto-generated method stub
 money_bt.setBorderPainted(false);
 }
 });
 emploer_bt.addMouseListener(new MouseListener() {
 
 
 @Override
 public void mouseClicked(MouseEvent e) {
 // TODO Auto-generated method stub
 
 }
 
 @Override
 public void mousePressed(MouseEvent e) {
 // TODO Auto-generated method stub
 
 }
 
 @Override
 public void mouseReleased(MouseEvent e) {
 // TODO Auto-generated method stub
 
 }
 
 @Override
 public void mouseEntered(MouseEvent e) {
 // TODO Auto-generated method stub
 emploer_bt.setBorderPainted(true);
 }
 
 @Override
 public void mouseExited(MouseEvent e) {
 // TODO Auto-generated method stub
 emploer_bt.setBorderPainted(false);
 }
 });
 exit_bt.addMouseListener(new MouseListener() {
 
 
 @Override
 public void mouseClicked(MouseEvent e) {
 // TODO Auto-generated method stub
 quit();
 }
 
 @Override
 public void mousePressed(MouseEvent e) {
 // TODO Auto-generated method stub
 
 }
 
 @Override
 public void mouseReleased(MouseEvent e) {
 // TODO Auto-generated method stub
 
 }
 
 @Override
 public void mouseEntered(MouseEvent e) {
 // TODO Auto-generated method stub
 exit_bt.setBorderPainted(true);
 }
 
 @Override
 public void mouseExited(MouseEvent e) {
 // TODO Auto-generated method stub
 exit_bt.setBorderPainted(false);
 }
 });
 time_bt.addMouseListener(new MouseListener() {
 
 
 @Override
 public void mouseClicked(MouseEvent e) {
 // TODO Auto-generated method stub
 updateRoomState();
 }
 
 @Override
 public void mousePressed(MouseEvent e) {
 // TODO Auto-generated method stub
 
 }
 
 @Override
 public void mouseReleased(MouseEvent e) {
 // TODO Auto-generated method stub
 
 }
 
 @Override
 public void mouseEntered(MouseEvent e) {
 // TODO Auto-generated method stub
 time_bt.setBorderPainted(true);
 }
 
 @Override
 public void mouseExited(MouseEvent e) {
 // TODO Auto-generated method stub
 time_bt.setBorderPainted(false);
 }
 });
 
 }
 /**====================================================**
 * **[## public void run() {}] 线程执行,随着系统改变当前时间
 * 参数 :无
 * 返回值 :无
 * 修饰符 :public
 * 功能 :使用线程使当前界面时间随着系统改变当
 **===================================================**/
 public void run() {
 // TODO Auto-generated method stub
 SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
 while(true)
 {
 statelabel.setText("当前时间为:"+df.format(new Date())+" "+"当前登录的用户为:"+id_now+" "+"用户类型为:"+user_type);
 statelabel.repaint();
 this.repaint();
 
 }
 }
 
/**====================================================**
 * **[## private void quit() {}] 系统退出
 * 参数 :无
 * 返回值 :无
 * 修饰符 :private
 * 功能 :关闭系统函数,仅类内使用
 **===================================================**/
private void quit()
{
 int flag=0;
 String msg="你 确 定 要 关 闭 系 统 吗?";
 flag=JOptionPane.showConfirmDialog(null, msg,"提示",JOptionPane.YES_NO_OPTION);
 if(flag==JOptionPane.YES_OPTION)
 {
 this.setVisible(false);
 System.exit(0);
 }
 return;
}
/**====================================================**
 * **[## public void setLabelText(JLabel jl,int row) {}] 为JLabel设置text
 * 返回值 :无
 * 修饰符 :public
 * 功能 :为JLabel设置text
 **===================================================**/
public void setLabelText(JLabel jl,int row)
{
 try{
 jl.setText(Integer.toString(row)+" "+"间");
 }catch(Exception e){}
 }
/**====================================================**
 * **[## public void updateRoomState{}] 更新入住状态
 * 返回值 :无
 * 修饰符 :public
 * 功能 :更新入住统计情况
 **===================================================
 * @throws Exception **/
public void updateRoomState()
{
 DataBaseConnect ns=new DataBaseConnect();
 Vector<Vector> returndata = null;
 try {
 setLabelText(allroom_jl1, ns.getRow("select * from room_table"));
 } catch (Exception e) {
 // TODO Auto-generated catch block
 e.printStackTrace();
 }
 int tol=1;
 try {
 tol = ns.getRow("select * from room_table");
 } catch (Exception e) {
 // TODO Auto-generated catch block
 e.printStackTrace();
 }
 try {
 setLabelText(empty_jl1, ns.getRow("select * from room_table where roomatate=0"));
 } catch (Exception e) {
 // TODO Auto-generated catch block
 e.printStackTrace();
 }
 try {
 setLabelText(ordered_jl1, ns.getRow("select * from room_table where roomatate=1"));
 } catch (Exception e) {
 // TODO Auto-generated catch block
 e.printStackTrace();
 }
 try {
 setLabelText(isliv_jl1, ns.getRow("select * from room_table where roomatate=2"));
 } catch (Exception e) {
 // TODO Auto-generated catch block
 e.printStackTrace();
 }
 int isl=1;
 try {
 isl = ns.getRow("select * from room_table where roomatate=2");
 } catch (Exception e) {
 // TODO Auto-generated catch block
 e.printStackTrace();
 }
 try {
 setLabelText(else_jl1, ns.getRow("select * from room_table where roomatate=3"));
 } catch (Exception e) {
 // TODO Auto-generated catch block
 e.printStackTrace();
 }
 try {
 staticsstate.setText("入 住 率 :"+ " "+(int)(isl*100/tol)+"%");
 
 returndata=ns.RoomOperation();
 } catch (Exception e) {
 // TODO Auto-generated catch block
 e.printStackTrace();
 }
 for(int i=0;i<returndata.get(0).size();i++)
 {
 try{
 roomjb.get(i).setText("<html>" +returndata.get(0).get(i)+"<br>"+returndata.get(1).get(i)+"</html>");
 }catch(Exception e){}
 try{
 if(returndata.get(2).get(i).equals(0))
 roomjb.get(i).setForeground(Color.GREEN);
 else if(returndata.get(2).get(i).equals(1))
 roomjb.get(i).setForeground(Color.pink);
 else
 roomjb.get(i).setForeground(Color.red);
 }catch(Exception e){}
 repaint();
 
 }
 
 }
 
}

4.登记-换房-退房等父类

 /**====================================================**
 * 项目名 :酒店管理系统
 * 模块名 :入住登记窗口与预定登记窗口
 * 文件名 :CheckIn.java
 * 相关文件 :DataBaseConnct.java 
 * 实现功能 :入住登记或预定登记并写入数据库
 * 函数说明 :
 * [## public CheckIn(){}]:
 * 功能:构造函数 组建入住登记窗口
 * 
 * [## public void cancelButton(){}]
 * 功能:取消按钮的事件监听处理
 * 
 * [## returnButton{}]:
 * 功能:返回按钮的事件监听处理
 * 
 * [## public void checkinButton(final int flag){}]:
 * 功能:确定登记按钮的事件监听处理
 * 
 **===================================================**/
package com.databasejdbc;
import com.HotelGui.MyHotelMainGui;
import com.common.*;
 
import java.util.*;
import java.awt.*;
import java.awt.Event.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
 
import javax.swing.*;
public class CheckIn extends JFrame {
 
 JLabel name_jl,gender_jl,id_jl,room_num_jl,room_type_jl,checkin_jl,checkout_jl,tital_jl,tip_jl,price_jl,charge_jl,despoit_jl,tip_jl1,tip_jl2;
 JButton checkin_bt,cancel_bt,return_bt;
 JComboBox<String> gender_jb,room_type_jb;
 JTextField name_jf,id_jf;
 public JTextField room_num_jf;
 JTextField price_jf;
 JTextField despoit_jf;
 JTextField charge_jf;
 JTextField checkin_jf;
 JTextField checkout_jf;
 public static void main(String[] args) {
 // TODO Auto-generated method stub
 CheckIn ck=new CheckIn("入住登记","images\\checkin_bt.jpg");
 ck.cancelButton();
 //ck.checkinButton();
 }
 /**====================================================**
 * **[## public CheckIn(){}] 构造函数
 * 参数 :String str1,String path //界面Tital、按钮UI地址
 * 返回值 :无
 * 修饰符 :public
 * 功能 :构造函数,初始化入住登记界面
 **===================================================**/
 public CheckIn(String str1,String path)
 
 {
 tital_jl=new JLabel(str1);
 tital_jl.setBounds(300,20, 100, 60);
 tital_jl.setFont(new Font("宋体",Font.BOLD,23));
 tip_jl=new JLabel("(以下信息请完整填写)");
 tip_jl.setBounds(270,70, 200, 30);
 tip_jl.setFont(new Font("宋体",Font.HANGING_BASELINE,14));
 
 name_jl=new JLabel("姓 名");
 name_jl.setBounds(150, 170, 60, 30);
 name_jl.setFont(new Font("宋体",Font.HANGING_BASELINE,14));
 name_jf=new JTextField(10);
 name_jf.setBounds(230, 170, 140, 27);
 
 id_jl=new JLabel("身份证号");
 id_jl.setBounds(450, 170, 60, 30);
 id_jl.setFont(new Font("宋体",Font.HANGING_BASELINE,14));
 id_jf=new JTextField(10);
 id_jf.setBounds(530, 170, 140, 27);
 
 gender_jl=new JLabel("性 别");
 gender_jl.setBounds(150, 220, 60, 30);
 gender_jl.setFont(new Font("宋体",Font.HANGING_BASELINE,14));
 gender_jb=new JComboBox<String>();
 gender_jb.setBounds(230, 220, 140, 27);
 gender_jb.addItem("男");
 gender_jb.addItem("女");
 
 
 room_num_jl=new JLabel("房 间 号");
 room_num_jl.setBounds(450, 220, 60, 30);
 room_num_jl.setFont(new Font("宋体",Font.HANGING_BASELINE,14));
 room_num_jf=new JTextField(10);
 room_num_jf.setBounds(530, 220, 140, 27);
 
 room_type_jl=new JLabel("房间标准");
 room_type_jl.setBounds(150, 270, 60, 30);
 room_type_jl.setFont(new Font("宋体",Font.HANGING_BASELINE,14));
 room_type_jb=new JComboBox<String>();
 room_type_jb.setBounds(230, 270, 140, 27);
 room_type_jb.addItem("商务单间");
 room_type_jb.addItem("商务标间");
 room_type_jb.addItem("大床房");
 room_type_jb.addItem("杂物间");
 
 price_jl=new JLabel("房间价格");
 price_jl.setBounds(450, 270, 60, 30);
 price_jl.setFont(new Font("宋体",Font.HANGING_BASELINE,14));
 price_jf=new JTextField(10);
 price_jf.setBounds(530, 270, 140, 27);
 
 charge_jl=new JLabel("实际收费");
 charge_jl.setBounds(150, 320, 60, 30);
 charge_jl.setFont(new Font("宋体",Font.HANGING_BASELINE,14));
 charge_jf=new JTextField(10);
 charge_jf.setBounds(230, 320, 140, 27);
 
 despoit_jl=new JLabel("预收押金");
 despoit_jl.setBounds(450, 320, 60, 30);
 despoit_jl.setFont(new Font("宋体",Font.HANGING_BASELINE,14));
 despoit_jf=new JTextField(10);
 despoit_jf.setBounds(530, 320, 140, 27);
 
 checkin_jl=new JLabel("入住日期");
 tip_jl1=new JLabel("(####-##-##)");
 tip_jl1.setBounds(145, 400, 80, 40);
 checkin_jl.setBounds(150, 370, 60, 40);
 checkin_jl.setFont(new Font("宋体",Font.HANGING_BASELINE,14));
 checkin_jf=new JTextField(10);
 checkin_jf.setBounds(230, 370, 140, 27);
 
 checkout_jl=new JLabel("离店日期");
 tip_jl2=new JLabel("(####-##-##)");
 tip_jl2.setBounds(445, 400, 80, 40);
 checkout_jl.setBounds(450, 370, 60, 30);
 checkout_jl.setFont(new Font("宋体",Font.HANGING_BASELINE,14));
 checkout_jf=new JTextField(10);
 checkout_jf.setBounds(530, 370, 140, 27);
 
 checkin_bt=new JButton(new ImageIcon(path));
 checkin_bt.setBounds(160, 500, 85, 30);
 checkin_bt.setOpaque(false);
 
 cancel_bt=new JButton(new ImageIcon("images\\cancel_bt.jpg"));
 cancel_bt.setBounds(345, 500, 85, 30);
 cancel_bt.setOpaque(false);
 
 return_bt=new JButton(new ImageIcon("images\\return_bt.jpg"));
 return_bt.setBounds(530, 500, 85, 30);
 return_bt.setOpaque(false);
 return_bt.setActionCommand("1");
 /**========================================**
 * 返回按钮注册监听
 =========================================*/
 return_bt.addActionListener(new ActionListener() {
 
 @Override
 public void actionPerformed(ActionEvent e) {
 // TODO Auto-generated method stub
 if(e.getActionCommand().equals("1"))
 returnButton();
 }
 });
 
 this.setLayout(null);
 this.add(tital_jl);
 this.add(tip_jl);
 this.add(name_jl);
 this.add(name_jf);
 this.add(id_jl);
 this.add(gender_jl);
 this.add(room_num_jl);
 this.add(room_type_jl);
 this.add(price_jl);
 this.add(charge_jl);
 this.add(despoit_jl);
 this.add(checkin_jl);
 this.add(tip_jl1);
 this.add(checkout_jl);
 this.add(tip_jl2);
 this.add(checkin_bt);
 this.add(cancel_bt);
 this.add(return_bt);
 this.add(id_jf);
 this.add(gender_jb);
 this.add(room_num_jf);
 this.add(room_type_jb);
 this.add(price_jf);
 this.add(charge_jf);
 this.add(despoit_jf);
 this.add(checkin_jf);
 this.add(checkout_jf);
 
 this.setTitle(str1);
 this.setIconImage(new ImageIcon("images\\入住登记.jpg").getImage());
 this.setBounds(250, 80, Toolkit.getDefaultToolkit().getScreenSize().width-600,Toolkit.getDefaultToolkit().getScreenSize().height-150);
 this.setResizable(false);
 this.setVisible(true);
}
 
 /**====================================================**
 * **[## public void cancelButton() {}] 取消按钮操作
 * 参数 :无
 * 返回值 :无
 * 修饰符 :public
 * 功能 :点击取消按钮清空操作
 **===================================================**/
 public void cancelButton() 
 {
 cancel_bt.addActionListener(new ActionListener() {
 
 @Override
 public void actionPerformed(ActionEvent e) {
 // TODO Auto-generated method stub
 name_jf.setText("");
 id_jf.setText("");
 room_num_jf.setText("");
 charge_jf.setText("");
 price_jf.setText("");
 despoit_jf.setText("");
 checkin_jf.setText("");
 checkout_jf.setText("");
 gender_jb.setSelectedIndex(0);
 room_type_jb.setSelectedIndex(0);
 }
 
 });
 }
 /**====================================================**
 * **[## public void returnButton() {}] 返回按钮操作
 * 参数 :无
 * 返回值 :无
 * 修饰符 :public
 * 功能 :点击返回按钮返回到主界面,入住登记界面释放
 **===================================================**/
 public void returnButton()
 {
 this.dispose();
 }
 /**====================================================**
 * **[## public void checkinButton(int flag) {}] 确定按钮操作
 * 参数 :int flag flag==1,则表示入住登记状态更改 ;flag==2,则表示预订登记状态更改
 * 返回值 :无
 * 修饰符 :public
 * 功能 :点击确定按钮进行入住登记输入数据库操作操作
 **===================================================**/
 public void checkinButton(final int flag)
 {
 checkin_bt.addActionListener(new ActionListener() {
 
 @Override
 public void actionPerformed(ActionEvent e) {
 // TODO Auto-generated method stub 
 
 DataBaseConnect dc=new DataBaseConnect();
 String str=new String(Integer.valueOf(room_num_jf.getText())+",\'"+name_jf.getText()+"\',\'"+gender_jb.getSelectedItem().toString()+"\',\'"+
 id_jf.getText()+"\',\'"+checkin_jf.getText()+"\',\'"+checkout_jf.getText()+"\',"+Integer.valueOf(charge_jf.getText())+","+Integer.valueOf(despoit_jf.getText())+","+1);
 try {
 dc.insertData("costomer_table", str);
 } catch (Exception e1) {
 // TODO Auto-generated catch block
 e1.printStackTrace();
 }
 String sql="update room_table set roomatate="+flag+" where roomnum="+Integer.valueOf(room_num_jf.getText());
 try {
 dc.updateData(sql);
 } catch (Exception e1) {
 // TODO Auto-generated catch block
 e1.printStackTrace();
 }
 JOptionPane.showConfirmDialog(null, "登记成功!","提示",JOptionPane.CLOSED_OPTION);
 int option=0;
 if(option==JOptionPane.YES_OPTION)
 {
 try{
 MyHotelMainGui hm=new MyHotelMainGui(1);
 hm.updateRoomState();
 Thread th=new Thread(hm);
 th.start();
 }
 catch(Exception e1)
 {}
 
 }
 }
 });
 
 }
 
 
}

源代码比较多,就不再上传了,欢迎交流,共同学习进步。项目全部资源需要可从此下载:java实现酒店管理系统

更多学习资料请关注专题《管理系统开发》。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持亿速云。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI