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

📄 borrow_dialog.java

📁 library-manage-system(图书管理系统),很好的学习源码。
💻 JAVA
字号:
package library;import java.awt.*;import javax.swing.*;import com.borland.jbcl.layout.*;import com.borland.dbswing.*;import com.borland.dx.sql.dataset.*;import java.awt.event.*;import java.sql.*;/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2005</p> * <p>Company: </p> * @author unascribed * @version 1.0 */public class Borrow_Dialog extends JDialog {  private JPanel panel1 = new JPanel();  private JTextField jTextField1 = new JTextField();  private JLabel jLabel1 = new JLabel();  private TableScrollPane tableScrollPane1 = new TableScrollPane();  private JdbTable jdbTable1 = new JdbTable();  private JLabel jLabel2 = new JLabel();  private JTextField jTextField2 = new JTextField();  private JButton jButton1 = new JButton();  private JButton jButton2 = new JButton();  private Database database1 = new Database();  private QueryDataSet queryDataSet1 = new QueryDataSet();  private QueryDataSet queryDataSet2 = new QueryDataSet();  private TableScrollPane tableScrollPane2 = new TableScrollPane();  private JdbTable jdbTable2 = new JdbTable();  private JLabel jLabel3 = new JLabel();  private JLabel jLabel4 = new JLabel();  private QueryDataSet queryDataSet3 = new QueryDataSet();  private GridBagLayout gridBagLayout1 = new GridBagLayout();  public Borrow_Dialog(Frame frame, String title, boolean modal) {    super(frame, title, modal);    try {      jbInit();      pack();    }    catch(Exception ex) {      ex.printStackTrace();    }  }  public Borrow_Dialog() {    this(null, "", false);  }  private void jbInit() throws Exception {    panel1.setLayout(gridBagLayout1);    jLabel1.setFont(new java.awt.Font("DialogInput", 0, 12));    jLabel1.setText("读者编号:");    jLabel2.setFont(new java.awt.Font("DialogInput", 0, 12));    jLabel2.setText("图书编号:");    jButton1.setFont(new java.awt.Font("DialogInput", 0, 12));    jButton1.setText("借出");    jButton1.addActionListener(new java.awt.event.ActionListener() {      public void actionPerformed(ActionEvent e) {        jButton1_actionPerformed(e);      }    });    jButton2.setFont(new java.awt.Font("DialogInput", 0, 12));    jButton2.setText("返回");    jButton2.addActionListener(new java.awt.event.ActionListener() {      public void actionPerformed(ActionEvent e) {        jButton2_actionPerformed(e);      }    });    database1.setConnection(new com.borland.dx.sql.dataset.ConnectionDescriptor("jdbc:odbc:lib", "", "", false, "sun.jdbc.odbc.JdbcOdbcDriver"));    jdbTable1.setDataSet(queryDataSet1);    jdbTable1.setRowHeaderVisible(false);    jdbTable1.setEditable(false);    jTextField1.addKeyListener(new java.awt.event.KeyAdapter() {      public void keyReleased(KeyEvent e) {        jTextField1_keyReleased(e);      }    });    queryDataSet1.setQuery(new com.borland.dx.sql.dataset.QueryDescriptor(database1, "select code as 编号,name as 姓名,sex as 性别 ,type as 类型 ,dept as 部门 ,phone " +      "as 电话 from readerInfo where code = \'111111111111\'", null, true, Load.ALL));    queryDataSet2.setQuery(new com.borland.dx.sql.dataset.QueryDescriptor(database1, "select code as 编号,name as 书名, isBorrow as 是否借出 ,type as 类别,press " +      "as 出版社,writer as 作者, reader_code as 借阅人编号 from bookInfo where code " +      "= \'111111111111\'", null, true, Load.ALL));    jTextField2.addKeyListener(new java.awt.event.KeyAdapter() {      public void keyReleased(KeyEvent e) {        jTextField2_keyReleased(e);      }    });    jdbTable2.setEnabled(false);    jdbTable2.setDataSet(queryDataSet2);    jLabel3.setFont(new java.awt.Font("DialogInput", 0, 12));    jLabel3.setText("例如:001");    jLabel4.setFont(new java.awt.Font("DialogInput", 0, 12));    jLabel4.setText("例如:1001");    this.setTitle("借书");    getContentPane().add(panel1);    panel1.add(jLabel1,  new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0            ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(27, 17, 0, 0), 0, 0));    panel1.add(jTextField1,  new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0            ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(27, 14, 0, 0), 93, 3));    panel1.add(tableScrollPane1,  new GridBagConstraints(0, 1, 4, 1, 1.0, 1.0            ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(13, 17, 0, 16), 144, -379));    panel1.add(tableScrollPane2,  new GridBagConstraints(0, 3, 4, 1, 1.0, 1.0            ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(11, 17, 0, 16), 123, -370));    panel1.add(jLabel3,  new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0            ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(27, 37, 0, 9), 0, 0));    panel1.add(jLabel2,  new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0            ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(35, 17, 0, 0), 0, 0));    panel1.add(jTextField2,  new GridBagConstraints(1, 2, 1, 1, 1.0, 0.0            ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(32, 20, 0, 0), 87, 0));    panel1.add(jLabel4,  new GridBagConstraints(2, 2, 1, 1, 0.0, 0.0            ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(33, 39, 0, 0), 0, 0));    panel1.add(jButton2,  new GridBagConstraints(3, 4, 1, 1, 0.0, 0.0            ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(27, 83, 33, 193), 0, 0));    panel1.add(jButton1,  new GridBagConstraints(2, 4, 1, 1, 0.0, 0.0            ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(29, 0, 33, 46), 0, 0));    tableScrollPane2.getViewport().add(jdbTable2, null);    tableScrollPane1.getViewport().add(jdbTable1, null);  }  void jTextField1_keyReleased(KeyEvent e) {//JOptionPane.showMessageDialog(this,jTextField1.getText(),"提示",JOptionPane.ERROR_MESSAGE);    if(queryDataSet1.isOpen()) queryDataSet1.close();    queryDataSet1.setQuery(new com.borland.dx.sql.dataset.QueryDescriptor(database1, "select code as 编号,name as 姓名,sex as 性别 ,type as 类型 ,dept as 部门 ,phone as 电话 from readerInfo where code =\'"+ jTextField1.getText()+"\'" , null, true, Load.ALL));    queryDataSet1.open();  }  void jTextField2_keyReleased(KeyEvent e) {    if(queryDataSet2.isOpen()) queryDataSet2.close();    queryDataSet2.setQuery(new com.borland.dx.sql.dataset.QueryDescriptor(database1, "select code as 编号,name as 书名,  isBorrow as 是否借出 ,type as 类别,press as 出版社,writer as 作者,reader_code as 借阅人编号 from bookInfo where code =\'"+ jTextField2.getText()+"\'" , null, true, Load.ALL));    queryDataSet2.open();    //queryDataSet2.close();  }  void jButton2_actionPerformed(ActionEvent e) {    this.dispose();  }  void jButton1_actionPerformed(ActionEvent e) {    if(!queryDataSet2.isOpen())queryDataSet2.open();    if(queryDataSet2.getRowCount()==0)    {       JOptionPane.showMessageDialog(this,"您要借的图书不存在!","提示",JOptionPane.ERROR_MESSAGE);       return;    }    if(queryDataSet2.getBoolean("是否借出"))    {       JOptionPane.showMessageDialog(this,"您要借的图书已经借出!","提示",JOptionPane.ERROR_MESSAGE);       return;    }    if(!queryDataSet1.isOpen())queryDataSet1.open();    if(queryDataSet1.getRowCount()==0)    {       JOptionPane.showMessageDialog(this,"该读者不存在!","提示",JOptionPane.ERROR_MESSAGE);       return;    }    try    {      Statement sql = database1.createStatement() ;      sql.executeUpdate("update bookInfo set isBorrow  = true,reader_code = \'"+jTextField1.getText()+"\'  where code =\'"+ jTextField2.getText()+"\'" );      JOptionPane.showMessageDialog(this,"图书借出成功!","提示",JOptionPane.INFORMATION_MESSAGE);      queryDataSet2.refresh();    }catch(Exception ex)   {      JOptionPane.showMessageDialog(this,"图书借出失败!","提示",JOptionPane.INFORMATION_MESSAGE);   }  }}

⌨️ 快捷键说明

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