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

📄 panelretrieval.java

📁 学员信息管理系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                    labelWord = new JLabel();                    panelCondition.add(labelWord);                    labelWord.setText("条件字段");                    labelWord.setBounds(210, 14, 49, 21);                    labelWord.setFont(new java.awt.Font("宋体", 0, 12));                }                {                    labelJudge = new JLabel();                    panelCondition.add(labelJudge);                    labelJudge.setText("判断符号");                    labelJudge.setBounds(294, 14, 49, 21);                    labelJudge.setFont(new java.awt.Font("宋体", 0, 12));                }                {                    labelCondition = new JLabel();                    panelCondition.add(labelCondition);                    labelCondition.setText("查询条件");                    labelCondition.setBounds(378, 14, 49, 21);                    labelCondition.setFont(new java.awt.Font("宋体", 0, 12));                }                {                    labelHelp = new JLabel();                    panelCondition.add(labelHelp);                    labelHelp.setText("操作说明");                    labelHelp.setBounds(525, 14, 49, 21);                    labelHelp.setFont(new java.awt.Font("宋体", 0, 12));                }                {                    scrollPaneInformation = new JScrollPane();                    panelCondition.add(scrollPaneInformation);                    scrollPaneInformation.setBounds(105, 42, 84, 133);                    {                        ListModel listInformationModel = new DefaultComboBoxModel();                        listInformation = new JList();                        scrollPaneInformation.setViewportView(listInformation);                        listInformation.setModel(listInformationModel);                        listInformation.setBounds(7, 49, 84, 133);                        listInformation.setFont(new java.awt.Font("宋体", 0, 12));                    }                }            }            {                panelDown = new JPanel();                this.add(panelDown);                panelDown.setBackground(new java.awt.Color(236, 233, 216));                {                    buttonSubmit = new JButton();                    panelDown.add(buttonSubmit);                    buttonSubmit.setText("开始查询");                    buttonSubmit.setFont(new java.awt.Font("宋体", 0, 12));                    buttonSubmit.addActionListener(new ActionListener() {                        public void actionPerformed(ActionEvent evt) {                            buttonSubmitActionPerformed(evt);                        }                    });                }            }        } catch (Exception e) {            e.printStackTrace();        }    }    public void initial() {        /*         * SQLOperate.selectAllFromData("Students", tableStudents);         * ObjectClasses.tableStudentsRowCountFile =         * ObjectClasses.tableStudentsRowFile.setTableRowFile(ObjectClasses.tableStudentsRowCount);         * this.scrollPaneResult.setRowHeaderView(ObjectClasses.tableStudentsRowCountFile);         */    }    /**     * 查询表被选择时的事件处理方法     *      * @param evt     */    private void comboBoxTableItemStateChanged(ItemEvent evt) {        if (this.comboBoxTable.getSelectedItem().equals("请选择...")) {            listInformation.removeAll();            listInformation.setListData(new String[] {});            comboBoxWord.removeAllItems();            comboBoxWord.addItem("请选择...");        }        if (this.comboBoxTable.getSelectedItem().equals("学生表")) {            // System.out.println("学生表");            listInformation.removeAll();            listInformation.setListData(studentsItem);            comboBoxWord.removeAllItems();            comboBoxWord.addItem("请选择...");            for (int i = 0; i < studentsItem.length; i++) {                // System.out.println(item[i]);                comboBoxWord.addItem(studentsItem[i]);            }            this.tableName = "Students";        }        if (this.comboBoxTable.getSelectedItem().equals("教师表")) {            // System.out.println("教师表");            listInformation.removeAll();            listInformation.setListData(teachersItem);            comboBoxWord.removeAllItems();            comboBoxWord.addItem("请选择...");            for (int i = 0; i < teachersItem.length; i++) {                // System.out.println(item[i]);                comboBoxWord.addItem(teachersItem[i]);            }            this.tableName = "Teachers";        }        if (this.comboBoxTable.getSelectedItem().equals("课程表")) {            // System.out.println("课程表");            listInformation.removeAll();            listInformation.setListData(coursesItem);            comboBoxWord.removeAllItems();            comboBoxWord.addItem("请选择...");            for (int i = 0; i < coursesItem.length; i++) {                // System.out.println(item[i]);                comboBoxWord.addItem(coursesItem[i]);            }            this.tableName = "Courses";        }        if (this.comboBoxTable.getSelectedItem().equals("班级表")) {            // System.out.println("班级表");            listInformation.removeAll();            listInformation.setListData(classesItem);            comboBoxWord.removeAllItems();            comboBoxWord.addItem("请选择...");            for (int i = 0; i < classesItem.length; i++) {                // System.out.println(item[i]);                comboBoxWord.addItem(classesItem[i]);            }            this.tableName = "Classes";        }    }    /**     * 《开始查询》按钮事件处理     *      * @param evt     */    private void buttonSubmitActionPerformed(ActionEvent evt) {        if (!FormChecked.mustSelect("查询表", this.comboBoxTable.getSelectedItem().toString())) {            return;        }        if (!FormChecked.mustSelect("条件字段", this.comboBoxWord.getSelectedItem().toString())) {            return;        }        if (!FormChecked.mustSelect("判断符号", this.comboBoxJudge.getSelectedItem().toString())) {            return;        }        condition = this.textFieldCondition.getText().trim();        if (!FormChecked.mustNotNull("查询条件", condition)) {            return;        }        if (this.comboBoxJudge.getSelectedItem().toString().equals("等于")) {            judge = "=";        }        if (this.comboBoxJudge.getSelectedItem().toString().equals("包含")) {            judge = "like";        }        if (tableName.equals("Students")) {            word = wordStudents[this.comboBoxWord.getSelectedIndex() - 1];            getSqlStr(wordStudents);        }        if (tableName.equals("Teachers")) {            word = wordTeachers[this.comboBoxWord.getSelectedIndex() - 1];            getSqlStr(wordTeachers);        }        if (tableName.equals("Courses")) {            word = wordCourses[this.comboBoxWord.getSelectedIndex() - 1];            getSqlStr(wordCourses);        }        if (tableName.equals("Classes")) {            word = wordClasses[this.comboBoxWord.getSelectedIndex() - 1];            getSqlStr(wordClasses);        }        // System.out.println(sqlStr);        addTable();    }    /**     * 生成 SQL 语句的方法     *      * @param wordInformation     */    private void getSqlStr(String[] wordInformation) {        int selectCount = this.listInformation.getSelectedIndices().length;        int[] selectIndices = new int[selectCount];        selectIndices = this.listInformation.getSelectedIndices();        /**         * 生成SQL语句         */        sqlStr = "Select ";        for (int i = 0; i < selectIndices.length; i++) {            if (i == 0) {                sqlStr += wordInformation[selectIndices[i]];            } else {                sqlStr += ("," + wordInformation[selectIndices[i]]);            }        }        if (selectIndices.length == 0) {            sqlStr += "*";        }        sqlStr += (" from " + tableName);        sqlStr += (" where " + word + " ");        sqlStr += judge + " ";        if (judge.equals("=")) {            sqlStr += "'" + condition + "'";        } else {            sqlStr += ("'%" + condition + "%'");        }    }    /**     * 显示查询结果的方法     */    private void addTable() {        // System.out.println(ObjectClasses.tableRetrievalRowCount);        SQLOperate.selectAllFromDataForRetrieval(tableName, tableRetrieval, sqlStr);        ObjectClasses.tableRetrievalRowCountFile = ObjectClasses.tableRetrievalRowFile.setTableRowFile(ObjectClasses.tableRetrievalRowCount);        this.scrollPaneResult.setRowHeaderView(ObjectClasses.tableRetrievalRowCountFile);    }}

⌨️ 快捷键说明

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