?? returnbook.java~28~
字號:
package bookmanager;import javax.swing.*;import com.borland.jbcl.layout.*;import java.awt.*;import java.awt.event.*;import java.sql.*;/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2003</p> * <p>Company: </p> * @author not attributable * @version 1.0 */public class returnBook extends JFrame { //定義結(jié)果集 ResultSet rs; // 定義數(shù)據(jù)庫操作對象 private DBManager db =new DBManager(); XYLayout xYLayout1 = new XYLayout(); JLabel jLabel4 = new JLabel(); JTextField jTextbookname = new JTextField(); JButton jButtonCancel = new JButton(); JButton jButtonOk = new JButton(); JLabel jLabel1 = new JLabel(); JLabel jLabel3 = new JLabel(); JButton jButtonReset = new JButton(); JTextField jTextreturndate = new JTextField(); JLabel jLabel2 = new JLabel(); JTextField jTextcomment = new JTextField(); JTextField jTextstudentname = new JTextField(); public returnBook() { try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } public static void main(String[] args) { returnBook returnBook = new returnBook(); } private void jbInit() throws Exception { jTextstudentname.setText(""); jTextstudentname.setFont(new java.awt.Font("Dialog", 0, 16)); jTextcomment.setText(""); jTextcomment.setFont(new java.awt.Font("Dialog", 0, 16)); jLabel2.setFont(new java.awt.Font("Dialog", 0, 16)); jLabel2.setText("書名"); jTextreturndate.setText(""); jTextreturndate.setFont(new java.awt.Font("Dialog", 0, 16)); jButtonReset.setText("清空"); jButtonReset.addMouseListener(new returnBook_jButtonReset_mouseAdapter(this)); jButtonReset.setFont(new java.awt.Font("Dialog", 0, 16)); jButtonReset.setEnabled(true); jLabel3.setFont(new java.awt.Font("Dialog", 0, 16)); jLabel3.setText("日期"); jLabel1.setFont(new java.awt.Font("Dialog", 0, 16)); jLabel1.setRequestFocusEnabled(true); jLabel1.setText("還書者姓名"); jButtonOk.setFont(new java.awt.Font("Dialog", 0, 16)); jButtonOk.setText("確定"); jButtonOk.addMouseListener(new returnBook_jButtonOk_mouseAdapter(this)); jButtonCancel.setFont(new java.awt.Font("Dialog", 0, 16)); jButtonCancel.addMouseListener(new returnBook_jButtonCancel_mouseAdapter(this)); jButtonCancel.setText("退出"); jButtonCancel.addMouseListener(new returnBook_jButtonCancel_mouseAdapter(this)); jTextbookname.setText(""); jTextbookname.setFont(new java.awt.Font("Dialog", 0, 16)); jLabel4.setFont(new java.awt.Font("Dialog", 0, 16)); jLabel4.setText("備注"); this.getContentPane().setLayout(xYLayout1); xYLayout1.setWidth(497); xYLayout1.setHeight(306); this.getContentPane().add(jTextstudentname, new XYConstraints(204, 32, 134, 26)); this.getContentPane().add(jLabel4, new XYConstraints(79, 184, 63, 29)); this.getContentPane().add(jTextbookname, new XYConstraints(200, 82, 154, 30)); this.getContentPane().add(jButtonCancel, new XYConstraints(334, 229, 100, 36)); this.getContentPane().add(jButtonOk, new XYConstraints(208, 230, 101, 36)); this.getContentPane().add(jLabel3, new XYConstraints(79, 136, 87, 29)); this.getContentPane().add(jButtonReset, new XYConstraints(57, 233, 104, 32)); this.getContentPane().add(jTextreturndate, new XYConstraints(202, 131, 137, -1)); this.getContentPane().add(jLabel2, new XYConstraints(82, 79, 89, 35)); this.getContentPane().add(jTextcomment, new XYConstraints(206, 187, 137, -1)); this.getContentPane().add(jLabel1, new XYConstraints(80, 29, 88, 33)); } void jButtonCancel_mouseClicked(MouseEvent e) { this.dispose(); }//清空所有文本框 void jButtonReset_mouseClicked(MouseEvent e) { jTextstudentname.setText(""); jTextbookname.setText(""); jTextreturndate.setText(""); jTextcomment.setText(""); } void jButtonOk_mouseClicked(MouseEvent e) { String strSQL ; //借閱者姓名是否為空 if(jTextstudentname.getText().trim().equals("")) {JOptionPane.showMessageDialog(null,"借閱者姓名不許為空!"); return;} //書名是否為空 if(jTextbookname.getText().trim().equals("")) {JOptionPane.showMessageDialog(null,"書名不許為空!"); return;} //還閱日起是否為空 if(jTextreturndate.getText().trim().equals("")) {JOptionPane.showMessageDialog(null,"還閱日起不許為空!"); return;} //檢驗是否此人借的此書 strSQL="select * from BookBorrow where username='"+jTextFieldusername.getText().trim() +"' and password='"+jPasswordold.getText().trim()+"'"; rs=db.getResult(strSQL) ; boolean isexist=false; try { isexist = rs.first(); } catch (SQLException ex1) { } //若用戶名不存在,提示警告信息提醒用戶從新輸入 if(!isexist) {JOptionPane.showMessageDialog(null,"用戶名不存在,或原密碼不正確!"); return; } //生成更新sql語句 strSQL="update BookBorrow set returndate='"+jTextreturndate.getText()+"',"; strSQL=strSQL+" comment='"+jTextcomment.getText() +"'"; strSQL=strSQL+" where studentname='"+jTextstudentname.getText() +"'"; strSQL=strSQL+" and bookname='"+jTextbookname.getText() +"'"; //由數(shù)據(jù)庫操作對象執(zhí)行數(shù)據(jù)庫操作,并返回操作成功失敗的提示信息 if(db.executeSql(strSQL) ){ JOptionPane.showMessageDialog(null,"操作成功!"); } else { JOptionPane.showMessageDialog(null,"此借書者不存在!請確認!"); } }}class returnBook_jButtonCancel_mouseAdapter extends java.awt.event.MouseAdapter { returnBook adaptee; returnBook_jButtonCancel_mouseAdapter(returnBook adaptee) { this.adaptee = adaptee; } public void mouseClicked(MouseEvent e) { adaptee.jButtonCancel_mouseClicked(e); }}class returnBook_jButtonReset_mouseAdapter extends java.awt.event.MouseAdapter { returnBook adaptee; returnBook_jButtonReset_mouseAdapter(returnBook adaptee) { this.adaptee = adaptee; } public void mouseClicked(MouseEvent e) { adaptee.jButtonReset_mouseClicked(e); }}class returnBook_jButtonOk_mouseAdapter extends java.awt.event.MouseAdapter { returnBook adaptee; returnBook_jButtonOk_mouseAdapter(returnBook adaptee) { this.adaptee = adaptee; } public void mouseClicked(MouseEvent e) { adaptee.jButtonOk_mouseClicked(e); }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -