?? frmlibsearch.java~35~
字號:
pnlLibMessage.add(lblIsin);
pnlLibMessage.add(txtSynopsis);
pnlLibMessage.add(btnSearch);
pnlLibMessage.add(btnCancel);
pnlLibMessage.add(btnExit);
pnlLibMessage.add(rbnBlurrySearch);
pnlLibMessage.add(rbnExactSearch);
pnlLibMessage.add(lblLine);
pnlLibMessage.add(lblSynopsis);
pnlLibMessage.add(txtLoanCount);
pnlLibMessage.add(lblBorrowCount);
pnlLibMessage.add(lblLocation);
this.getContentPane().add(pnlLibMessage);
this.getContentPane().add(lblDisplay);
this.getContentPane().add(jScrollPane1);
jScrollPane1.getViewport().add(tblDisplay);
buttonGroup1.add(rbnExactSearch);
buttonGroup1.add(rbnBlurrySearch);
rbnExactSearch.setSelected(true);
this.setTitle("圖書查詢");
this.setDefaultLookAndFeelDecorated(true);
DisplayAllBook();
tblDisplay.setAutoResizeMode(tblDisplay.AUTO_RESIZE_OFF);
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() {
for (int i = 0; i < column.length; i++) {
vtColName.add(column[i]);
}
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 ShowLibSearch() {
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) {
pnlLibMessage.setLocation((this.getWidth() - pnlLibMessage.getWidth()) /
2, 0);
jScrollPane1.setSize(this.getWidth() - 30,
this.getHeight() - pnlLibMessage.getHeight() - 65);
tblDisplay.setSize(jScrollPane1.getWidth(), jScrollPane1.getHeight());
}
//******************************查詢按鈕事件********************************
public void btnSearch_actionPerformed(ActionEvent e) {
String Id = txtSearchId.getText();
String BarCode = txtSearchBarCode.getText();
String Name = txtSearchName.getText();
String Author = txtSearchAuthor.getText();
String Publish = txtSearchPublish.getText();
String Sort = txtSearchSort.getText();
BookConDB bookDB = new BookConDB();
boolean Isnot;
if (rbnExactSearch.isSelected()) {
Isnot = true;
} else {
for (int i = 0; i < Id.length(); i++) {
if (String.valueOf(Id.charAt(i)).equals("%")) {
JOptionPane.showMessageDialog(null, "模糊查詢不能含有特殊符號\"%\"!");
return;
}
}
for (int i = 0; i < BarCode.length(); i++) {
if (String.valueOf(BarCode.charAt(i)).equals("%")) {
JOptionPane.showMessageDialog(null, "模糊查詢不能含有特殊符號\"%\"!");
return;
}
}
for (int i = 0; i < Author.length(); i++) {
if (String.valueOf(Author.charAt(i)).equals("%")) {
JOptionPane.showMessageDialog(null, "模糊查詢不能含有特殊符號\"%\"!");
return;
}
}
for (int i = 0; i < Author.length(); i++) {
if (String.valueOf(Author.charAt(i)).equals("%")) {
JOptionPane.showMessageDialog(null, "模糊查詢不能含有特殊符號\"%\"!");
return;
}
}
for (int i = 0; i < Publish.length(); i++) {
if (String.valueOf(Publish.charAt(i)).equals("%")) {
JOptionPane.showMessageDialog(null, "模糊查詢不能含有特殊符號\"%\"!");
return;
}
}
for (int i = 0; i < Sort.length(); i++) {
if (String.valueOf(Sort.charAt(i)).equals("%")) {
JOptionPane.showMessageDialog(null, "模糊查詢不能含有特殊符號\"%\"!");
return;
}
}
Isnot = false;
}
if (Id.equals("") && BarCode.equals("") && Name.equals("") &&
Author.equals("") && Publish.equals("") && Sort.equals("")) {
Displaynull();
JOptionPane.showMessageDialog(this, "請輸入內(nèi)容");
} else {
vt = bookDB.SearchBook(Id, BarCode, Name, Author, Publish, Sort,
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) {
txtSearchId.setText("");
txtSearchBarCode.setText("");
txtSearchName.setText("");
txtSearchAuthor.setText("");
txtSearchPublish.setText("");
txtSearchSort.setText("");
}
//******************************退出按鈕事件********************************
public void btnExit_actionPerformed(ActionEvent e) {
this.dispose();
}
}
class frmLibSearch_btnExit_actionAdapter implements ActionListener {
private frmLibSearch adaptee;
frmLibSearch_btnExit_actionAdapter(frmLibSearch adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.btnExit_actionPerformed(e);
}
}
class frmLibSearch_btnCancel_actionAdapter implements ActionListener {
private frmLibSearch adaptee;
frmLibSearch_btnCancel_actionAdapter(frmLibSearch adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.btnCancel_actionPerformed(e);
}
}
class frmLibSearch_tblDisplay_mouseAdapter extends MouseAdapter {
private frmLibSearch adaptee;
frmLibSearch_tblDisplay_mouseAdapter(frmLibSearch adaptee) {
this.adaptee = adaptee;
}
public void mouseClicked(MouseEvent e) {
adaptee.tblDisplay_mouseClicked(e);
}
}
class frmLibSearch_btnSearch_actionAdapter implements ActionListener {
private frmLibSearch adaptee;
frmLibSearch_btnSearch_actionAdapter(frmLibSearch adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.btnSearch_actionPerformed(e);
}
}
class frmLibSearch_this_componentAdapter extends ComponentAdapter {
private frmLibSearch adaptee;
frmLibSearch_this_componentAdapter(frmLibSearch adaptee) {
this.adaptee = adaptee;
}
public void componentResized(ComponentEvent e) {
adaptee.this_componentResized(e);
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -