⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 borrowbook.java~8~

📁 Java信息系统设计与开发实例(第二版)随书源代码.
💻 JAVA~8~
字号:
package bookmanager;import javax.swing.*;import com.borland.jbcl.layout.*;import java.awt.*;import java.awt.event.*;/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2003</p> * <p>Company: </p> * @author not attributable * @version 1.0 */public class borrowBook extends JFrame {  //定义数据库操作对象 private DBManager db =new DBManager();  XYLayout xYLayout1 = new XYLayout();  JLabel jLabel4 = new JLabel();  JLabel jLabel2 = new JLabel();  JButton jButtonCancel = new JButton();  JTextField jTextbookname = new JTextField();  JTextField jTextborrowdate = new JTextField();  JLabel jLabel1 = new JLabel();  JButton jButtonOk = new JButton();  JLabel jLabel3 = new JLabel();  JTextField jTextcomment = new JTextField();  JButton jButtonReset = new JButton();  JTextField jTextstudentname = new JTextField();  public borrowBook() {    try {      jbInit();    }    catch(Exception e) {      e.printStackTrace();    }  }  public static void main(String[] args) {    borrowBook borrowBook = new borrowBook();  }  private void jbInit() throws Exception {    jTextstudentname.setText("");    jTextstudentname.setFont(new java.awt.Font("Dialog", 0, 16));     jButtonReset.setText("清空");    jButtonReset.addMouseListener(new borrowBook_jButtonReset_mouseAdapter(this));    jButtonReset.setFont(new java.awt.Font("Dialog", 0, 16));    jButtonReset.setEnabled(true);    jTextcomment.setText("");    jTextcomment.setFont(new java.awt.Font("Dialog", 0, 16));    jLabel3.setText("日期");    jLabel3.setFont(new java.awt.Font("Dialog", 0, 16));     jButtonOk.setText("确定");    jButtonOk.addMouseListener(new borrowBook_jButtonOk_mouseAdapter(this));    jButtonOk.setFont(new java.awt.Font("Dialog", 0, 16));    jLabel1.setText("借阅者姓名");    jLabel1.setRequestFocusEnabled(true);    jLabel1.setFont(new java.awt.Font("Dialog", 0, 16));    jTextborrowdate.setText("");    jTextborrowdate.setFont(new java.awt.Font("Dialog", 0, 16));    jTextbookname.setText("");    jTextbookname.setFont(new java.awt.Font("Dialog", 0, 16));     jButtonCancel.setText("取消");    jButtonCancel.addMouseListener(new borrowBook_jButtonCancel_mouseAdapter(this));    jButtonCancel.setFont(new java.awt.Font("Dialog", 0, 16));    jLabel2.setText("书名");    jLabel2.setFont(new java.awt.Font("Dialog", 0, 16));    jLabel4.setText("备注");    jLabel4.setFont(new java.awt.Font("Dialog", 0, 16));    xYLayout1.setWidth(484);    xYLayout1.setHeight(307);    this.getContentPane().setLayout(xYLayout1);    this.getContentPane().add(jTextstudentname,  new XYConstraints(206, 23, 150, 26));    this.getContentPane().add(jLabel4, new XYConstraints(77, 180, 63, 29));    this.getContentPane().add(jLabel2, new XYConstraints(75, 77, 89, 35));    this.getContentPane().add(jTextbookname, new XYConstraints(205, 77, 154, 23));    this.getContentPane().add(jTextborrowdate, new XYConstraints(205, 120, 153, -1));    this.getContentPane().add(jLabel1, new XYConstraints(78, 19, 88, 33));    this.getContentPane().add(jLabel3, new XYConstraints(75, 133, 87, 29));    this.getContentPane().add(jTextcomment, new XYConstraints(206, 169, 154, -1));    this.getContentPane().add(jButtonOk,  new XYConstraints(189, 248, 101, 30));    this.getContentPane().add(jButtonCancel,  new XYConstraints(315, 249, 100, 29));    this.getContentPane().add(jButtonReset,  new XYConstraints(56, 250, 104, 27));  }  void jButtonCancel_mouseClicked(MouseEvent e) {         this.dispose();  }//清空所有文本框  void jButtonReset_mouseClicked(MouseEvent e) {           jTextstudentname.setText("");            jTextbookname.setText("");             jTextborrowdate.setText("");              jTextcomment.setText("");  }  void jButtonOk_mouseClicked(MouseEvent e) {    String sql;      //借阅者姓名是否为空         if(jTextstudentname.getText().trim().equals(""))         {JOptionPane.showMessageDialog(null,"借阅者姓名不许为空!");             return;}       //书名是否为空     if(jTextbookname.getText().trim().equals(""))         {JOptionPane.showMessageDialog(null,"书名不许为空!");             return;}       //借阅日起是否为空     if(jTextborrowdate.getText().trim().equals(""))         {JOptionPane.showMessageDialog(null,"借阅日起不许为空!");             return;}    //然后执行插入操作                sql="insert into BookBorrow(studentname,bookname,borrowdate,returndate,comment)values(  ";                  sql=sql+"'"+jTextstudentname.getText() +"',";                    sql=sql+"'"+jTextbookname.getText() +"',";                      sql=sql+"#"+jTextborrowdate.getText()+"#,";                       sql=sql+"'',";                          sql=sql+"'"+jTextcomment.getText() +"'";                sql=sql+")";         //由数据库操作对象执行数据库操作,并返回操作成功失败的提示信息                   if(db.executeSql(sql))                       {JOptionPane.showMessageDialog(null,"成功添加!"); }                    else                       { JOptionPane.showMessageDialog(null," 添加失败,请重新操作!");      }  }}class borrowBook_jButtonCancel_mouseAdapter extends java.awt.event.MouseAdapter {  borrowBook adaptee;  borrowBook_jButtonCancel_mouseAdapter(borrowBook adaptee) {    this.adaptee = adaptee;  }  public void mouseClicked(MouseEvent e) {    adaptee.jButtonCancel_mouseClicked(e);  }}class borrowBook_jButtonReset_mouseAdapter extends java.awt.event.MouseAdapter {  borrowBook adaptee;  borrowBook_jButtonReset_mouseAdapter(borrowBook adaptee) {    this.adaptee = adaptee;  }  public void mouseClicked(MouseEvent e) {    adaptee.jButtonReset_mouseClicked(e);  }}class borrowBook_jButtonOk_mouseAdapter extends java.awt.event.MouseAdapter {  borrowBook adaptee;  borrowBook_jButtonOk_mouseAdapter(borrowBook adaptee) {    this.adaptee = adaptee;  }  public void mouseClicked(MouseEvent e) {    adaptee.jButtonOk_mouseClicked(e);  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -