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

📄 booklist.java

📁 教材管理系统
💻 JAVA
字号:
package bookmanager;
import javax.swing.*;
import com.borland.jbcl.layout.*;
import java.awt.*;
import java.sql.*; //引入包java.sql.*;
import javax.swing.table.*; //引入包sqljavax.swing.table.*;
import java.util.*; //引入包sqljava.util*;
import java.awt.event.*;
import com.borland.dbswing.*;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2003</p>
 * <p>Company: </p>
 * @author not attributable
 * @version 1.0
 */

public class bookList
    extends JFrame {
  //定义结果集
  ResultSet rs;
  //定义数据库操作对象
  private DBManager db = new DBManager();
  String searchType =new String();
  Vector tempvector = new Vector(1, 1);
  //定义DefaultTableModel模型
  DefaultTableModel model = new DefaultTableModel();
  //定义JTable为DefaultTableModel的实例model模式
  JTable jTableResult = new JTable(model);

  XYLayout xYLayout1 = new XYLayout();
  JScrollPane jScrollPane1 = new JScrollPane();
  JButton jBOK = new JButton();
  JRadioButton jRbybookname = new JRadioButton();
  JRadioButton jRbyauthor = new JRadioButton();
  JRadioButton jRbytype = new JRadioButton();
  JRadioButton jRbyisbn = new JRadioButton();
  JTextField jTContent = new JTextField();
   ButtonGroup group=new ButtonGroup();
  JLabel jLabel1 = new JLabel();
  JLabel jLabel2 = new JLabel();

  public bookList() {
    try {
      jbInit();
    }
    catch (Exception e) {
      e.printStackTrace();
    }
  }

  public static void main(String[] args) {
    bookList bookList = new bookList();
  }

  private void jbInit() throws Exception {
    xYLayout1.setWidth(683);
    xYLayout1.setHeight(550);
    this.getContentPane().setLayout(xYLayout1);
    jBOK.setText("查询");
    jBOK.addMouseListener(new bookList_jBOK_mouseAdapter(this));
    jBOK.setBackground(UIManager.getColor("inactiveCaptionText"));
    jBOK.setFont(new java.awt.Font("Dialog", 0, 16));
    // model中加入列名
    model.addColumn("ISBN号");
    model.addColumn("书名");
    model.addColumn("出版社");
    model.addColumn("作者");
    model.addColumn("版本号");
    model.addColumn("出版日期");
    model.addColumn("定价");
    model.addColumn("类别");
    model.addColumn("数量");
    model.addColumn("所在仓库号");


    this.getContentPane().setBackground(UIManager.getColor("inactiveCaptionText"));
    this.setTitle("教材信息查询");
    jRbybookname.setBackground(UIManager.getColor("inactiveCaptionText"));
    jRbybookname.setFont(new java.awt.Font("Dialog", 0, 16));
    jRbybookname.setText("按书名查询");
    jRbyauthor.setBackground(UIManager.getColor("inactiveCaptionText"));
    jRbyauthor.setFont(new java.awt.Font("Dialog", 0, 16));
    jRbyauthor.setText("按作者查询");
    jRbytype.setBackground(UIManager.getColor("inactiveCaptionText"));
    jRbytype.setFont(new java.awt.Font("Dialog", 0, 16));
    jRbytype.setText("按出版社查询");
    jRbyisbn.setBackground(UIManager.getColor("inactiveCaptionText"));
    jRbyisbn.setFont(new java.awt.Font("Dialog", 0, 16));
    jRbyisbn.setText("按ISBN号查询");
    jTContent.setFont(new java.awt.Font("Dialog", 0, 16));
    jLabel1.setFont(new java.awt.Font("Dialog", 0, 16));
    jLabel1.setText("请输入查询条件:");
    jScrollPane1.getViewport().setBackground(UIManager.getColor("inactiveCaptionText"));
    jLabel2.setFont(new java.awt.Font("Dialog", 0, 30));
    jLabel2.setText("教材信息查询");

    this.getContentPane().add(jScrollPane1,    new XYConstraints(27, 179, 628, 337));
    this.getContentPane().add(jLabel2,     new XYConstraints(224, 24, 186, 39));
    this.getContentPane().add(jTContent,  new XYConstraints(338, 125, 223, 28));
    this.getContentPane().add(jBOK, new XYConstraints(575, 126, 81, 28));
    this.getContentPane().add(jRbybookname,   new XYConstraints(41, 84, -1, -1));
    this.getContentPane().add(jRbyauthor,  new XYConstraints(150, 84, 110, 27));
    this.getContentPane().add(jLabel1, new XYConstraints(50, 126, 230, 28));
    this.getContentPane().add(jRbyisbn, new XYConstraints(258, 84, 129, 24));
    this.getContentPane().add(jRbytype,    new XYConstraints(385, 86, 138, 19));
    jScrollPane1.getViewport().add(jTableResult, null);
    jRbybookname.addActionListener(new search_jRbybookname_actionAdapter(this));
    jRbyauthor.addActionListener(new search_jRbyauthor_actionAdapter(this));
    jRbyisbn.addActionListener(new search_jRbyisbn_actionAdapter(this));
    jRbytype.addActionListener(new search_jRbytype_actionAdapter(this));
    group.add(jRbytype);
    group.add(jRbyisbn);
    group.add(jRbyauthor);
    group.add(jRbybookname);
  }
  //设置标签内容
 void setLabelText(String content){
   jLabel1.setText(content);
 }

  void setType(String i){
   searchType=i;
 }

  void jRbybookname_actionPerformed(ActionEvent e) {
        jLabel1.setText("请输入要查询教材名称:");
        jTContent.setEnabled(true);
        setType("bookname");
   }

   void jRbyauthor_actionPerformed(ActionEvent e) {
     jLabel1.setText("请输入要查询教材的作者:");
     jTContent.setEnabled(true);
     setType("author");
   }

   void jRbyisbn_actionPerformed(ActionEvent e) {
     jLabel1.setText("请输入要查询教材的ISBN号:");
     jTContent.setEnabled(true);
     setType("isbn");
   }

   void jRbytype_actionPerformed(ActionEvent e) {
        jLabel1.setText("请输入要查询的出版社名:");
        jTContent.setEnabled(true);
        setType("type");
      }

//加载数据
  void jBOK_mouseClicked(MouseEvent e) {
    String strSQL;
    //
    boolean isFirst = true;
    //检验书目是否存在
    strSQL = "select * from Books ";
    if (!jTContent.getText().trim().equals("")) {
      strSQL = strSQL + " where ISBN='" + jTContent.getText().trim() +
          "'";
      isFirst = false;
    }
    if (!jTContent.getText().trim().equals("")) {
      if (isFirst) {
        strSQL = strSQL + " where bookname='" + jTContent.getText().trim() +
            "'";
        isFirst = false;
      }
      else {
        strSQL = strSQL + " and bookname='" + jTContent.getText().trim() +
            "'";
      }
    }
    if (!jTContent.getText().trim().equals("")) {
      if (isFirst) {
        strSQL = strSQL + " where type='" + jTContent.getText().trim() +
            "'";
        isFirst = false;
      }
      else {
        strSQL = strSQL + " and type='" + jTContent.getText().trim() +
            "'";
      }

    }
    strSQL = "select * from orderbook ";
    if (!jTContent.getText().trim().equals("")) {
      if (isFirst) {
        strSQL = strSQL + " where orderuser='" + jTContent.getText().trim() +
            "'";
        isFirst = false;
      }
      else {
        strSQL = strSQL + " and orderuser='" + jTContent.getText().trim() +
            "'";
      }

    }



    rs = db.getResult(strSQL);
    boolean isexist = false;
    try {
      isexist = rs.first();
    }
    catch (SQLException ex1) {
      JOptionPane.showMessageDialog(null, "ex1.toString() " + ex1.toString());
    }
    //若书目不存在,提示警告信息提醒用户
    if (!isexist) {
      JOptionPane.showMessageDialog(null, "书库中没有书目,请确认!");
      return;
    }
    //若存在,执行以下操作
    //清空model中的对象
    for (int n = model.getRowCount() - 1; n >= 0; n--)
      model.removeRow(n);

    try {
      rs.beforeFirst();
      while (rs.next()) {
        tempvector = new Vector(1, 1);
        tempvector.add(rs.getString("ISBN"));
        tempvector.add(rs.getString("name"));
        tempvector.add(rs.getString("Press"));
        tempvector.add(rs.getString("Author"));
        tempvector.add(rs.getString("type"));
        tempvector.add(rs.getString("Pressdate"));
        tempvector.add(rs.getString("Price"));
        tempvector.add(rs.getString("Vnum"));
        tempvector.add(rs.getString("num"));
        tempvector.add(rs.getString("roomnum"));
        model.addRow(tempvector);
      }
    }
    catch (SQLException ex) {
      JOptionPane.showMessageDialog(null, "ex.toString() :" + ex.toString());
    }

  }
}

