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

📄 filterpanel.java

📁 一个带界面的在线测试系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        sumitPanelLayout.setHorizontalGroup(
            sumitPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(sumitPanelLayout.createSequentialGroup()
                .addGap(123, 123, 123)
                .addComponent(buttonForEnter)
                .addGap(79, 79, 79)
                .addComponent(buttonForCancel)
                .addContainerGap(123, Short.MAX_VALUE))
        );
        sumitPanelLayout.setVerticalGroup(
            sumitPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(sumitPanelLayout.createSequentialGroup()
                .addGap(29, 29, 29)
                .addGroup(sumitPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(buttonForCancel)
                    .addComponent(buttonForEnter))
                .addContainerGap(30, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(sumitPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(filterPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(infoArea, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(infoArea, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(filterPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(sumitPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void buttonForCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonForCancelActionPerformed
// TODO 将在此处添加您的处理代码:
        this.mainFrame.reset();
    }//GEN-LAST:event_buttonForCancelActionPerformed

    private void checkBoxByDiffStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_checkBoxByDiffStateChanged
// TODO 将在此处添加您的处理代码:
    }//GEN-LAST:event_checkBoxByDiffStateChanged

    private void checkBoxByTypeStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_checkBoxByTypeStateChanged
// TODO 将在此处添加您的处理代码:
        if (this.checkBoxByDiff.isSelected() == true){
            this.type =(String) this.comboBoxForType.getSelectedItem();
        }else {
            this.type = null;
        }
    }//GEN-LAST:event_checkBoxByTypeStateChanged

    private void RadioButtonForConditionStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_RadioButtonForConditionStateChanged
// TODO 将在此处添加您的处理代码:
        if (this.RadioButtonForCondition.isSelected() == true){
            //this.lableForInfo.setText("select");
            this.condition = "combination";
                
             this.checkBoxByDiff.setEnabled(true);
             this.checkBoxByType.setEnabled(true);
             this.textFieldForDiff.setEnabled(true);
             this.comboBoxForType.setEnabled(true);

            
            this.mainFrame.pack();
        } else {
        
            this.checkBoxByDiff.setEnabled(false);
            this.checkBoxByType.setEnabled(false);
            this.textFieldForDiff.setEnabled(false);
            this.comboBoxForType.setEnabled(false);
            //this.textFieldForId.setEnabled(false);
          
            this.mainFrame.pack();
        }
    }//GEN-LAST:event_RadioButtonForConditionStateChanged

    private void RadioButtonForRandomStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_RadioButtonForRandomStateChanged
// TODO 将在此处添加您的处理代码:
        if (this.RadioButtonForRandom.isSelected() == true){
            this.condition = "random";
        }
    }//GEN-LAST:event_RadioButtonForRandomStateChanged

    private void RadioButtonForAllStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_RadioButtonForAllStateChanged
// TODO 将在此处添加您的处理代码:
        if (this.RadioButtonForAll.isSelected() == true){
            this.condition = "all";
        }
    }//GEN-LAST:event_RadioButtonForAllStateChanged

    private void RadioButtonForIDStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_RadioButtonForIDStateChanged
// TODO 将在此处添加您的处理代码:
        if (this.RadioButtonForID.isSelected() == true){
          
            this.condition = "id";
        
            this.textFieldForId.setEnabled(true);
            this.mainFrame.pack();
        } else {

            this.textFieldForId.setEnabled(false);
          
            this.mainFrame.pack();
        }
    }//GEN-LAST:event_RadioButtonForIDStateChanged

    private void RadioButtonForIDActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RadioButtonForIDActionPerformed
// TODO 将在此处添加您的处理代码:
    }//GEN-LAST:event_RadioButtonForIDActionPerformed

    private void RadioButtonForAllActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RadioButtonForAllActionPerformed
// TODO 将在此处添加您的处理代码:
    }//GEN-LAST:event_RadioButtonForAllActionPerformed

    private void RadioButtonForRandomActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RadioButtonForRandomActionPerformed
// TODO 将在此处添加您的处理代码:
    }//GEN-LAST:event_RadioButtonForRandomActionPerformed

    private void buttonForEnterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonForEnterActionPerformed
