⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainframe[anank].java

📁 (1)功能模块: A :个人开户功能 B :查询功能 查询个人用户信息 查询各个房间使用信息 查询寄存物品信息 C :增加寄存物品模块 用JAVA实现宾馆客房管理系统
💻 JAVA
字号:
/**
 * @author   路建华
 * @version  1.0
 * 时间:大二上学期Java程序设计
 */
import javax.swing.*;
import java.awt.*;
import java.sql.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.table.* ;
import javax.swing.event.ListSelectionListener ;//用ListSelectionListener和ListSelectionEvent的时候好像要单独引入!~
import javax.swing.event.ListSelectionEvent ;
import javax.swing.table.* ;
import javax.swing.tree.* ;
public class MainFrame
{
	/** staticData = new Object[200][4] ;为JTable提供数据来源 */
	static Object[][] staticData = new Object[200][4] ;
    /** myModel是自定义的JTable模型 */
	public class myModel extends AbstractTableModel
	{
		
		String[] columnNames = {"房间号码", "房间类型", "房间价格", "房间状态"} ;
		Object[][] data = staticData ;
		public int getRowCount()
		{
			return data.length ;
		}
		public int getColumnCount()
		{
			return data[0].length ;
		}
		public Object getValueAt(int row, int column)
		{
			return data[row][column] ;
		}
		public String getColumnName(int column)
		{
			return columnNames[column].toString() ;
		}
		public Class getColumnClass(int column)
		{
			return data[0][column].getClass() ;
			
		}
	    public void setValueAt(Object ob, int row, int column)
		{
			data[row][column] = ob ;
		}
		
	}
    
        /** 构造函数MainFrame
         *  完成的任务:所有任务都是在构造函数里面完成的
         */
	public MainFrame()
	{
		for(int i = 0 ; i < 200 ; i++)
		    for(int j = 0 ; j < 2 ; j++)
		        staticData[i][j] = new String() ;
		for(int i = 0 ; i < 200 ; i++)
		    staticData[i][2] = new Integer(0) ;
		for(int i = 0 ; i < 200 ; i++)
		    staticData[i][3] = new Boolean(false) ;
		/*
		 *注意:这个地方如果不线进行初始化,那么系统会发生他NullPointerException!
		 */
		JFrame.setDefaultLookAndFeelDecorated(true);//把JFrame设置城修饰的外观!
		final JFrame frame = new JFrame("宾馆客房关系系统----设计者:软件04-2班   路建华") ;
		frame.setSize(700, 600) ;
		//设置content的布局管理:
		Container content = frame.getContentPane() ;
		GridBagLayout gbl = new GridBagLayout() ;
		GridBagConstraints gbc = new GridBagConstraints() ;
		content.setLayout(gbl) ;
		gbc.fill = GridBagConstraints.BOTH ;
		gbc.weightx = 1.0 ;
		gbc.weighty = 1.0 ;
		//建立表格模型,并依据表格模型建立表格!加到JPanel-panUnderRight上面
		myModel model = new myModel() ;
		JTable table = new JTable(model) ;
		table.setColumnSelectionAllowed(false) ;//只允许选择行的设置!
		table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION ) ;//设置-只允许单选
		//
		JPanel panUnderRight = new JPanel() ;
		panUnderRight.add(new JScrollPane(table)) ;
		//设置菜单
		JMenuBar bar = new JMenuBar() ;
		frame.setJMenuBar(bar) ;
		//添加菜单
		JMenu Reception = new JMenu("宾客接待") ;
		final JMenuItem indiv = new JMenuItem("个人开房") ;
		indiv.addActionListener(new ActionListener()
		    {
		    	public void actionPerformed(ActionEvent e)
		    	{
		    		new IndivOpen() ;
		    	}
		    }) ;//监听类结束!
		JMenuItem party = new JMenuItem("团体开房") ;
		JMenuItem preOrder = new JMenuItem("预定房间") ;
		Reception.add(indiv) ;
		Reception.add(party) ;
		Reception.add(preOrder) ;
		bar.add(Reception) ;
		//////////////////////////////////////////
		JMenu consign = new JMenu("寄存物品") ;
		final JMenuItem consignItem1 = new JMenuItem("寄存物品") ;
		consignItem1.addActionListener(new ActionListener()
		    {
		    	public void actionPerformed(ActionEvent e)
		    	{
		    		new Consign() ;
		    	}
		    }) ;//监听类结束!
		final JMenuItem consignItem2 = new JMenuItem("物品提取和查询") ;
		consignItem2.addActionListener(new ActionListener()
		    {
		    	public void actionPerformed(ActionEvent e)
		    	{
		    		new Distill() ;
		    	}
		    }) ;//监听类结束!
		consign.add(consignItem1) ;
		consign.add(consignItem2) ;
		bar.add(consign) ;
		/////////////////////////////////////////////////
		JMenu cashDealer = new JMenu("收银结帐") ;
		JMenuItem payment = new JMenuItem("结帐") ;
		JMenuItem check = new JMenuItem("核对帐单") ;
		cashDealer.add(payment) ;
		cashDealer.add(check) ;
		bar.add(cashDealer) ;
		//
		JMenu query = new JMenu("查询统计") ;
		JMenuItem roomQuery = new JMenuItem("查询房间信息") ;
		JMenuItem clientQuery = new JMenuItem("查询客户信息") ;
		query.add(roomQuery) ;
		query.add(clientQuery) ;
		bar.add(query) ;
		//
		JMenu finaceManager = new JMenu("财务管理") ;
		JMenuItem paymentQuery = new JMenuItem("帐单查询") ;
		finaceManager.add(paymentQuery) ;
		bar.add(finaceManager) ;
		//
		JMenu system = new JMenu("系统设置") ;
		JMenuItem password = new JMenuItem("密码设置") ;
		JMenuItem changePassword = new JMenuItem("密码更改") ;
		system.add(password) ;
		system.add(changePassword) ;
		bar.add(system) ;
		//
		
		Icon iconReception = new ImageIcon("reception.jpg") ;
		final JButton btnReception = new JButton(iconReception) ;
		btnReception.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent e)
			{
				new IndivOpen() ;
			}
		}) ;//监听类结束!
		gbc.gridx = 0 ;
		gbc.gridy = 0 ;
	    gbl.setConstraints(btnReception, gbc) ;
	    content.add(btnReception) ;
	    gbc.ipadx = 0 ;
		gbc.ipady = 0 ;
		gbc.insets = new Insets(0, 0, 0, 0) ;
		//
		Icon iconPrePay = new ImageIcon("Prepay.jpg") ;
		JButton btnPrepay = new JButton(iconPrePay) ;
		gbc.gridx++ ;
		gbc.gridy = gbc.gridy ;
		//
		gbl.setConstraints(btnPrepay, gbc) ;
		content.add(btnPrepay) ;
		gbc.ipadx = 0 ;
		gbc.ipady = 0 ;
		gbc.insets = new Insets(0, 0, 0, 0) ;
		//
		Icon iconOrder = new ImageIcon("Order.jpg") ;
		JButton btnOrder = new JButton(iconOrder) ;
		gbc.gridx++ ;
		gbc.gridy = gbc.gridy ;
		//
		gbl.setConstraints(btnOrder, gbc) ;
		content.add(btnOrder) ;
		gbc.ipadx = 0 ;
		gbc.ipady = 0 ;
		gbc.insets = new Insets(0, 0, 0, 0) ;
		//
		Icon iconEnd = new ImageIcon("End.jpg") ;
		JButton btnEnd = new JButton(iconEnd) ;
		gbc.gridx++ ;
		gbc.gridy = gbc.gridy ;
		//
		gbl.setConstraints(btnEnd, gbc) ;
		content.add(btnEnd) ;
		gbc.ipadx = 0 ;
		gbc.ipady = 0 ;
		gbc.insets = new Insets(0, 0, 0, 0) ;
		//
		Icon iconClose = new ImageIcon("Close.jpg") ;
		final JButton btnClose = new JButton(iconClose) ;
		btnClose.addActionListener(new ActionListener()
		    {
		    	public void actionPerformed(ActionEvent e)
		    	{
		    	    frame.setVisible(false) ;
		    	    frame.dispose() ;
		    	    System.exit(0) ;
		    	}
		    }) ;//监听类结束!
		gbc.gridx++ ;
		gbc.gridy = gbc.gridy ;
		//
		gbl.setConstraints(btnClose, gbc) ;
		content.add(btnClose) ;
		gbc.ipadx = 0 ;
		gbc.ipady = 0 ;
		gbc.insets = new Insets(0, 0, 0, 0) ;
		//
		Icon iconLabel = new ImageIcon("imageIcon.gif") ;
		JLabel label = new JLabel(iconLabel) ;
		gbc.gridx++ ;
		gbc.gridy = gbc.gridy ;
		gbc.ipady = -6 ;
		gbc.ipadx = 0 ;
		gbc.gridwidth = 5 ;
		gbc.gridheight = 1 ;
		label.setBorder(BorderFactory.createEtchedBorder()) ;
		gbl.setConstraints(label, gbc) ;
		content.add(label) ;
		gbc.ipadx = 0 ;
		gbc.ipady = 0 ;
		gbc.gridwidth = 1 ;
		gbc.gridheight = 1 ;
		///////////////////////////////////////////////////////////////
		//建立树模型并且建立树
		///////////////////////////////////////////////////////////////
		MutableTreeNode Hotel = new DefaultMutableTreeNode("房间") ;
		MutableTreeNode Common = new DefaultMutableTreeNode("普通房间") ;
		MutableTreeNode Luxury = new DefaultMutableTreeNode("豪华房间") ;
		//
		Common.insert(new DefaultMutableTreeNode("普通单人间"), 0);
		Common.insert(new DefaultMutableTreeNode("普通双人间"), 1);
		//
		Luxury.insert(new DefaultMutableTreeNode("总统套房"), 0);
		Luxury.insert(new DefaultMutableTreeNode("普通豪华型"), 1) ;
		//
		Hotel.insert(Common, 0) ;
		Hotel.insert(Luxury, 1) ;
		//
		TreeModel modelTree = new DefaultTreeModel(Hotel) ;
		JTree tree = new JTree(modelTree) ;
		JPanel panUnderLeft = new JPanel(new BorderLayout()) ;
		panUnderLeft.add(new JScrollPane(tree), "Center") ;
		///////////////////////////////////////////////////////////////////
		//树的设计已经完毕!加到Jpanel-panUnderLeft
		//////////////////////////////////////////////////////////////////
		gbc.gridx = 0 ;
		gbc.gridy++ ;
		gbc.gridwidth = 3 ;
		gbc.gridheight = 1 ;
		gbc.ipadx = 0 ;
		gbc.ipady = 20;
		gbc.insets = new Insets(30, 0, 0, 0) ;
		gbl.setConstraints(panUnderLeft, gbc) ;
		content.add(panUnderLeft) ;
		gbc.insets = new Insets(0, 0, 0, 0) ;
		gbc.gridwidth = 1 ;
		gbc.gridheight = 1 ; 
		gbc.ipadx = 0 ;
		gbc.ipady = 0 ;
		//
		gbc.gridx = 3 ;
		gbc.gridy = gbc.gridy ;
		gbc.gridwidth = 7 ;
		gbc.gridheight = 1 ;
		gbc.insets = new Insets(30, 30, 0, 0) ;
		gbl.setConstraints(panUnderRight, gbc) ;
		content.add(panUnderRight) ;
		gbc.insets = new Insets(0, 0, 0, 0) ;
		////////////////////////////////////////////////////
	    frame.pack() ;
	    frame.setResizable(false) ;
		frame.setVisible(true) ;
		////////////////////////////////////////////////////
		//
		String driver   = "sun.jdbc.odbc.JdbcOdbcDriver";
        String url      = "jdbc:odbc:Hotel";
        //注册数据库驱动程序!
        try
        {
            Class.forName(driver);
        }   
        catch(Exception E)
        {
            JOptionPane.showMessageDialog(null, "数据库驱动程序注册失败!") ;
            E.printStackTrace();
        }
        //连接数据库,并进行相关操作!
        try
        {
            Connection con = DriverManager.getConnection(url);
            Statement  smt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
                                               ResultSet.CONCUR_UPDATABLE); 
            //连接成功后,对数据库进行相关的操作! 
            try
            {
                ResultSet  rst = smt.executeQuery("SELECT * from table_Room") ;
                int tableRoomNumber = 0 ;//行号!row
                rst.beforeFirst() ;
                while(rst.next())//在读取ResultSet对象里面的记录的时候,把记录显示到JTable中!
                {
                  
                    String numberOfRoom = rst.getString(1) ;
                    String styleOfRoom = rst.getString(2) ;
                    int priceOfRoom = rst.getInt(3) ;
                    String stateOfRoom = rst.getString(4) ;
                    Boolean bool = new Boolean(true) ;
                    Integer integer = new Integer(priceOfRoom) ;
                    if(stateOfRoom.equals("可用"))
                        bool = new Boolean(true) ;
                    else
                        bool = new Boolean(false) ;
                    staticData[tableRoomNumber][0] = numberOfRoom ;
                    staticData[tableRoomNumber][1] = styleOfRoom ;
                    staticData[tableRoomNumber][2] = integer ;
                    staticData[tableRoomNumber][3] = bool ;
                    tableRoomNumber++ ;
                 }
                 JOptionPane.showMessageDialog(null, "从数据库中导入数据成功!") ;
             }
             catch(SQLException eeee)
             {
                JOptionPane.showMessageDialog(null, "从数据库中导入数据失败!") ;
             }
         }
         catch(SQLException SE)
         {
            JOptionPane.showMessageDialog(null, "数据库连接失败!") ;
         }
	  }
    
	/** 主函数:new MainFrame() ; */
	public static void main(String args[])
	{
		new MainFrame() ;
	}
	
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -