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

📄 return.java

📁 JAVA图书管理系统有很多代码这只是很小的一部分
💻 JAVA
字号:
/*
 * Return.java
 *
 * Created on 2004年1月4日, 下午6:32
 */

package library;
import java.sql.*;
import javax.swing.JOptionPane;
/**
 *
 * @author  Administrator
 */
public class Return extends javax.swing.JFrame {
    
    /** Creates new form Return */
    public Return() {
        initComponents();
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" 生成的代码 ">//GEN-BEGIN:initComponents
    private void initComponents() {
        jLabel1 = new javax.swing.JLabel();
        codeTextField = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        bookTable = new javax.swing.JTable();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("\u8fd8\u4e66\u7cfb\u7edf");
        jLabel1.setText("\u56fe\u4e66\u7f16\u53f7\uff1a");

        codeTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                codeTextFieldKeyReleased(evt);
            }
        });

        jLabel2.setText("\u4f8b\u5982\uff1a");

        jLabel3.setText("1001");

        bookTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null}
            },
            new String [] {
                "编号", "书名", "是否借出", "类别", "出版社"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.Boolean.class, java.lang.String.class, java.lang.String.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        jScrollPane1.setViewportView(bookTable);

        jButton1.setText("\u5f52\u8fd8");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("\u8fd4\u56de");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(20, 20, 20)
                        .add(jLabel1)
                        .add(34, 34, 34)
                        .add(codeTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 64, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(36, 36, 36)
                        .add(jLabel2)
                        .add(17, 17, 17)
                        .add(jLabel3))
                    .add(layout.createSequentialGroup()
                        .addContainerGap()
                        .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 375, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(32, Short.MAX_VALUE))
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                .add(52, 52, 52)
                .add(jButton1)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 150, Short.MAX_VALUE)
                .add(jButton2)
                .add(101, 101, 101))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(31, 31, 31)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel1)
                    .add(codeTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel2)
                    .add(jLabel3))
                .add(74, 74, 74)
                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 66, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(69, 69, 69)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jButton2)
                    .add(jButton1))
                .add(65, 65, 65))
        );
        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
// TODO 将在此处添加您的处理代码:
          this.hide();
              MainFrame mf=new MainFrame();
              mf.show();
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
// TODO 将在此处添加您的处理代码:
      ResultSet rs;
          int result;
           String code=codeTextField.getText().trim();
          try{  
             Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
             Connection con=DriverManager.getConnection("jdbc:odbc:library","","");      
             Statement st=con.createStatement(); 
             String s1="Select isBorrow from bookInfo where code='"+code+"'";
             rs=st.executeQuery(s1);  
             rs.next();
            if(rs.getString("isBorrow").trim().equals("1")){
                String s2="update bookInfo set isBorrow=False,reader_code=' ' where code='"+code+"'";
                result=st.executeUpdate(s2);  
          bookTable.setValueAt(false,0,2);
             }else{
                   JOptionPane.showMessageDialog(this,"此书已还");
             }
                 st.close();
                 con.close();   
        }catch(Exception e){
            System.out.println(e.getMessage());
        }
    }//GEN-LAST:event_jButton1ActionPerformed

    private void codeTextFieldKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_codeTextFieldKeyReleased
// TODO 将在此处添加您的处理代码:
        try{
            String code=codeTextField.getText().trim();
           Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
             Connection con =DriverManager.getConnection("jdbc:odbc:library","","");
             Statement st= con.createStatement();
             if(!"".equalsIgnoreCase(code)){
              String s1="select * from bookInfo where code='"+code+"'";
             ResultSet rs=st.executeQuery(s1);
            
            if(rs.next()){
                 String name=rs.getString(2);
                 String type=rs.getString(3);
                 String press=rs.getString(4);
                boolean isBorrow=rs.getBoolean(6);
                
                 bookTable.setValueAt(code,0,0);
                 bookTable.setValueAt(name,0,1);
                 bookTable.setValueAt(new Boolean(isBorrow),0,2);
                 bookTable.setValueAt(type,0,3);
                 bookTable.setValueAt(press,0,4);
               
                
             }
             
               rs.close();
             st.close();
             con.close();
        }
          else{
               JOptionPane.showMessageDialog(null,"重新输入");;  
             }
              }catch(Exception e){
            e.getMessage();
        }
    }//GEN-LAST:event_codeTextFieldKeyReleased
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Return().setVisible(true);
            }
        });
    }
    
    // 变量声明 - 不进行修改//GEN-BEGIN:variables
    private javax.swing.JTable bookTable;
    private javax.swing.JTextField codeTextField;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JScrollPane jScrollPane1;
    // 变量声明结束//GEN-END:variables
    
}

⌨️ 快捷键说明

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