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

📄 maindemouserframe2.java~36~

📁 该文件中包含有源代码及一部分的文档,该系统是一个小型的英语单词字典的系统.
💻 JAVA~36~
📖 第 1 页 / 共 2 页
字号:
package logindemo;

import java.awt.*;

import javax.swing.*;
import javax.swing.event.*;
import javax.swing.JComboBox;
import com.borland.jbcl.layout.BoxLayout2;
import java.awt.event.*;
import java.awt.Dimension;
import java.sql.ResultSet;
import java.sql.SQLException;


/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2007</p>
 *
 * <p>Company: </p>
 *
 * @author not attributable
 * @version 1.0
 */
public class MainDemoUserFrame2 extends JFrame {
    BorderLayout borderLayout1 = new BorderLayout();
    JPanel contentPane;
    JPanel jPanel1 = new JPanel();
    JPanel jPanel2 = new JPanel();
    CardLayout cardLayout1 = new CardLayout();
    JPanel jPanel3 = new JPanel();
    JPanel jPanel4 = new JPanel();
    JPanel jPanel5 = new JPanel();
    JPanel jPanel6 = new JPanel();
    JLabel jLabel1 = new JLabel();
    JTextField jTextField1 = new JTextField();
    JButton jButton1 = new JButton();
    JButton jButton2 = new JButton();
    JComboBox jComboBox1 = new JComboBox();
    JLabel jLabel2 = new JLabel();
    JButton jButton3 = new JButton();
    JComboBox jComboBox2 = new JComboBox();
    JLabel jLabel3 = new JLabel();
    JComboBox jComboBox3 = new JComboBox();
    JButton jButton4 = new JButton();
    JLabel jLabel4 = new JLabel();
    BoxLayout2 boxLayout21 = new BoxLayout2();
    JScrollPane jScrollPane1 = new JScrollPane();
    JMenuBar jMenuBar1 = new JMenuBar();
    JMenu jMenu1 = new JMenu();
    JMenu jMenu2 = new JMenu();
    JMenu jMenu4 = new JMenu();
    JMenuItem jMenuItem1 = new JMenuItem();
    JMenuItem jMenuItem2 = new JMenuItem();
    JMenuItem jMenuItem3 = new JMenuItem();
    JMenuItem jMenuItem4 = new JMenuItem();
    JMenuItem jMenuItem5 = new JMenuItem();
    JMenu jMenu5 = new JMenu();
    JMenuItem jMenuItem6 = new JMenuItem();
    JMenuItem jMenuItem7 = new JMenuItem();
    JMenuItem jMenuItem8 = new JMenuItem();
    JMenuItem jMenuItem9 = new JMenuItem();
    JTextArea jTextArea1 = new JTextArea();
    public MainDemoUserFrame2() {
        try {
            jbInit();
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }

    private void jbInit() throws Exception {
        contentPane = (JPanel) getContentPane();
        contentPane.setLayout(borderLayout1);
        this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        this.setJMenuBar(jMenuBar1);
        setSize(new Dimension(495, 403));
        setTitle("欢迎进入图书查询系统");
        jPanel1.setLayout(cardLayout1);
        jLabel1.setText("请输入书名");
        jButton1.setText("搜索");
        jButton1.addActionListener(new
                                   MainDemoUserFrame2_jButton1_actionAdapter(this));
        jButton2.setText("搜索 ");
        jButton2.addActionListener(new
                                   MainDemoUserFrame2_jButton2_actionAdapter(this));
        jLabel2.setText("请输入作者");
        jButton3.setText("搜索");
        jButton3.addActionListener(new
                                   MainDemoUserFrame2_jButton3_actionAdapter(this));
        jLabel3.setText("请选择出版社");
        jButton4.setText("搜索");
        jButton4.addActionListener(new
                                   MainDemoUserFrame2_jButton4_actionAdapter(this));
        jLabel4.setText("请选择类别");
        jPanel2.setLayout(boxLayout21);
        this.setJMenuBar(jMenuBar1);
        jMenu1.setText("查询");
        jMenu2.setText("编辑");
        jMenu4.setText("文件");
        jMenuItem1.setText("按书名查询");
        jMenuItem1.addActionListener(new
                MainDemoUserFrame2_jMenuItem1_actionAdapter(this));
        jMenuItem2.setText("按作者查询");
        jMenuItem2.addActionListener(new
                MainDemoUserFrame2_jMenuItem2_actionAdapter(this));
        jMenuItem3.setText("按出版社查询");
        jMenuItem3.addActionListener(new
                MainDemoUserFrame2_jMenuItem3_actionAdapter(this));
        jMenuItem4.setText("按类别查询");
        jMenuItem4.addActionListener(new
                MainDemoUserFrame2_jMenuItem4_actionAdapter(this));
        jMenuItem5.setText("退出");
        jMenuItem5.addActionListener(new
                MainDemoUserFrame2_jMenuItem5_actionAdapter(this));
        jPanel3.addComponentListener(new
                MainDemoUserFrame2_jPanel3_componentAdapter(this));
        jPanel4.addComponentListener(new
                MainDemoUserFrame2_jPanel4_componentAdapter(this));
        jTextField1.setPreferredSize(new Dimension(100, 20));
        jComboBox1.setPreferredSize(new Dimension(100, 23));
        jComboBox2.setPreferredSize(new Dimension(100, 23));
        jComboBox3.setPreferredSize(new Dimension(100, 23));
        jMenu5.setText("帮助");
        jMenuItem6.setText("关于");
        jMenuItem6.addActionListener(new
                MainDemoUserFrame2_jMenuItem6_actionAdapter(this));
        jMenuItem7.setText("录入");
        jMenuItem7.addActionListener(new
                MainDemoUserFrame2_jMenuItem7_actionAdapter(this));
        jMenuItem8.setText("修改");
        jMenuItem8.addActionListener(new
                MainDemoUserFrame2_jMenuItem8_actionAdapter(this));
        jMenuItem9.setText("删除");
        jMenuItem9.addActionListener(new
                MainDemoUserFrame2_jMenuItem9_actionAdapter(this));
        jPanel1.addComponentListener(new
                MainDemoUserFrame2_jPanel1_componentAdapter(this));
        jPanel5.addComponentListener(new
                MainDemoUserFrame2_jPanel5_componentAdapter(this));
        jPanel6.addComponentListener(new
                MainDemoUserFrame2_jPanel6_componentAdapter(this));
        contentPane.add(jPanel2, java.awt.BorderLayout.CENTER);
        contentPane.add(jPanel1, java.awt.BorderLayout.NORTH);
        jPanel1.add(jPanel3, "jPanel3");
        jPanel3.add(jLabel1);
        jPanel3.add(jTextField1);
        jPanel3.add(jButton1);
        jPanel1.add(jPanel4, "jPanel4");
        jPanel4.add(jLabel2);
        jPanel4.add(jComboBox1);
        jPanel4.add(jButton2);
        jPanel1.add(jPanel5, "jPanel5");
        jPanel5.add(jLabel3);
        jPanel5.add(jLabel3);
        jPanel5.add(jComboBox2);
        jPanel5.add(jButton3);
        jPanel1.add(jPanel6, "jPanel6");
        jPanel6.add(jLabel4);
        jPanel6.add(jComboBox3);
        jPanel6.add(jButton4);
        jPanel2.add(jScrollPane1);
        jScrollPane1.getViewport().add(jTextArea1);
        jMenuBar1.add(jMenu4);
        jMenuBar1.add(jMenu1);
        jMenuBar1.add(jMenu2);
        jMenuBar1.add(jMenu5);
        jMenu1.add(jMenuItem1);
        jMenu1.add(jMenuItem2);
        jMenu1.add(jMenuItem3);
        jMenu1.add(jMenuItem4);
        jMenu4.add(jMenuItem5);
        jMenu5.add(jMenuItem6);
        jMenu2.add(jMenuItem7);
        jMenu2.add(jMenuItem8);
        jMenu2.add(jMenuItem9);
    }

    public void jMenuItem1_actionPerformed(ActionEvent e) {
        cardLayout1.show(jPanel1,"jPanel3");
    }

    public void jMenuItem2_actionPerformed(ActionEvent e) {
        cardLayout1.show(jPanel1,"jPanel4");
    }

    public void jMenuItem3_actionPerformed(ActionEvent e) {
        cardLayout1.show(jPanel1,"jPanel5");
    }

    public void jMenuItem4_actionPerformed(ActionEvent e) {
       cardLayout1.show(jPanel1,"jPanel6");
    }

    public void jMenuItem5_actionPerformed(ActionEvent e) {
          System.exit(0);
    }

    public void jPanel3_componentShown(ComponentEvent componentEvent) {

    }

    public void jPanel4_componentShown(ComponentEvent componentEvent) {
     Database database = new Database();
     String sql = "select distinct author from book";
     ResultSet rs = database.query(sql);
     try {
         while (rs.next()) {
             jComboBox1.addItem(rs.getString(1));
         }
     } catch (SQLException ex) {
         ex.printStackTrace();
     }

    }

    public void jButton1_actionPerformed(ActionEvent e) {
        Database database = new Database();
     String bookname = jTextField1.getText().trim();
     String sql = "select * from book where bookname = '"+bookname+"'";
     ResultSet rs = database.query(sql);
     try {
         String text = "";
         while (rs.next()) {
            text =  "书名:"+ rs.getString(2)+"    "
                           +"作者:"+rs.getString(4)+"    "
                           +"出版社:"+rs.getString(7)+"   "
                           +"价格:"+rs.getString(8)+"\n"+text;
         }
         if(text.equals("")){
            text = "无此书!";
         }
         jTextArea1.setText(text);
     } catch (SQLException ex) {
         ex.printStackTrace();
     }

    }

    public void jMenuItem6_actionPerformed(ActionEvent e) {
        Frame1_AboutBox dlg = new Frame1_AboutBox(this);
        Dimension dlgSize = dlg.getPreferredSize();
        Dimension frmSize = getSize();
        Point loc = getLocation();
        dlg.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x,
              (frmSize.height - dlgSize.height) / 2 + loc.y);
        dlg.setModal(true);
        dlg.pack();
        dlg.setVisible(true);

    }

    public void jPanel1_componentShown(ComponentEvent e) {

    }

    public void jButton2_actionPerformed(ActionEvent e) {
        String author = (String)jComboBox1.getSelectedItem();
        Database database = new Database();
        String sql = "select * from book where author = '"+author+"'";
        ResultSet rs = database.query(sql);
        try {
           String text = "";
            while (rs.next()) {
              text =  "书名:"+ rs.getString(2)+"    "
                           +"作者:"+rs.getString(4)+"    "
                           +"出版社:"+rs.getString(7)+"   "
                           +"价格:"+rs.getString(8)+"\n"+text;
         }
           if(text.equals("")){
            text = "无此书!";
         }
            jTextArea1.setText(text);
        } catch (SQLException ex) {
           ex.printStackTrace();
     }

    }

    public void jPanel5_componentShown(ComponentEvent e) {
        Database database = new Database();
        String sql = "select distinct Publish from book";
        ResultSet rs = database.query(sql);
         try {
              while (rs.next()) {
                jComboBox2.addItem(rs.getString(1));
        }
        } catch (SQLException ex) {
         ex.printStackTrace();
      }

    }

    public void jButton3_actionPerformed(ActionEvent e) {
        String Publish = (String)jComboBox2.getSelectedItem();
        Database database = new Database();
        String sql = "select * from book where Publish = '"+Publish+"'";
        ResultSet rs = database.query(sql);
         try {
          String text = "";
             while (rs.next()) {
              text =  "书名:"+ rs.getString(2)+"    "

                   +"作者:"+rs.getString(4)+"    "
                   +"出版社:"+rs.getString(7)+"   "

⌨️ 快捷键说明

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