// TODO 将在此处添加您的处理代码:
        //this.mainFrame.showTestingPanel();
        if (this.RadioButtonForID.isSelected() == true ){//检查ID字段
            boolean check = this.textFieldForId.getText().matches(this.numFormat);
            if (check == true){
                this.mainFrame.toNextStage();return;
            }else{
                JOptionPane.showMessageDialog(this.mainFrame,"ID字段必须写入一个数字");
            }
        }else if (this.RadioButtonForCondition.isSelected() == true){
            boolean flag = true;
            if (this.checkBoxByDiff.isSelected() == false && 
                    this.checkBoxByType.isSelected() == false){
                JOptionPane.showMessageDialog(this.mainFrame,"必须选择一个条件");
                return;
            }
            if (this.checkBoxByDiff.isSelected() == true){//检查难度字段
                 boolean check = this.textFieldForDiff.getText().matches(this.numFormat);
                 if (check == true){
                     flag = true;
                 }else {
                     JOptionPane.showMessageDialog(this.mainFrame,"试题难度字段必须写入一个数字");
                     flag = false;
                 }
            }else {
                this.mainFrame.toNextStage();return;
            }
            if (flag == true){
                this.mainFrame.toNextStage();return;
            }

        }else {
            this.mainFrame.toNextStage();return;
        }
        
    }//GEN-LAST:event_buttonForEnterActionPerformed
    
    
    // 变量声明 - 不进行修改//GEN-BEGIN:variables
    private javax.swing.JRadioButton RadioButtonForAll;
    private javax.swing.JRadioButton RadioButtonForCondition;
    private javax.swing.JRadioButton RadioButtonForID;
    private javax.swing.JRadioButton RadioButtonForRandom;
    private javax.swing.JButton buttonForCancel;
    private javax.swing.JButton buttonForEnter;
    private javax.swing.ButtonGroup buttonGroup;
    private javax.swing.JCheckBox checkBoxByDiff;
    private javax.swing.JCheckBox checkBoxByType;
    private javax.swing.JComboBox comboBoxForType;
    private javax.swing.JPanel filterPanel;
    private javax.swing.JPanel infoArea;
    private javax.swing.JLabel lableForInfo;
    private javax.swing.JPanel sumitPanel;
    private javax.swing.JTextField textFieldForDiff;
    private javax.swing.JTextField textFieldForId;
    // 变量声明结束//GEN-END:variables

    //自定义变量
    private MainFrame mainFrame;
    private String condition;
    private int diff  = -1 ;
    private int id ;
    private String type ;
    protected String numFormat = "\\d+";
    protected String trueFalseFormat = "true|false";
    protected String singleChoiceFormat ="A|B|C|D";
    
    /**得到用户决定的抽取条件
     * 有random,all,combination和 id 这四种情况
     */
    public String getConditionDecision(){
        return this.condition;
    }
    
    /**得到用户决定的抽取的试题难度*/
    public int getConditionOfDiff(){
        this.getDiffFromText();
        return diff;
    }
    
    /**得到用户决定的抽取试题的类型*/
    public String getConditionOfType(){
        return (String) this.comboBoxForType.getSelectedItem();
    }
    
    /**得到用户决定的用于抽取试题的ID*/
    public int getConditionOfId(){
        this.getIdFromText();
        return this.id;
    }
    
    /**
     *将文本字段的内容转化为diff
     */
    private void getDiffFromText(){
        if (this.textFieldForDiff.getText().length()==0){
            this.diff = -1;
        }
        else {
            this.diff = Integer.parseInt(this.textFieldForDiff.getText());
        }
    }
    
    /**
     *将文本字段的内容转化为id
     */
    private void getIdFromText(){
        this.id = Integer.parseInt(this.textFieldForId.getText());
    }
    
    
    class TextChecker implements DocumentListener{

        public void changedUpdate(DocumentEvent e){
            //getDiffFromText();
        }
        public void insertUpdate(DocumentEvent e){

            //getDiffFromText();
        }
        public void removeUpdate(DocumentEvent e){

            //getDiffFromText();
        }
        
    }
}

⌨️ 快捷键说明

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