📄 searchpanel.java
字号:
package cn.javass.bookmgr.book.ui.panels;
import java.awt.*;
import com.borland.jbcl.layout.*;
import java.awt.event.*;
import cn.javass.bookmgr.util.uiutil.ChangePanel;
import cn.javass.bookmgr.MainFrame;
import cn.javass.bookmgr.book.business.factory.BookFactory;
import cn.javass.bookmgr.book.valueobject.BookModel;
import cn.javass.bookmgr.book.valueobject.QueryBookModel;
import java.util.Collection;
import javax.swing.*;
/**
* 图书模块表现层用于图书查询的Panel
*
* <p>Title: Java私塾第一个Java项目——图书进销存系统(单机版)</p>
* <p>Description: 网址:<a href="http://www.javass.cn">http://www.javass.cn</a>
* 新电话:010-86835215 新地址:北京市海淀区厂洼路5号院深博达商务楼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 jLabel5 = new JLabel();
JLabel jLabel6 = new JLabel();
JTextField txt_Id = new JTextField();
JTextField txt_name = new JTextField();
JButton btn_search = new JButton();
JButton btn_back = new JButton();
JTextField txt_inPrice = new JTextField();
JTextField txt_salePrice = new JTextField();
JLabel jLabel4 = new JLabel();
JTextField txt_inPrice2 = new JTextField();
JLabel jLabel7 = new JLabel();
JTextField txt_salePrice2 = new JTextField();
/**
* 用来保持对主窗体的引用
*/
MainFrame mf = null;
/**
* 构建图书查询的Panel
* @param mf 主窗体的引用
*/
public SearchPanel(MainFrame mf) {
try {
this.mf = mf;
jbInit();
}
catch (Exception ex) {
ex.printStackTrace();
}
}
/**
* 真正进行组件初始化,并构建整个界面
* @throws Exception
*/
void jbInit() throws Exception {
jLabel1.setFont(new java.awt.Font("Dialog", 1, 30));
jLabel1.setText("查询图书");
this.setLayout(xYLayout1);
jLabel2.setText("图书编号");
jLabel3.setText("图书名称");
jLabel5.setText("最低进货价格");
jLabel6.setText("最低销售价格");
txt_Id.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(543);
xYLayout1.setHeight(413);
txt_inPrice.setText("");
txt_salePrice.setText("");
jLabel4.setText("最高进货价格");
txt_inPrice2.setText("");
jLabel7.setText("最高销售价格");
txt_salePrice2.setText("");
this.add(jLabel2, new XYConstraints(13, 91, 77, 30));
this.add(btn_back, new XYConstraints(307, 326, 117, 46));
this.add(jLabel5, new XYConstraints(13, 164, 77, 30));
this.add(btn_search, new XYConstraints(147, 326, 117, 46));
this.add(jLabel6, new XYConstraints(13, 237, 77, 30));
this.add(txt_salePrice, new XYConstraints(88, 239, 166, 33));
this.add(txt_inPrice, new XYConstraints(88, 168, 166, 33));
this.add(jLabel4, new XYConstraints(276, 164, 101, 37));
this.add(txt_inPrice2, new XYConstraints(357, 168, 166, 33));
this.add(txt_name, new XYConstraints(357, 93, 166, 33));
this.add(jLabel3, new XYConstraints(276, 92, 77, 30));
this.add(jLabel7, new XYConstraints(276, 237, 98, 37));
this.add(txt_salePrice2, new XYConstraints(357, 239, 166, 33));
this.add(txt_Id, new XYConstraints(88, 93, 166, 33));
this.add(jLabel1, new XYConstraints(197, 7, 377, 82));
}
/**
* 点击查询按钮的事件处理
* @param e Action事件对象
*/
void btn_search_actionPerformed(ActionEvent e) {
//1:收集参数
String id = this.txt_Id.getText();
String name = this.txt_name.getText();
String inPrice = this.txt_inPrice.getText();
String salePrice = this.txt_salePrice.getText();
String inPrice2 = this.txt_inPrice2.getText();
String salePrice2 = this.txt_salePrice2.getText();
//2:组织参数
QueryBookModel bm = new QueryBookModel();
bm.setId(id);
bm.setName(name);
if (inPrice != null && inPrice.trim().length() > 0) {
bm.setInPrice(Double.parseDouble(inPrice));
}
if (salePrice != null && salePrice.trim().length() > 0) {
bm.setSalePrice(Double.parseDouble(salePrice));
}
if (inPrice2 != null && inPrice2.trim().length() > 0) {
bm.setInPrice2(Double.parseDouble(inPrice2));
}
if (salePrice2 != null && salePrice2.trim().length() > 0) {
bm.setSalePrice2(Double.parseDouble(salePrice2));
}
//3:调用逻辑层Api,并获取返回值
Collection col = BookFactory.getInstance().createBookEbi().getByCondition(
bm);
//4:根据返回值选择新的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);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -