📄 genuscreatedialog.java
字号:
package com.ciash.bms.gui.impl;
import java.awt.*;
import javax.swing.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import javax.swing.JOptionPane;
import com.ciash.bms.entity.BookGenus;
import com.ciash.common.gui.tool.ToolKit;
import com.ciash.bms.gui.uiInter.GenusDialogUI;
import com.ciash.bms.observer.EditGenusObserver;
/**
* <p>
* Title: BMS
* </p>
* <p>
* Description:
* </p>
* <p>
* Copyright: Copyright (c) 2009
* </p>
* <p>
* Company: Cigarette Ash Inc.
* </p>
*
* @author Cigarette Ash
* @version 1.0
*/
public class GenusCreateDialog extends JDialog implements GenusDialogUI {
// private JTextField genusValue = new JTextField();
private JTextField genusDesc = new JTextField();
// private JLabel genusValueLabel = new JLabel();
private JLabel genusDescLabel = new JLabel();
private JButton cancel = new JButton();
private JButton confirm = new JButton();
private int option;
private EditGenusObserver editGenusObserver;
GridBagLayout gridBagLayout1 = new GridBagLayout();
public GenusCreateDialog() {
this(null, "添加分类", true);
jbInit();
Listener l = new Listener();
confirm.addActionListener(l);
confirm.setActionCommand(Listener.CON);
cancel.addActionListener(l);
cancel.setActionCommand(Listener.CAN);
addWindowListener(l);
}
private GenusCreateDialog(Frame frame, String title, boolean model) {
super(frame, title, model);
}
// public void setGenusEditObserver(EditGenusObserver genusObserver) {
// this.editGenusObserver = genusObserver;
// }
//
// public EditGenusObserver getGenusEditObserver() {
// return this.editGenusObserver;
// }
private void jbInit() {
this.setForeground(Color.black);
this.getContentPane().setLayout(gridBagLayout1);
genusDesc.setText("jTextField2");
genusDescLabel.setVerifyInputWhenFocusTarget(true);
genusDescLabel.setText("分类名");
cancel.setText("取消");
confirm.setText("确定");
// this.getContentPane().add(
// genusValueLabel,
// new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
// GridBagConstraints.WEST, GridBagConstraints.NONE,
// new Insets(15, 17, 0, 0), 23, 7));
this.getContentPane().add(
genusDesc,
new GridBagConstraints(1, 1, 2, 1, 1.0, 0.0,
GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
new Insets(8, 0, 0, 14), 66, 2));
// this.getContentPane().add(
// genusValue,
// new GridBagConstraints(1, 0, 2, 1, 1.0, 0.0,
// GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
// new Insets(15, 0, 0, 14), 66, 2));
this.getContentPane().add(
genusDescLabel,
new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0,
GridBagConstraints.WEST, GridBagConstraints.NONE,
new Insets(10, 17, 0, 0), 22, 5));
this.getContentPane().add(
confirm,
new GridBagConstraints(0, 2, 2, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.NONE,
new Insets(16, 29, 15, 0), 20, 1));
this.getContentPane().add(
cancel,
new GridBagConstraints(2, 2, 1, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.NONE,
new Insets(17, 14, 15, 25), 19, 0));
}
private class Listener extends WindowAdapter implements ActionListener {
public final static String CON = "确定";
public final static String CAN = "取消";
public void actionPerformed(ActionEvent e) {
String command = e.getActionCommand();
if (command.equals(CON)) {
if (check()) {
option = OK_OPTION;
setVisible(false);
}
} else if (command.equals(CAN)) {
option = CANCEL_OPTION;
setVisible(false);
}
}
public void windowClosing(WindowEvent e) {
option = CANCEL_OPTION;
setVisible(false);
}
private boolean check() {
// if (ToolKit.isNull(genusValue.getText())) {
// JOptionPane.showMessageDialog(null, "分类值必须填写!", "错误!",
// JOptionPane.ERROR_MESSAGE);
// return false;
// } else
if (ToolKit.isNull(genusDesc.getText())) {
JOptionPane.showMessageDialog(null, "分类名必须填写!", "错误!",
JOptionPane.ERROR_MESSAGE);
return false;
// } else if (!ToolKit.isInt(genusValue.getText())) {
// JOptionPane.showMessageDialog(null, "分类值必须是数字!", "错误!",
// JOptionPane.ERROR_MESSAGE);
// genusValue.grabFocus();
// return false;
}
return true;
}
}
public BookGenus getGenus() {
BookGenus g = new BookGenus();
// String vs = this.genusValue.getText();
// g.setDescription(vs);
g.setDescription(this.genusDesc.getText());
return g;
}
public int getOption() {
return option;
}
public int showDialog() {
// genusValue.setText("");
genusDesc.setText("");
setSize(240, 170);
setLocation(ToolKit.getScreenCenterLocation(getSize()));
setVisible(true);
return option;
}
public void setValueEditable(boolean e) {
this.genusDesc.setEditable(e);
}
public void setDescEditable(boolean e) {
this.genusDesc.setEditable(e);
}
public int showDialog(BookGenus g) {
// genusValue.setText(g.getDescription());
genusDesc.setText(g.getDescription());
setSize(240, 170);
setLocation(ToolKit.getScreenCenterLocation(getSize()));
setVisible(true);
return option;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -