?? searchpanel.java
字號:
package cn.javass.bookmgr.user.ui.panels;
import java.awt.*;
import javax.swing.JPanel;
import com.borland.jbcl.layout.*;
import javax.swing.*;
import java.awt.event.*;
import cn.javass.bookmgr.util.uiutil.ChangePanel;
import cn.javass.bookmgr.MainFrame;
import cn.javass.bookmgr.user.business.factory.UserFactory;
import cn.javass.bookmgr.user.valueobject.UserModel;
import cn.javass.bookmgr.user.valueobject.QueryUserModel;
import java.util.Collection;
/**
* 用戶模塊表現(xiàn)層用于用戶查詢的Panel
*
* <p>Title: Java私塾第一個Java項目——圖書進銷存系統(tǒng)(單機版)</p>
* <p>Description: 網(wǎng)址:<a href="http://www.javass.cn">http://www.javass.cn</a>
* 新電話:010-86835215 新地址:北京市海淀區(qū)廠洼路5號院深博達商務(wù)樓5層</p>
* <p>Copyright: Copyright (c) 2008</p>
* <p>Company: Java私塾</p>
* @author Java私塾
* @version 1.0
*/
public class SearchPanel extends JPanel {
//以下為本界面需要的組件定義
XYLayout xYLayout1 = new XYLayout();
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
JLabel jLabel3 = new JLabel();
JLabel jLabel4 = new JLabel();
JTextField txt_userId = new JTextField();
JTextField txt_name = new JTextField();
JComboBox cmb_type = new JComboBox();
JButton btn_search = new JButton();
JButton btn_back = new JButton();
/**
* 用來保持對主窗體的引用
*/
MainFrame mf = null;
/**
* 構(gòu)建用戶查詢的Panel
* @param mf 主窗體的引用
*/
public SearchPanel(MainFrame mf) {
try {
this.mf = mf;
jbInit();
}
catch(Exception ex) {
ex.printStackTrace();
}
}
/**
* 真正進行組件初始化,并構(gòu)建整個界面
* @throws Exception
*/
void jbInit() throws Exception {
jLabel1.setFont(new java.awt.Font("Dialog", 1, 30));
//為用戶類型的下拉列表設(shè)置初始值
//添加一個為空的值,因為這是查詢,可以不按照類型查詢
this.cmb_type.addItem("");
this.cmb_type.addItem(UserModel.TYPE_1);
this.cmb_type.addItem(UserModel.TYPE_2);
this.cmb_type.addItem(UserModel.TYPE_3);
this.cmb_type.addItem(UserModel.TYPE_4);
this.cmb_type.addItem(UserModel.TYPE_5);
this.cmb_type.addItem(UserModel.TYPE_6);
jLabel1.setText("查詢用戶");
this.setLayout(xYLayout1);
jLabel2.setText("用戶編號");
jLabel3.setText("用戶姓名");
jLabel4.setText("用戶類型");
txt_userId.setText("");
txt_name.setText("");
btn_search.setText("查詢");
btn_search.addActionListener(new SearchPanel_btn_search_actionAdapter(this));
btn_back.setText("返回");
btn_back.addActionListener(new SearchPanel_btn_back_actionAdapter(this));
xYLayout1.setWidth(497);
xYLayout1.setHeight(413);
this.add(jLabel1, new XYConstraints(96, 12, 377, 82));
this.add(jLabel2, new XYConstraints(13, 91, 77, 30));
this.add(jLabel3, new XYConstraints(238, 90, 77, 30));
this.add(jLabel4, new XYConstraints(13, 165, 77, 30));
this.add(txt_userId, new XYConstraints(63, 93, 166, 33));
this.add(txt_name, new XYConstraints(295, 93, 166, 33));
this.add(cmb_type, new XYConstraints(63, 163, 166, 33));
this.add(btn_search, new XYConstraints(142, 343, 117, 46));
this.add(btn_back, new XYConstraints(307, 343, 117, 46));
}
/**
* 點擊查詢按鈕的事件處理
* @param e Action事件對象
*/
void btn_search_actionPerformed(ActionEvent e) {
//1:收集參數(shù)
String id = this.txt_userId.getText();
String name = this.txt_name.getText();
String type = (String)this.cmb_type.getSelectedItem();
//2:組織參數(shù)
QueryUserModel um = new QueryUserModel();
um.setId(id);
um.setName(name);
um.setType(um.typeStringToInt(type));
//3:調(diào)用邏輯層Api,并獲取返回值
Collection col = UserFactory.getInstance().createUserEbi().getByCondition(um);
//4:根據(jù)返回值選擇新的Panel
ChangePanel.changePanel(mf,new ListPanel(mf,true,col));
}
/**
* 點擊返回按鈕的事件處理
* @param e Action事件對象
*/
void btn_back_actionPerformed(ActionEvent e) {
ChangePanel.changePanel(mf,new ListPanel(mf,false,null));
}
}
//以下為事件處理中的Adaper類
class SearchPanel_btn_search_actionAdapter implements java.awt.event.ActionListener {
SearchPanel adaptee;
SearchPanel_btn_search_actionAdapter(SearchPanel adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.btn_search_actionPerformed(e);
}
}
class SearchPanel_btn_back_actionAdapter implements java.awt.event.ActionListener {
SearchPanel adaptee;
SearchPanel_btn_back_actionAdapter(SearchPanel adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.btn_back_actionPerformed(e);
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -