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

📄 questionpanel.java

📁 《Java案例开发》源代码( 考勤系统的完整实现!) 包括数据库 网络通讯&uml
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        ShowQuestion(Question_Num, check);                if(this.Question_Num == 0){            this.BackButton.setEnabled(false);        }        this.ForwordButton.setEnabled(true);    }//GEN-LAST:event_BackButtonActionPerformed    //init test show    private void initTest(){        this.TestInfoLabel.setText(test.getTitle()+"("+test.getIdent()+")");        this.TimeInfoLabel.setText(test.getTiming()+"");        this.Question_Num = 0;        this.Total_Num = test.size();        this.questions = new Question[Total_Num];        Iterator ite = test.questionIterator();        for(int i = 0 ; (ite.hasNext())&&(i<Total_Num); i++){            questions[i] = (Question)(ite.next());        }        this.BackButton.setEnabled(false);        if(test.size() == 1){            this.ForwordButton.setEnabled(false);        }        ShowQuestion(Question_Num, check);    }        //show a question    //check = true means only view    private void ShowQuestion(int num, boolean check){                Question que = questions[num];                this.QuestionInfoLabel.setText(que.getTitle()+"("+que.getIdent()+")");                //objective        {            this.ObjectiveTextArea.setText(null);                        Iterator ite_obj = que.objectiveIterator();            if(ite_obj.hasNext()){                Objective obj = (Objective)(ite_obj.next());                Iterator ite_i_con = obj.getContent().contentItemIterator();                if(ite_i_con.hasNext()){                    ContentItem item = (ContentItem)(ite_i_con.next());                    if(item instanceof TextContent){                        TextContent titem = (TextContent)item;                        this.ObjectiveTextArea.setFont(getFont());                        this.ObjectiveTextArea.setText(titem.getString());                        if(titem.isEmphatic()){                            this.ObjectiveTextArea.setFont(new Font(getFont().getName(), Font.BOLD, getFont().getSize()));                        }                    }                }            }        }                //feedback        {            this.FeedbackTextArea.setText(null);                        Iterator ite_feed = que.feedbackIterator();            if(ite_feed.hasNext()){                Feedback fbk = (Feedback)(ite_feed.next());                Iterator ite_i_con = fbk.getContent().contentItemIterator();                if(ite_i_con.hasNext()){                    ContentItem item = (ContentItem)(ite_i_con.next());                    if(item instanceof TextContent){                        TextContent titem = (TextContent)item;                        this.FeedbackTextArea.setFont(getFont());                        this.FeedbackTextArea.setText(titem.getString());                        if(titem.isEmphatic()){                            this.FeedbackTextArea.setFont(new Font(getFont().getName(), Font.BOLD, getFont().getSize()));                        }                    }                }            }        }                //question        {            this.ContentTextArea.setText(null);            this.AnswerPanel.removeAll();                        QuestionItem qitem = que.getItem();            if(qitem instanceof FIB){                FIB fib = (FIB)qitem;                Iterator ite_i_con = fib.getContent().contentItemIterator();                if(ite_i_con.hasNext()){                    ContentItem item = (ContentItem)(ite_i_con.next());                    if(item instanceof TextContent){                        TextContent titem = (TextContent)item;                        this.ContentTextArea.setFont(getFont());                        this.ContentTextArea.setText(titem.getString());                        if(titem.isEmphatic()){                            this.ContentTextArea.setFont(new Font(getFont().getName(), Font.BOLD, getFont().getSize()));                        }                    }                }                                JTextField ans = new JTextField();                this.fibfield = ans;                ans.setMinimumSize(new Dimension(80, 30));                ans.setMaximumSize(new Dimension(160, 30));                this.AnswerPanel.add(ans);                ans.setText(fib.getAnswer());                if(check){                    ans.setEditable(false);                    JTextField corr_ans = new JTextField();                    corr_ans.setMinimumSize(new Dimension(80, 30));                    corr_ans.setMaximumSize(new Dimension(160, 30));                    this.AnswerPanel.add(corr_ans);                    corr_ans.setText(fib.getCorrectAnswer());                    corr_ans.setFont(getFont());                    corr_ans.setForeground(Color.red);                    corr_ans.setEditable(false);                }                else{                    ans.setEditable(true);                }                            }                        else if(qitem instanceof romulus.Choice){                                romulus.Choice choice = (romulus.Choice)qitem;                Iterator ite_i_con = choice.getContent().contentItemIterator();                if(ite_i_con.hasNext()){                    ContentItem item = (ContentItem)(ite_i_con.next());                    if(item instanceof TextContent){                        TextContent titem = (TextContent)item;                        this.ContentTextArea.setFont(getFont());                        this.ContentTextArea.setText(titem.getString());                        if(titem.isEmphatic()){                            this.ContentTextArea.setFont(new Font(getFont().getName(), Font.BOLD, getFont().getSize()));                        }                    }                }                                Iterator ite_citem = choice.choiceitemIterator();                AbstractList aitem = choice.answerList();                this.choicefield.clear();                this.choiceItems.clear();                                for( ;ite_citem.hasNext(); ){                    ChoiceItem citem = (ChoiceItem)(ite_citem.next());                    choiceItems.put(citem.getIdent(), citem);                                        Iterator ite_i_con_item = citem.getContent().contentItemIterator();                    if(ite_i_con_item.hasNext()){                        ContentItem item = (ContentItem)(ite_i_con_item.next());                        if(item instanceof TextContent){                            TextContent titem = (TextContent)item;                            JCheckBox jcb = new JCheckBox(titem.getString());                            jcb.setFont(getFont());                            jcb.setName(citem.getIdent());                            choicefield.add(jcb);                            jcb.setSelected(false);                            this.AnswerPanel.add(jcb);                            if(aitem.contains(citem)){                                jcb.setSelected(true);                            }                            if(check && citem.isCorrect()){                                jcb.setForeground(Color.red);                            }                        }                    }                }                                if(check){                    this.AnswerPanel.setEnabled(false);                }                else{                    this.AnswerPanel.setEnabled(true);                }            }                    }                this.repaint();        this.validate();    }        private void setAnswer(int num){        Question que = questions[num];                QuestionItem qitem = que.getItem();        if(qitem instanceof FIB){            FIB fib = (FIB)qitem;            fib.setAnswer(fibfield.getText());        }        if(qitem instanceof romulus.Choice){            romulus.Choice choice = (romulus.Choice)qitem;            choice.clearAnswer();            for( Iterator ita = this.choicefield.iterator(); ita.hasNext(); ){                JCheckBox jcb = (JCheckBox)(ita.next());                if(jcb.isSelected()){                    choice.addAnswer((ChoiceItem)(choiceItems.get(jcb.getName())));                }            }        }            }        public void actionPerformed(java.awt.event.ActionEvent actionEvent) {        if(!check){            if(actionEvent.getSource() == timer){                time--;                this.TimeInfoLabel.setText("Time Left: "+time);                this.repaint();                this.revalidate();                if(time <= 0){                    timer.stop();                    setAnswer(Question_Num);                    firePropertyChange(PropName_Commit, null, this.test);                }            }        }    }        // Variables declaration - do not modify//GEN-BEGIN:variables    private javax.swing.JButton ForwordButton;    private javax.swing.JPanel ButtonPanel;    private javax.swing.JTextArea ContentTextArea;    private javax.swing.JTextArea ObjectiveTextArea;    private javax.swing.JScrollPane ContentScrollPane;    private javax.swing.JScrollPane AnswerScrollPane;    private javax.swing.JLabel TestInfoLabel;    private javax.swing.JButton BackButton;    private javax.swing.JLabel QuestionInfoLabel;    private javax.swing.JLabel TimeInfoLabel;    private javax.swing.JPanel AnswerPanel;    private javax.swing.JButton CommitButton;    private javax.swing.JScrollPane ObjectiveScrollPane;    private javax.swing.JScrollPane FeedbackScrollPane;    private javax.swing.JTextArea FeedbackTextArea;    // End of variables declaration//GEN-END:variables    //the content    private Test test;    private int Question_Num;    private int Total_Num;    private Question[] questions;    private boolean check;    private JTextField fibfield;    private Vector choicefield = new Vector();    private HashMap choiceItems = new HashMap();    private javax.swing.Timer timer;    private int time;    //end        //props    public static String PropName_Commit = "QuestionPanel_Commit";    public static String PropName_Exit = "QuestionPanel_Exit";    }

⌨️ 快捷键说明

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