class bookList_jBOK_mouseAdapter
    extends java.awt.event.MouseAdapter {
  bookList adaptee;

  bookList_jBOK_mouseAdapter(bookList adaptee) {
    this.adaptee = adaptee;
  }

  public void mouseClicked(MouseEvent e) {
    adaptee.jBOK_mouseClicked(e);
  }
}
class search_jRbybookname_actionAdapter implements java.awt.event.ActionListener {
  bookList  adaptee;

  search_jRbybookname_actionAdapter(bookList  adaptee) {
    this.adaptee = adaptee;
  }
  public void actionPerformed(ActionEvent e) {
    adaptee.jRbybookname_actionPerformed(e);
  }
}
class search_jRbyauthor_actionAdapter implements java.awt.event.ActionListener {
  bookList  adaptee;

  search_jRbyauthor_actionAdapter(bookList  adaptee) {
    this.adaptee = adaptee;
  }
  public void actionPerformed(ActionEvent e) {
    adaptee.jRbyauthor_actionPerformed(e);
  }
}
class search_jRbyisbn_actionAdapter implements java.awt.event.ActionListener {
  bookList  adaptee;

  search_jRbyisbn_actionAdapter(bookList  adaptee) {
    this.adaptee = adaptee;
  }
  public void actionPerformed(ActionEvent e) {
    adaptee.jRbyisbn_actionPerformed(e);
  }
}
class search_jRbytype_actionAdapter implements java.awt.event.ActionListener {
  bookList  adaptee;

  search_jRbytype_actionAdapter(bookList  adaptee) {
    this.adaptee = adaptee;
  }
  public void actionPerformed(ActionEvent e) {
    adaptee.jRbytype_actionPerformed(e);
  }
}

⌨️ 快捷键说明

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