📄 frmlibmanage.java
字号:
tblDisplay.getTableHeader().setReorderingAllowed(false);
}
//****************************显示空表格及清空所有文本框**********************************
public void Displaynull() {
Vector vt = new Vector();
dt = new DefaultTableModel(vt, vtColName);
tblDisplay.setModel(dt);
txtId.setText("");
txtBarCode.setText("");
txtName.setText("");
txtAuthor.setText("");
txtPage.setText("");
txtPublish.setText("");
txtIsbn.setText("");
txtPrice.setText("");
txtSort.setText("");
txtIntoTime.setText("");
txtLocation.setText("");
txtIsin.setText("");
txtLoanCount.setText("");
txtSynopsis.setText("");
}
//********************************显示所有图书******************************
public void DisplayAllBook() {
BookConDB bookDB = new BookConDB();
vt = bookDB.SearchAll();
bookDB.CloseBookDB();
dt = new DefaultTableModel(vt, vtColName);
tblDisplay.setModel(dt);
txtId.setText(String.valueOf(tblDisplay.getValueAt(0, 0)));
txtBarCode.setText(String.valueOf(tblDisplay.getValueAt(0, 1)));
txtName.setText(String.valueOf(tblDisplay.getValueAt(0, 2)));
txtAuthor.setText(String.valueOf(tblDisplay.getValueAt(0, 3)));
txtPage.setText(String.valueOf(tblDisplay.getValueAt(0, 4)));
txtPublish.setText(String.valueOf(tblDisplay.getValueAt(0, 5)));
txtIsbn.setText(String.valueOf(tblDisplay.getValueAt(0, 6)));
txtPrice.setText(String.valueOf(tblDisplay.getValueAt(0, 7)));
txtSort.setText(String.valueOf(tblDisplay.getValueAt(0, 8)));
txtIntoTime.setText(String.valueOf(tblDisplay.getValueAt(0, 9)));
txtLocation.setText(String.valueOf(tblDisplay.getValueAt(0, 10)));
txtIsin.setText(String.valueOf(tblDisplay.getValueAt(0, 11)));
txtLoanCount.setText(String.valueOf(tblDisplay.getValueAt(0, 12)));
txtSynopsis.setText(String.valueOf(tblDisplay.getValueAt(0, 13)));
}
//******************************显示窗口********************************
public void ShowLibManage() {
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension dlgSize = this.getSize();
if (dlgSize.height > screenSize.height) {
dlgSize.height = screenSize.height;
}
if (dlgSize.width > screenSize.width) {
dlgSize.width = screenSize.width;
}
this.setLocation((screenSize.width - dlgSize.width) / 2,
(screenSize.height - dlgSize.height) / 2);
this.setVisible(true);
}
//******************************表格根随窗口改变********************************
public void this_componentResized(ComponentEvent e) {
pnlFind.setLocation((this.getWidth() - pnlFind.getWidth()) / 2, 0);
jScrollPane1.setSize(this.getWidth() - 40,
this.getHeight() - pnlFind.getHeight() - 60);
tblDisplay.setSize(jScrollPane1.getWidth(), jScrollPane1.getHeight());
}
//******************************更新按钮事件********************************
public void btnUpdate_actionPerformed(ActionEvent e) {
String Id = txtId.getText();
String BarCode = txtBarCode.getText();
String Name = txtName.getText();
String Author = txtAuthor.getText();
String Page = txtPage.getText();
String Publish = txtPublish.getText();
String Isbn = txtIsbn.getText();
String Price = txtPrice.getText();
String Sort = txtSort.getText();
String IntoTime = txtIntoTime.getText();
String Location = txtLocation.getText();
String Isin = txtIsin.getText();
String LoanCount = txtLoanCount.getText();
String Synopsis = txtSynopsis.getText();
if (Id.equals("")) {
JOptionPane.showMessageDialog(this, "修改失败,请选择你要修改的图书!");
return;
}
BookConDB bookDB = new BookConDB();
boolean Success = bookDB.UpdateBook(Id, BarCode, Name, Author, Page,
Publish, Isbn, Price, Sort, IntoTime,
Location, Isin, LoanCount, Synopsis);
if (!Success) {
JOptionPane.showMessageDialog(this, "修改失败!");
return;
}
vt = bookDB.SearchAll();
bookDB.CloseBookDB();
dt = new DefaultTableModel(vt, vtColName);
tblDisplay.setModel(dt);
JOptionPane.showMessageDialog(this, "修改成功");
}
//******************************查询按钮事件********************************
public void btnSearch_actionPerformed(ActionEvent e) {
BookConDB bookDB = new BookConDB();
if (rbnExactSearch.isSelected()) {
Isnot = true;
} else {
for (int i = 0; i < txtContent.getText().length(); i++) {
if (String.valueOf(txtContent.getText().charAt(i)).equals("%")) {
JOptionPane.showMessageDialog(null, "模糊查询不能含有特殊符号\"%\"!");
return;
}
}
Isnot = false;
}
if (txtContent.getText().equals("")) {
Displaynull();
JOptionPane.showMessageDialog(this, "请输入内容");
} else {
vt = bookDB.SearchUpdateBook(txtContent.getText(),
cbbSort.getSelectedItem().toString(),
Isnot);
bookDB.CloseBookDB();
if (vt.size() < 1) {
Displaynull();
JOptionPane.showMessageDialog(this, "找不到记录!");
} else {
dt = new DefaultTableModel(vt, vtColName);
tblDisplay.setModel(dt);
int row = tblDisplay.getSelectedRow();
if (row < 0) {
row++;
}
txtId.setText(String.valueOf(tblDisplay.getValueAt(row, 0)));
txtBarCode.setText(String.valueOf(tblDisplay.getValueAt(row, 1)));
txtName.setText(String.valueOf(tblDisplay.getValueAt(row, 2)));
txtAuthor.setText(String.valueOf(tblDisplay.getValueAt(row, 3)));
txtPage.setText(String.valueOf(tblDisplay.getValueAt(row, 4)));
txtPublish.setText(String.valueOf(tblDisplay.getValueAt(row, 5)));
txtIsbn.setText(String.valueOf(tblDisplay.getValueAt(row, 6)));
txtPrice.setText(String.valueOf(tblDisplay.getValueAt(row, 7)));
txtSort.setText(String.valueOf(tblDisplay.getValueAt(row, 8)));
txtIntoTime.setText(String.valueOf(tblDisplay.getValueAt(row,
9)));
txtLocation.setText(String.valueOf(tblDisplay.getValueAt(row,
10)));
txtIsin.setText(String.valueOf(tblDisplay.getValueAt(row, 11)));
txtLoanCount.setText(String.valueOf(tblDisplay.getValueAt(row,
12)));
txtSynopsis.setText(String.valueOf(tblDisplay.getValueAt(row,
13)));
}
}
}
//********************************鼠标点击表格事件******************************
public void tblDisplay_mouseClicked(MouseEvent e) {
int row = tblDisplay.getSelectedRow();
txtId.setText(String.valueOf(tblDisplay.getValueAt(row, 0)));
txtBarCode.setText(String.valueOf(tblDisplay.getValueAt(row, 1)));
txtName.setText(String.valueOf(tblDisplay.getValueAt(row, 2)));
txtAuthor.setText(String.valueOf(tblDisplay.getValueAt(row, 3)));
txtPage.setText(String.valueOf(tblDisplay.getValueAt(row, 4)));
txtPublish.setText(String.valueOf(tblDisplay.getValueAt(row, 5)));
txtIsbn.setText(String.valueOf(tblDisplay.getValueAt(row, 6)));
txtPrice.setText(String.valueOf(tblDisplay.getValueAt(row, 7)));
txtSort.setText(String.valueOf(tblDisplay.getValueAt(row, 8)));
txtIntoTime.setText(String.valueOf(tblDisplay.getValueAt(row, 9)));
txtLocation.setText(String.valueOf(tblDisplay.getValueAt(row, 10)));
txtIsin.setText(String.valueOf(tblDisplay.getValueAt(row, 11)));
txtLoanCount.setText(String.valueOf(tblDisplay.getValueAt(row, 12)));
txtSynopsis.setText(String.valueOf(tblDisplay.getValueAt(row, 13)));
}
//*******************************清空按钮事件*******************************
public void btnCancel_actionPerformed(ActionEvent e) {
txtContent.setText("");
cbbSort.setSelectedIndex(0);
}
//*******************************退出按钮事件*******************************
public void btnExit_actionPerformed(ActionEvent e) {
this.dispose();
}
//*******************************删除按钮事件*******************************
public void btnDelete_actionPerformed(ActionEvent e) {
String Isin = txtIsin.getText();
if (Isin.equals("不在库")) {
JOptionPane.showMessageDialog(this, "图书不在库,不能删除!");
} else if(txtId.getText().equals("")){
JOptionPane.showMessageDialog(this, "请选择你要删除的图书!");
} else {
BookConDB bookDB = new BookConDB();
bookDB.DeleteBook(txtId.getText());
bookDB.CloseBookDB();
DisplayAllBook();
JOptionPane.showMessageDialog(this, "成功删除");
}
}
}
class frmLibManage_btnExit_actionAdapter implements ActionListener {
private frmLibManage adaptee;
frmLibManage_btnExit_actionAdapter(frmLibManage adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.btnExit_actionPerformed(e);
}
}
class frmLibManage_btnDelete_actionAdapter implements ActionListener {
private frmLibManage adaptee;
frmLibManage_btnDelete_actionAdapter(frmLibManage adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.btnDelete_actionPerformed(e);
}
}
class frmLibManage_btnCancel_actionAdapter implements ActionListener {
private frmLibManage adaptee;
frmLibManage_btnCancel_actionAdapter(frmLibManage adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.btnCancel_actionPerformed(e);
}
}
class frmLibManage_tblDisplay_mouseAdapter extends MouseAdapter {
private frmLibManage adaptee;
frmLibManage_tblDisplay_mouseAdapter(frmLibManage adaptee) {
this.adaptee = adaptee;
}
public void mouseClicked(MouseEvent e) {
adaptee.tblDisplay_mouseClicked(e);
}
}
class frmLibManage_btnSearch_actionAdapter implements ActionListener {
private frmLibManage adaptee;
frmLibManage_btnSearch_actionAdapter(frmLibManage adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.btnSearch_actionPerformed(e);
}
}
class frmLibManage_btnUpdate_actionAdapter implements ActionListener {
private frmLibManage adaptee;
frmLibManage_btnUpdate_actionAdapter(frmLibManage adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.btnUpdate_actionPerformed(e);
}
}
class frmLibManage_this_componentAdapter extends ComponentAdapter {
private frmLibManage adaptee;
frmLibManage_this_componentAdapter(frmLibManage adaptee) {
this.adaptee = adaptee;
}
public void componentResized(ComponentEvent e) {
adaptee.this_componentResized(e);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -