📄 searchhistoryguestframe.java
字号:
package myprojects.search;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.AbstractTableModel;
import java.util.*;
import javax.swing.table.*;
import java.util.Vector;
import java.util.*;
//------------------
import myprojects.search.*;
import myprojects.historyguest.*;
/**
* @(#)SearchHistoryGuestFrame.java
*
* 查找历史客人信息
*
* @author
* @version 1.00 05/12/25
*/
public class SearchHistoryGuestFrame extends JFrame {
JPanel contentPane;
JTabbedPane SearchHistoryGuestTabbedPane = new JTabbedPane();
JPanel searchHistoryGuestByCIdPanel = new JPanel();
JPanel searchAllHistoryGuestPanel = new JPanel();
JPanel searchHistoryGuestByNamePanel = new JPanel();
////////////////////////////////////////////
JLabel hintSearchAllLabel = new JLabel();
JPanel searchAllPanel = new JPanel();
JButton searchAllButton = new JButton();
JButton exitButton = new JButton();
JLabel searchByCIdLabel = new JLabel();
JPanel searchByCIdPanel = new JPanel();
JLabel hintCidLabel = new JLabel();
JTextField certifyIdTextField = new JTextField();
JButton searchCIdButton = new JButton();
JButton exitCIdButton = new JButton();
JLabel hintSearchByNameLabel = new JLabel();
JPanel searchByNamePanel = new JPanel();
JLabel hintsearchNameLabel = new JLabel();
JTextField searchNameTextField = new JTextField();
JButton SearchByNameButton = new JButton();
JButton exitbyNameButton = new JButton();
//用表格来表示列表
DefaultTableModel allHistoryGuestModel = new DefaultTableModel();
JTable allHistoryGuestTable = new JTable(allHistoryGuestModel);
//用表格来表示列表
DefaultTableModel historyGuestByCIdModel = new DefaultTableModel();
JTable historyGuestByCIdTable = new JTable(historyGuestByCIdModel);
//用表格来表示列表
DefaultTableModel historyGuestByNameModel = new DefaultTableModel();
JTable historyGuestByNameTable = new JTable(historyGuestByNameModel);
///////////////////////////////////////////////
SearchHistoryGuest searchHistoryGuest = new SearchHistoryGuest();
//存放所有的历史客人信息
Vector searchAllHistoryList=new Vector();
//历史客人信息 特定Id的客人信息
Vector searchByCIdList=new Vector();
//历史客人信息 特定Name的客人信息
Vector searchByNameList=new Vector();
//Construct the frame
public SearchHistoryGuestFrame() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
contentPane = (JPanel) this.getContentPane();
searchHistoryGuestByNamePanel.setLayout(null);
contentPane.setForeground(Color.black);
contentPane.setDebugGraphicsOptions(0);
this.setSize(new Dimension(430+200-90, 350+50));
this.setLocation(300,250);
this.setTitle("历史客人信息查询");
this.setResizable(false); //使之不能改变大小
searchAllHistoryGuestPanel.setLayout(null);
SearchHistoryGuestTabbedPane.setTabPlacement(JTabbedPane.TOP);
SearchHistoryGuestTabbedPane.setVerifyInputWhenFocusTarget(true);
searchHistoryGuestByCIdPanel.setLayout(null);
hintSearchAllLabel.setText(" 历史客人信息");
hintSearchAllLabel.setBounds(new Rectangle(162, 15, 175, 16));
searchAllPanel.setBackground(Color.lightGray);
searchAllPanel.setBounds(new Rectangle(24, 40, 479, 187));
searchAllButton.setBounds(new Rectangle(160, 272, 73, 25));
searchAllButton.setText("查找");
exitButton.setText("返回");
exitButton.setBounds(new Rectangle(347, 272, 73, 25));
searchByCIdLabel.setText(" 按证件号查询");
searchByCIdLabel.setBounds(new Rectangle(161, 14, 171, 16));
searchByCIdPanel.setBackground(Color.lightGray);
searchByCIdPanel.setBounds(new Rectangle(24, 40, 479, 187));
hintCidLabel.setText("证件号");
hintCidLabel.setBounds(new Rectangle(107, 249, 73, 25));
certifyIdTextField.setText("");
certifyIdTextField.setBounds(new Rectangle(107, 291, 96, 25));
searchCIdButton.setBounds(new Rectangle(368, 249, 73, 25));
searchCIdButton.setText("查找");
exitCIdButton.setText("返回");
exitCIdButton.setBounds(new Rectangle(368, 291, 73, 25));
hintSearchByNameLabel.setText(" 按姓名查询");
hintSearchByNameLabel.setBounds(new Rectangle(172, 17, 189, 16));
searchByNamePanel.setBackground(Color.lightGray);
searchByNamePanel.setBounds(new Rectangle(24, 40, 479, 187));
hintsearchNameLabel.setText("姓名");
hintsearchNameLabel.setBounds(new Rectangle(107, 249, 73, 25));
searchNameTextField.setText("");
searchNameTextField.setBounds(new Rectangle(107, 293, 98, 22));
SearchByNameButton.setBounds(new Rectangle(364, 249, 73, 25));
SearchByNameButton.setSelectedIcon(null);
SearchByNameButton.setText("查找");
exitbyNameButton.setBounds(new Rectangle(364, 292, 73, 25));
exitbyNameButton.setText("返回");
contentPane.add(SearchHistoryGuestTabbedPane, null);
SearchHistoryGuestTabbedPane.add(searchAllHistoryGuestPanel, "查询所有");
searchAllHistoryGuestPanel.add(searchAllPanel, null);
SearchHistoryGuestTabbedPane.add(searchHistoryGuestByCIdPanel, "按证件号查询");
SearchHistoryGuestTabbedPane.add(searchHistoryGuestByNamePanel, "按姓名查询");
searchAllHistoryGuestPanel.add(exitButton, null);
searchAllHistoryGuestPanel.add(searchAllButton, null);
searchAllHistoryGuestPanel.add(hintSearchAllLabel, null);
searchHistoryGuestByCIdPanel.add(searchByCIdPanel, null);
searchHistoryGuestByCIdPanel.add(searchCIdButton, null);
searchHistoryGuestByCIdPanel.add(exitCIdButton, null);
searchHistoryGuestByCIdPanel.add(certifyIdTextField, null);
searchHistoryGuestByCIdPanel.add(hintCidLabel, null);
searchHistoryGuestByCIdPanel.add(searchByCIdLabel, null);
searchHistoryGuestByNamePanel.add(searchByNamePanel, null);
searchHistoryGuestByNamePanel.add(hintsearchNameLabel, null);
searchHistoryGuestByNamePanel.add(searchNameTextField, null);
searchHistoryGuestByNamePanel.add(exitbyNameButton, null);
searchHistoryGuestByNamePanel.add(SearchByNameButton, null);
searchHistoryGuestByNamePanel.add(hintSearchByNameLabel, null);
/////////////////////////////////////////////
allHistoryGuestModel.addColumn("历史客人号");
allHistoryGuestModel.addColumn("首次登记号");
allHistoryGuestModel.addColumn("证件类型");
allHistoryGuestModel.addColumn("证件号码");
allHistoryGuestModel.addColumn("姓名");
allHistoryGuestModel.addColumn("总消费天数");
allHistoryGuestModel.addColumn("总消费");
allHistoryGuestTable.setPreferredScrollableViewportSize(new Dimension(130, 100));
allHistoryGuestTable.setBackground(new Color(255, 255, 210));
allHistoryGuestTable.setRowHeight(20);
allHistoryGuestTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
JScrollPane allCheckinInfoscrollpane = new JScrollPane(allHistoryGuestTable);
searchAllPanel.setLayout(new BorderLayout());
searchAllPanel.add(allCheckinInfoscrollpane,BorderLayout.CENTER);
/////////////////////////////////////////////
historyGuestByCIdModel.addColumn("历史客人号");
historyGuestByCIdModel.addColumn("首次登记号");
historyGuestByCIdModel.addColumn("证件类型");
historyGuestByCIdModel.addColumn("证件号码");
historyGuestByCIdModel.addColumn("姓名");
historyGuestByCIdModel.addColumn("总消费天数");
historyGuestByCIdModel.addColumn("总消费");
historyGuestByCIdTable.setPreferredScrollableViewportSize(new Dimension(130, 100));
historyGuestByCIdTable.setBackground(new Color(255, 255, 210));
historyGuestByCIdTable.setRowHeight(20);
historyGuestByCIdTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
JScrollPane checkinInfoByIdscrollpane = new JScrollPane(historyGuestByCIdTable);
searchByCIdPanel.setLayout(new BorderLayout());
searchByCIdPanel.add(checkinInfoByIdscrollpane,BorderLayout.CENTER);
/////////////////////////////////////////////
historyGuestByNameModel.addColumn("历史客人号");
historyGuestByNameModel.addColumn("首次登记号");
historyGuestByNameModel.addColumn("证件类型");
historyGuestByNameModel.addColumn("证件号码");
historyGuestByNameModel.addColumn("姓名");
historyGuestByNameModel.addColumn("总消费天数");
historyGuestByNameModel.addColumn("总消费");
historyGuestByNameTable.setPreferredScrollableViewportSize(new Dimension(130, 100));
historyGuestByNameTable.setBackground(new Color(255, 255, 210));
historyGuestByNameTable.setRowHeight(20);
historyGuestByNameTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
JScrollPane checkinInfoByNamescrollpane = new JScrollPane(historyGuestByNameTable);
searchByNamePanel.setLayout(new BorderLayout());
searchByNamePanel.add(checkinInfoByNamescrollpane,BorderLayout.CENTER);
///////////////////////////////////////////////////////////////
//所有客人的信息
searchAllHistoryList = searchHistoryGuest.getAllHistoryGuestList();
//按钮事件处理
searchAllButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
searchAllInfo_searchAllButtonClick();
}
});
//按钮事件处理
searchCIdButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
searchById_searchCheckInIdButtonClick();
}
});
//按钮事件处理
SearchByNameButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
searchByName_searchCheckInIdButtonClick();
}
});
exitButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
closeFrame();
}
});
exitCIdButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
closeFrame();
}
});
exitbyNameButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
closeFrame();
}
});
////////////////////////////////////////////
this.setVisible(true);
SearchHistoryGuestTabbedPane.setSelectedComponent(searchAllHistoryGuestPanel);
//SearchHistoryGuestTabbedPane.setSelectedIndex(0);
////////////////////////////////////////////
}
//所有客人的信息
void searchAllInfo_searchAllButtonClick(){
while(allHistoryGuestModel.getRowCount()!=0){
allHistoryGuestModel.removeRow(0);
}
//从 SearchHistoryGuest 类对象获取的信息: 登记客人信息
//所有客人的信息
//searchAllHistoryList.removeAllElements();
//searchAllHistoryList = searchHistoryGuest.getAllHistoryGuestList();
HistoryGuest hGuest=new HistoryGuest();
for(int i=0;i<searchAllHistoryList.size();i++)
{
hGuest=(HistoryGuest)searchAllHistoryList.get(i);
String certificateKind="";
if(hGuest.certificateKind==0)
certificateKind="身份证";
else if(hGuest.certificateKind==1)
certificateKind="军官证";
else
certificateKind="学生证";
allHistoryGuestModel.addRow(new Object[]{
Integer.toString(hGuest.historyGuestId),
Integer.toString(hGuest.firstCheckInId),
certificateKind,
hGuest.certificateId.trim(),
hGuest.guestName.trim(),
Integer.toString(hGuest.totalStayNum),
hGuest.totalExpense+"",
});
}
}
void searchById_searchCheckInIdButtonClick(){
boolean mark=false;
while(historyGuestByCIdModel.getRowCount()!=0){
historyGuestByCIdModel.removeRow(0);
}
HistoryGuest hGuest=new HistoryGuest();
for(int i=0;i<searchAllHistoryList.size();i++)
{
hGuest=(HistoryGuest)searchAllHistoryList.get(i);
String id=certifyIdTextField.getText().trim();
if(hGuest.certificateId.trim().equals(id.trim())){
////////////////////////////////////
String certificateKind="";
if(hGuest.certificateKind==0)
certificateKind="身份证";
else if(hGuest.certificateKind==1)
certificateKind="军官证";
else
certificateKind="学生证";
historyGuestByCIdModel.addRow(new Object[]{
Integer.toString(hGuest.historyGuestId),
Integer.toString(hGuest.firstCheckInId),
certificateKind,
hGuest.certificateId.trim(),
hGuest.guestName.trim(),
Integer.toString(hGuest.totalStayNum),
hGuest.totalExpense+"",
});
////////////////////////////////////
mark=true; //标志查到了
}
}
if(!mark){
//如果没有找到,则通知不存在该客人入住
JOptionPane.showMessageDialog(this,"不存在该历史客人","ok",
JOptionPane.INFORMATION_MESSAGE);
}
}
void searchByName_searchCheckInIdButtonClick(){
boolean mark=false;
while(historyGuestByNameModel.getRowCount()!=0){
historyGuestByNameModel.removeRow(0);
}
HistoryGuest hGuest=new HistoryGuest();
String name=searchNameTextField.getText().trim();
for(int i=0;i<searchAllHistoryList.size();i++)
{
hGuest=(HistoryGuest)searchAllHistoryList.get(i);
if(name.equals(hGuest.guestName.trim())){
String certificateKind="";
if(hGuest.certificateKind==0)
certificateKind="身份证";
else if(hGuest.certificateKind==1)
certificateKind="军官证";
else
certificateKind="学生证";
historyGuestByNameModel.addRow(new Object[]{
Integer.toString(hGuest.historyGuestId),
Integer.toString(hGuest.firstCheckInId),
certificateKind,
hGuest.certificateId.trim(),
hGuest.guestName.trim(),
Integer.toString(hGuest.totalStayNum),
hGuest.totalExpense+"",
});
////////////////////////////////////
mark=true; //标志查到了
}
}
if(!mark){
//如果没有找到,则通知不存在该客人入住
JOptionPane.showMessageDialog(this,"不存在该历史客人","ok",
JOptionPane.INFORMATION_MESSAGE);
}
}
//close this frame when window is closed
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
closeFrame();
}
}
void closeFrame() {
this.dispose();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -