📄 addbookdialog.java
字号:
/*
* Created on 2005-5-8
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package ui;
import java.awt.*;
import javax.swing.*;
/**
* @author ade
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class addBookDialog extends Dialog{
/**
* @param arg0
*/
public addBookDialog(Frame arg0) {
super(arg0);
// TODO Auto-generated constructor stub
initialize();
}
private JLabel bookIDLabel = new JLabel("图书编号");
private JLabel bookNameLabel = new JLabel("图书名称");
private JLabel bookAuthorLabel = new JLabel("图书作者");
private JLabel bookAvailableLabel = new JLabel("可借阅量");
private JLabel bookSumLabel = new JLabel("图书总量");
private TextField bookIDField = null;
private TextField bookNameField = null;
private TextField bookAuthorField = null;
private TextField bookAvailableField = null;
private TextField bookSumField = null;
private Button okBut = null;
private Button cancelBut = null;
private int bookID = 0;
private String bookName = "";
private String bookAuthor = "";
private int available = 0;
private int bookSum = 0;
private boolean cancelled = false;
public void initialize() {
this.setLayout(null);
this.add(getBookIDlabel(), null);
this.add(getBookNameLabel(), null);
this.add(getBookAuthorLabel(), null);
this.add(getBookAvailableLabel(),null);
this.add(getBookSumLabel(), null);
this.add(getBookIDField(), null);
this.add(getBookNameField(), null);
this.add(getBookAuthorField(), null);
this.add(getBookAvailableField(),null);
this.add(getBookSumField(), null);
this.add(getOKBut(), null);
this.add(getCancleBut(), null);
this.setSize(321, 289);
this.setTitle("添加新书");
this.setModal(true);
this.setResizable(false);
this.addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent e) {
setCancelled(true);
setVisible(false);
}
});
}
/**
* This method initializes bookIDLabel
*
* @return JLabel
*/
private JLabel getBookIDlabel() {
bookIDLabel.setBounds(13, 39, 60, 20);
return bookIDLabel;
}
/**
* This method initializes bookNameLabel
*
* @return JLabel
*/
private JLabel getBookNameLabel() {
bookNameLabel.setBounds(13, 73, 61, 17);
return bookNameLabel;
}
/**
* This method initializes bookAuthorLabel
*
* @return JLabel
*/
private JLabel getBookAuthorLabel() {
bookAuthorLabel.setBounds(14, 112, 59, 18);
return bookAuthorLabel;
}
/**
* This method initializes bookAvailableLabel
*
* @return JLabel
*/
private JLabel getBookAvailableLabel() {
bookAvailableLabel.setBounds(16, 153, 57, 18);
return bookAvailableLabel;
}
/**
* This method initializes bookSumLabel
*
* @return JLabel
*/
private JLabel getBookSumLabel() {
bookSumLabel.setBounds(16, 189, 57, 18);
return bookSumLabel;
}
/**
* This method initializes textField
*
* @return java.awt.TextField
*/
private TextField getBookIDField() {
if(bookIDField == null) {
bookIDField = new TextField();
bookIDField.setBounds(87, 41, 208, 22);
bookIDField.minimumSize(10);
bookIDField.setName("书号");
bookIDField.addTextListener(new java.awt.event.TextListener() {
public void textValueChanged(java.awt.event.TextEvent e) {
try{
bookID = Integer.parseInt(bookIDField.getText());
}
catch(Exception ex){
}
}
});
bookIDField.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyPressed(java.awt.event.KeyEvent e) {
if(e.getKeyChar() < 32 || e.getKeyChar() >= 127)return;
if(e.getKeyChar() < '0' || e.getKeyChar() > '9'){
e.consume();
}
}
});
}
return bookIDField;
}
public void setIDadaptable(){
bookIDField.setEditable(false);
}
/**
* This method initializes textField1
*
* @return java.awt.TextField
*/
private java.awt.TextField getBookNameField() {
if(bookNameField == null) {
bookNameField = new java.awt.TextField();
bookNameField.setBounds(88, 75, 209, 20);
bookNameField.setName("书名");
bookNameField.addTextListener(new java.awt.event.TextListener() {
public void textValueChanged(java.awt.event.TextEvent e) {
bookName = bookNameField.getText();
}
});
bookNameField.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyPressed(java.awt.event.KeyEvent e) {
if(e.getKeyChar() == '<' || e.getKeyChar() == '>'){
JOptionPane.showMessageDialog(null, "书名中不能有'<' 和 '>'!");
e.consume();
}
}
});
}
return bookNameField;
}
/**
* This method initializes textField2
*
* @return java.awt.TextField
*/
private java.awt.TextField getBookAuthorField() {
if(bookAuthorField == null) {
bookAuthorField = new TextField();
bookAuthorField.setBounds(90, 109, 204, 22);
bookAuthorField.setName("作者");
bookAuthorField.addTextListener(new java.awt.event.TextListener() {
public void textValueChanged(java.awt.event.TextEvent e) {
bookAuthor = bookAuthorField.getText();
}
});
}
return bookAuthorField;
}
/**
* This method initializes textField3
*
* @return java.awt.TextField
*/
private java.awt.TextField getBookAvailableField() {
if(bookAvailableField == null) {
bookAvailableField = new java.awt.TextField();
bookAvailableField.setBounds(88, 151, 206, 18);
bookAvailableField.setName("可借阅");
bookAvailableField.setEditable(false);
bookAvailableField.addTextListener(new java.awt.event.TextListener() {
public void textValueChanged(java.awt.event.TextEvent e) {
try{
available = Integer.parseInt(bookAvailableField.getText());
}
catch(Exception ex){
}
}
});
}
return bookAvailableField;
}
/**
* This method initializes textField3
*
* @return java.awt.TextField
*/
private TextField getBookSumField() {
if(bookSumField == null) {
bookSumField = new TextField();
bookSumField.setBounds(90, 187, 204, 20);
bookSumField.setName("书总量");
bookSumField.addTextListener(new java.awt.event.TextListener() {
public void textValueChanged(java.awt.event.TextEvent e) {
try{
bookSum = Integer.parseInt(bookSumField.getText());
}
catch(Exception ex){
}
}
});
}
return bookSumField;
}
/**
* This method initializes button
*
* @return java.awt.Button
*/
private java.awt.Button getOKBut() {
if(okBut == null) {
okBut = new java.awt.Button();
okBut.setBounds(121, 239, 85, 23);
okBut.setLabel("确定");
okBut.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
if(getBookID() == 0){
JOptionPane.showMessageDialog(null, "书号不能为0");
return;
}
if(getBookTitle().trim().length() == 0){
JOptionPane.showMessageDialog(null, "书名不能为空");
return;
}
if(getTotal() == 0){
JOptionPane.showMessageDialog(null, "总数不能为0");
return;
}
// LibraryBook book = new LibraryBook();
// book.setBookID(getBookID());
// if(library.getBook_storage().findComparable(book) != null){
// JOptionPane.showMessageDialog(null, "您所输入的书号已经被另一本书占用,请换一个书号或把旧书删除,然后再试一次");
// return;
// }
setCancelled(false);
setVisible(false);
}
});
}
return okBut;
}
/**
* This method initializes button1
*
* @return java.awt.Button
*/
private java.awt.Button getCancleBut() {
if(cancelBut == null) {
cancelBut = new java.awt.Button();
cancelBut.setBounds(214, 241, 91, 21);
cancelBut.setLabel("取消");
cancelBut.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
setCancelled(true);
setVisible(false);
}
});
}
return cancelBut;
}
/**
* @return
*/
public boolean isCancelled() {
return cancelled;
}
/**
* @param b
*/
public void setCancelled(boolean b) {
cancelled = b;
}
/**
* @return
*/
public String getAuthor() {
return bookAuthor;
}
/**
* @return
*/
public int getAvailable() {
return available;
}
/**
* @return
*/
public int getBookID() {
return bookID;
}
/**
* @return
*/
public String getBookTitle() {
return bookName;
}
/**
* @return
*/
public int getTotal() {
return bookSum;
}
/**
* @param string
*/
public void setAuthor(String string) {
bookAuthor = string;
bookAuthorField.setText(string);
}
/**
* @param i
*/
public void setAvailable(int i) {
available = i;
bookAvailableField.setText(""+i);
}
/**
* @param i
*/
public void setBookID(int i) {
bookID = i;
bookIDField.setText(""+i);
}
/**
* @param string
*/
public void setBookTitle(String string) {
bookName = string;
bookNameField.setText(string);
}
/**
* @param i
*/
public void setTotal(int i) {
bookSum = i;
bookSumField.setText(i+"");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -