📄 deletepanel.java
字号:
package cn.javass.bookmgr.book.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.book.business.factory.BookFactory;import cn.javass.bookmgr.book.valueobject.BookModel;/** * 图书模块表现层用于删除图书的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 DeletePanel 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_delete = new JButton(); JButton btn_back = new JButton(); JTextField txt_inPrice = new JTextField(); JTextField txt_salePrice = new JTextField(); /** * 用来保持对主窗体的引用 */ MainFrame mf = null; /** * 需要删除的图书的String值 */ String str = ""; /** * 需要删除的图书Model */ BookModel bm = null; /** * 构建删除图书的Panel * @param mf 主窗体的引用 * @param str 图书的String值 */ public DeletePanel(MainFrame mf,String str) { try { this.str = str; this.mf = mf; jbInit(); } catch(Exception ex) { ex.printStackTrace(); } } /** * 真正进行组件初始化,并构建整个界面 * @throws Exception */ void jbInit() throws Exception { //1:根据传递过来的图书String,转换成为对应的图书Model bm = new BookModel(this.str); //2:把值设置到组件上,用于显示 this.txt_name.setText(bm.getName()); this.txt_Id.setText(bm.getId()); this.txt_Id.setEditable(false); this.txt_inPrice.setText(""+bm.getInPrice()); this.txt_salePrice.setText(""+bm.getSalePrice()); jLabel1.setFont(new java.awt.Font("Dialog", 1, 30)); jLabel1.setText("删除图书"); this.setLayout(xYLayout1); jLabel2.setText("图书编号"); jLabel3.setText("图书名称"); jLabel5.setText("进货价格"); jLabel6.setText("销售价格"); btn_delete.setText("删除"); btn_delete.addActionListener(new DeletePanel_btn_delete_actionAdapter(this)); btn_back.setText("返回"); btn_back.addActionListener(new DeletePanel_btn_back_actionAdapter(this)); xYLayout1.setWidth(486); xYLayout1.setHeight(397); 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(txt_Id, new XYConstraints(63, 93, 166, 33)); this.add(txt_name, new XYConstraints(295, 93, 166, 33)); this.add(btn_back, new XYConstraints(307, 251, 117, 46)); this.add(jLabel5, new XYConstraints(13, 164, 77, 30)); this.add(txt_inPrice, new XYConstraints(63, 169, 166, 33)); this.add(jLabel6, new XYConstraints(238, 164, 77, 30)); this.add(txt_salePrice, new XYConstraints(295, 169, 166, 33)); this.add(btn_delete, new XYConstraints(142, 251, 117, 46)); } /** * 点击删除按钮的事件处理 * @param e Action事件对象 */ void btn_delete_actionPerformed(ActionEvent e) { //1: //2: //3:调用逻辑层Api,并获取返回值 boolean flag = BookFactory.getInstance().createBookEbi().deleteBook(bm); //4:根据返回值选择新的Panel if(flag){ ChangePanel.changePanel(mf,new ListPanel(mf,false,null)); }else{ JOptionPane.showMessageDialog(null,"很遗憾,删除失败了"); } } /** * 点击返回按钮的事件处理 * @param e Action事件对象 */ void btn_back_actionPerformed(ActionEvent e) { ChangePanel.changePanel(mf,new ListPanel(mf,false,null)); }}//以下为事件处理中的Adaper类class DeletePanel_btn_delete_actionAdapter implements java.awt.event.ActionListener { DeletePanel adaptee; DeletePanel_btn_delete_actionAdapter(DeletePanel adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.btn_delete_actionPerformed(e); }}class DeletePanel_btn_back_actionAdapter implements java.awt.event.ActionListener { DeletePanel adaptee; DeletePanel_btn_back_actionAdapter(DeletePanel adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.btn_back_actionPerformed(e); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -