roominfoframe.java

来自「Athena酒店小组_Athena酒店管理系统」· Java 代码 · 共 262 行

JAVA
262
字号
/*
 * RoomInformationFrame.java
 *
 * Created on 2007年6月19日, 下午2:48
 */

package frames;

import java.util.*;
import javax.swing.*;

import plugin.*;
import module.*;
import helper.*;
import lambert.*;


/**
 *
 * @author  hlb
 */
public class RoomInfoFrame extends javax.swing.JInternalFrame {
    
    /** Creates new form RoomInformationFrame */
    public RoomInfoFrame() {
        initComponents();
        new UIEffect(this).MakeComponentPerfectPosition();
        userInit();
    }
        private void userInit()
    {
        BindHelper bh = new BindHelper(Resource.getDBResource());
	//装载客房号信息
	bh.bindRoomInfo(jComboBox1);
        
	//设置Table格式
	jTable1.getTableHeader().setReorderingAllowed(false);
	jTable1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
	
	//获取客房信息
	RoomAccess ra = new RoomAccess(Resource.getDBResource());
	ArrayList<Room> rms = ra.getAllRooms();
	for(Room r : rms)
	{
	    Object[] objs = new Object[]
	    {
		r.getRoomNum(),
		r.getRoomType(),
                r.getEngrossDetail()
	    };
	    TableHelper.addToTable(jTable1, objs);
	}
    }
        private String getSelectedRoomNum() {
            int index =jTable1.getSelectedRow();
            if (index == -1) {
                return null;
            }
            return jTable1.getValueAt(index, 0).toString();
        }

        
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" 生成的代码 ">//GEN-BEGIN:initComponents
    private void initComponents() {
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jButton1 = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jComboBox1 = new javax.swing.JComboBox();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();

        setClosable(true);
        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setIconifiable(true);
        setMaximizable(true);
        setResizable(true);
        setTitle("\u5ba2\u623f\u4fe1\u606f\u7ba1\u7406");
        jScrollPane1.setBorder(javax.swing.BorderFactory.createTitledBorder("\u5ba2\u623f\u72b6\u6001"));
        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "客房号", "类型", "占用情况"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTable1MouseClicked(evt);
            }
        });

        jScrollPane1.setViewportView(jTable1);

        jButton1.setText("\u9000\u51fa");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("\u8fc7\u6ee4"));
        jLabel1.setText("\u5ba2\u623f\u53f7\uff1a");

        jButton2.setText("\u67e5\u8be2");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 145, Short.MAX_VALUE)
                .addComponent(jButton2)
                .addGap(18, 18, 18))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel1)
                .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jButton2))
        );

        jButton3.setText("\u4fee\u6539");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 379, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jButton3)
                        .addGap(22, 22, 22)
                        .addComponent(jButton1)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 231, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jButton3))
                .addGap(10, 10, 10))
        );
        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MouseClicked
// TODO 将在此处添加您的处理代码:
        if (evt.getClickCount() == 2) {
            jButton3ActionPerformed(null);
        }
    }//GEN-LAST:event_jTable1MouseClicked

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
// TODO 将在此处添加您的处理代码:
        String roomNum=null;
        //清除表格数据
	TableHelper.clearTable(jTable1);
	
	//获取查询信息
	ArrayList<String> names = new ArrayList<String>();
	ArrayList<Object> values = new ArrayList<Object>();
	if (jComboBox1.getSelectedIndex()!=-1)
	{
	    roomNum = ((Room)jComboBox1.getSelectedItem()).getRoomNum();
        }
	//查询客房信息并将其添加到Table中
	RoomAccess ra = new RoomAccess(Resource.getDBResource());
        Room r = ra.getRoomByRoomNum(roomNum);
        Object[] objs = new Object[]
        {
            r.getRoomNum(),
            r.getRoomType(),
            r.getEngrossDetail()
        };
        TableHelper.addToTable(jTable1, objs);
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
// TODO 将在此处添加您的处理代码:
	RoomAccess ra = new RoomAccess(Resource.getDBResource());
        Room r = ra.getRoomByRoomNum(getSelectedRoomNum());
        RoomInfoModifFrame rim=new RoomInfoModifFrame(r);
        Resource.getGUIResource().getDesktopPane().add(rim);
	rim.setVisible(true);
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
// TODO 将在此处添加您的处理代码:
        this.dispose();
    }//GEN-LAST:event_jButton1ActionPerformed
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new RoomInfoFrame().setVisible(true);
            }
        });
    }
    
    // 变量声明 - 不进行修改//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    // 变量声明结束//GEN-END:variables
    
}

⌨️ 快捷键说明

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