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

📄 maindemoframe1.java~144~

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

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import com.borland.jbcl.layout.*;
import java.awt.Dimension;
import java.awt.BorderLayout;
import javax.swing.border.Border;
import java.sql.ResultSet;
import java.sql.*;

/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2007</p>
 *
 * <p>Company: </p>
 *
 * @author not attributable
 * @version 1.0
 */
//读者主界面
public class MainDemoframe1 extends JFrame {
    BorderLayout borderLayout1 = new BorderLayout();
    JPanel contentPane;
    JPanel jPanel1 = new JPanel();
    JPanel jPanel2 = new JPanel();
    JScrollPane jScrollPane1 = new JScrollPane();
    BoxLayout2 boxLayout21 = new BoxLayout2();
    Border border1 = BorderFactory.createEtchedBorder(Color.white,
            new Color(165, 163, 151));
    CardLayout cardLayout1 = new CardLayout();
    JPanel jPanel3 = new JPanel();
    JPanel jPanel4 = new JPanel();
    JPanel jPanel5 = new JPanel();
    JButton jbSerach = new JButton();
    JPanel jPanel6 = new JPanel();
    JLabel jLabel1 = new JLabel();
    JButton jButton2 = new JButton();
    JComboBox jComboBox2 = new JComboBox();
    JLabel jLabel2 = new JLabel();
    JButton jButton3 = new JButton();
    JComboBox jComboBox3 = new JComboBox();
    JLabel jLabel3 = new JLabel();
    JButton jButton4 = new JButton();
    JComboBox jComboBox4 = new JComboBox();
    JLabel jLabel4 = new JLabel();
    JMenuBar jMenuBar1 = new JMenuBar();
    JMenu jMenu1 = new JMenu();
    JMenu jMenu2 = new JMenu();
    JMenu jMenu3 = new JMenu();
    JMenuItem jMenuItem1 = new JMenuItem();
    JMenuItem jMenuItem2 = new JMenuItem();
    JMenuItem jMenuItem3 = new JMenuItem();
    JMenuItem jMenuItem4 = new JMenuItem();
    JTextField jtBook_name = new JTextField();
    JMenuItem jMenuItem5 = new JMenuItem();
    JMenuItem jMenuItem6 = new JMenuItem();
    JTextArea jTextArea1 = new JTextArea();
    public MainDemoframe1() {
        try {
            jbInit();
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }
     /**
      * Component initialization.
      *
      * @throws java.lang.Exception
      */
     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("欢迎进入图书查询系统");
        jPanel2.setLayout(boxLayout21);
        jPanel1.setBorder(border1);
        jPanel1.setLayout(cardLayout1);
        jbSerach.setText("搜索");
        jbSerach.addActionListener(new MainDemoframe1_jButton1_actionAdapter(this));
        jLabel1.setText("请输入书名:");
        jButton2.setText("搜索");
        jButton2.addActionListener(new MainDemoframe1_jButton2_actionAdapter(this));
        jLabel2.setText("请输入作者:");
        jButton3.setText("搜索");
        jButton3.addActionListener(new MainDemoframe1_jButton3_actionAdapter(this));
        jLabel3.setText("请输入出版社:");
        jButton4.setText("搜索");
        jButton4.addActionListener(new MainDemoframe1_jButton4_actionAdapter(this));
        jLabel4.setText("请输入类别:");
        jMenu1.setText("查询");
        jMenuItem1.setText("按书名查询");
        jMenuItem1.addActionListener(new
                                     MainDemoframe1_jMenuItem1_actionAdapter(this));
        jMenuItem2.setText("按作者查询");
        jMenuItem2.addActionListener(new
                                     MainDemoframe1_jMenuItem2_actionAdapter(this));
        jMenuItem3.setText("按出版社查询");
        jMenuItem3.addActionListener(new
                                     MainDemoframe1_jMenuItem3_actionAdapter(this));
        jMenuItem4.setText("按类别查询");
        jMenuItem4.addActionListener(new
                                     MainDemoframe1_jMenuItem4_actionAdapter(this));
        jPanel3.addComponentListener(new
                                     MainDemoframe1_jPanel3_componentAdapter(this));
        jPanel4.addComponentListener(new
                                     MainDemoframe1_jPanel4_componentAdapter(this));
        jMenu2.setText("帮助");
        jMenu3.setText("文件");
        jtBook_name.setPreferredSize(new Dimension(100, 20));
        jtBook_name.addActionListener(new
                                      MainDemoframe1_jTextField1_actionAdapter(this));
        jMenuItem5.setText("关于");
        jMenuItem5.addActionListener(new
                                     MainDemoframe1_jMenuItem5_actionAdapter(this));
        jMenuItem6.setText("退出");
        jMenuItem6.addActionListener(new
                                     MainDemoframe1_jMenuItem6_actionAdapter(this));
        jComboBox2.setPreferredSize(new Dimension(100, 23));
        jComboBox2.addActionListener(new
                                     MainDemoframe1_jComboBox2_actionAdapter(this));
        jComboBox3.setPreferredSize(new Dimension(100, 23));
        jComboBox3.addActionListener(new
                                     MainDemoframe1_jComboBox3_actionAdapter(this));
        jComboBox4.setPreferredSize(new Dimension(100, 23));
        jPanel5.addComponentListener(new
                                     MainDemoframe1_jPanel5_componentAdapter(this));
        jPanel6.addComponentListener(new
                                     MainDemoframe1_jPanel6_componentAdapter(this));
        contentPane.add(jPanel2, java.awt.BorderLayout.CENTER);
        jPanel2.add(jScrollPane1);
        contentPane.add(jPanel1, java.awt.BorderLayout.NORTH);
        jPanel1.add(jPanel3, "jPanel3");
        jPanel3.add(jLabel1);
        jPanel3.add(jtBook_name);
        jPanel3.add(jbSerach);
        jPanel1.add(jPanel4, "jPanel4");
        jPanel4.add(jLabel2);
        jPanel4.add(jComboBox2);
        jPanel4.add(jButton2);
        jPanel1.add(jPanel5, "jPanel5");
        jPanel5.add(jLabel3);
        jPanel5.add(jComboBox3);
        jPanel5.add(jButton3);
        jPanel1.add(jPanel6, "jPanel6");
        jPanel6.add(jLabel4);
        jPanel6.add(jComboBox4);
        jPanel6.add(jButton4);
        jMenuBar1.add(jMenu3);
        jMenuBar1.add(jMenu1);
        jMenuBar1.add(jMenu2);
        jMenu1.add(jMenuItem1);
        jMenu1.add(jMenuItem2);
        jMenu1.add(jMenuItem3);
        jMenu1.add(jMenuItem4);
        jMenu2.add(jMenuItem5);
        jMenu3.add(jMenuItem6);
        jScrollPane1.getViewport().add(jTextArea1);
    }

    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 jPanel3_componentShown(ComponentEvent e) {
    }

    public void jPanel4_componentShown(ComponentEvent e) {
        Database database = new Database();
        String sql = "select distinct author from book";
        ResultSet rs = database.query(sql);
        try {
            while (rs.next()) {
                jComboBox2.addItem(rs.getString(1));
            }
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
    }
//连接数据库
    public void jButton1_actionPerformed(ActionEvent e) {
        Database database = new Database();
        String bookname = jtBook_name.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 jMenuItem5_actionPerformed(ActionEvent actionEvent) {
        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 jMenuItem6_actionPerformed(ActionEvent e) {
        System.exit(0);
    }

    public void jTextField1_actionPerformed(ActionEvent e) {

    }

    public void jButton2_actionPerformed(ActionEvent actionEvent) {
       String author = (String)jComboBox2.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 jComboBox3_actionPerformed(ActionEvent e) {

    }

    public void jComboBox2_actionPerformed(ActionEvent e) {

    }

    public void jButton3_actionPerformed(ActionEvent e) {
     String Publish = (String)jComboBox3.getSelectedItem();

⌨️ 快捷键说明

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