| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1397 人关注过本帖
标题:求大神帮我看看我的程序,运行后是一个界面而已,我还差哪些步奏?
只看楼主 加入收藏
你若为王
Rank: 1
等 级:新手上路
帖 子:36
专家分:0
注 册:2015-11-15
结帖率:40%
收藏
 问题点数:0 回复次数:0 
求大神帮我看看我的程序,运行后是一个界面而已,我还差哪些步奏?
package javazuoye;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import *;

public class A {
    public static void main(String args[]) {
        StandardExamInTime win = new StandardExamInTime();
        win.setTitle("限时回答问题");
        win.setTestFile(new ("test.txt"));
        win.setMAX(8);
    }
}
 class StandardExamInTime extends JFrame implements ActionListener, ItemListener {
    File testFile;
    int MAX = 8;
    int maxTime = MAX, score = 0;
    Timer time;
    JTextArea showQuesion;
    JCheckBox choiceA, choiceB, choiceC, choiceD;
    JLabel showScore, showTime;
    String correctAnswer;
    JButton reStart;
    FileReader inOne;
    BufferedReader inTwo;

    public StandardExamInTime() {
        time = new Timer(1000, this);
        showQuesion = new JTextArea(2, 16);
        setLayout(new FlowLayout());
        showScore = new JLabel("分数" + score);
        showTime = new JLabel(" ");
        add(showTime);
        add(new JLabel("问题1:下列哪种动物属于猫科动物?-D-问题2:你喜欢谁?-A"));
        add(showQuesion);
        choiceA = new JCheckBox("A");
        choiceB = new JCheckBox("B");
        choiceC = new JCheckBox("C");
        choiceD = new JCheckBox("D");
        choiceA.addItemListener(this);
        choiceB.addItemListener(this);
        choiceC.addItemListener(this);
        choiceD.addItemListener(this);
        add(choiceA);
        add(choiceB);
        add(choiceC);
        add(choiceD);
        add(showScore);
        reStart = new JButton("再做一遍");
        reStart.setEnabled(false);
        add(reStart);
        reStart.addActionListener(this);
        setBounds(200, 200, 400, 400);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setVisible(true);
    }

    public void setMAX(int n) {
        MAX = n;
    }

    public void setTestFile(File f) {
        testFile = f;
        score = 0;
        try {
            inOne = new FileReader(testFile);
            inTwo = new BufferedReader(inOne);
            readOneQuesion();
            reStart.setEnabled(false);
        } catch (IOException exp) {
            showQuesion.setText("");
        }
    }

    public void readOneQuesion() {
        showQuesion.setText(null);
        try {
            String s = null;
            while ((s = inTwo.readLine()) != null) {
                if (!s.startsWith("-"))
                    showQuesion.append("\n" + s);
                else {
                    s = s.replaceAll("-", "-");
                    correctAnswer = s;
                    break;
                }
            }
            time.start();
            if (s == null) {
                inTwo.close();
                reStart.setEnabled(true);
                showQuesion.setText("题目完毕");
                time.stop();
            }
        } catch (IOException exp) {
        }
    }

    public void itemStateChanged(ItemEvent e) {
        JCheckBox box = (JCheckBox) e.getSource();
        String str = box.getText();
        boolean booOne = box.isSelected();
        boolean booTwo = (correctAnswer) == 0;
        if (booOne & booTwo) {
            score++;
            showScore.setText("分数:" + score);
            time.stop();
            maxTime = MAX;
            readOneQuesion();
        }
        box.setSelected(false);
    }

    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == time) {
            showTime.setText("剩:" + maxTime + "秒");
            maxTime--;
            if (maxTime <= 0) {
                maxTime = MAX;
                readOneQuesion();
            }
        } else if (e.getSource() == reStart) {
            setTestFile(testFile);
        }
    }
}
图片附件: 游客没有浏览图片的权限,请 登录注册
搜索更多相关主题的帖子: 回答问题 package public import 
2016-06-24 22:39
快速回复:求大神帮我看看我的程序,运行后是一个界面而已,我还差哪些步奏?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018662 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved