大神求帮忙,在此先谢过各位
  • 浏览:948 评论:3 人

  • import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.KeyEvent;
    import java.awt.event.KeyListener;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import java.util.ArrayList;

    import javax.swing.JFrame;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    import javax.swing.JScrollPane;
    import javax.swing.JTextArea;
    public class TestProblem extends JFrame implements ActionListener,KeyListener,MouseListener{
    int number=0;
    int error=0;
    int correct=0;
    JMenuBar gjt;
    JMenu cd;
    JMenuItem cd1,cd2,cd3;
    JScrollPane gdt;
    JTextArea wby;
    ArrayList<Problem> list=new ArrayList<Problem>();
    public static void main(String[] args){
    TestProblem sp=new TestProblem();
    }
    TestProblem(){
    cd=new JMenu("选项(C)");
    cd.setMnemonic('C');

    cd1=new JMenuItem("开始(S)");
    cd1.setMnemonic('S');
    cd1.addActionListener(this);
    cd1.setActionCommand("1");

    cd2=new JMenuItem("退出(E)");
    cd2.setMnemonic('E');
    cd2.addActionListener(this);
    cd2.setActionCommand("2");

    cd3=new JMenuItem("关于");
    cd3.addActionListener(this);
    cd3.setActionCommand("3");

    gjt=new JMenuBar();
    wby=new JTextArea();
    wby.setLineWrap(true);
    wby.addMouseListener(this);
    wby.addKeyListener(this);
    wby.setBackground(Color.lightGray);
    gdt=new JScrollPane(wby);

    cd.add(cd1); cd.add(cd2);
    gjt.add(cd);gjt.add(cd3);

    this.add(gjt,BorderLayout.NORTH);
    this.add(gdt);

    this.setTitle("100以内加减法练习");
    this.setSize(400,300);
    this.setLocation(300,150);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.setResizable(false);
    this.setVisible(true);

    }
    @Override
    public void actionPerformed(ActionEvent e) {
    // TODO Auto-generated method stub
    if(e.getActionCommand().equals("1")){
    for(int i=0;i<100;i++){
    list.add(new Problem());
    }
    Font font=new Font("宋体",Font.BOLD,20);
    wby.setFont(font);
    wby.setForeground(Color.MAGENTA);
    wby.setText("注意事项"+'\n'+"1、请按回车键开始答题"+'\n'+"2、做完检查后,点击鼠标左键进入下一题"+'\n'+"3、做错的题目记得再看一遍");
    }
    if(e.getActionCommand().equals("2")){
    wby.setText("正确题数:"+correct+'\n'+"错误题数:"+error+'\n'+"(^ω^)!");
    }
    if(e.getActionCommand().equals("3")){
    wby.setText("Version 1.0"+'\n'+"作者:Beautiful的一天");
    wby.setEditable(false);
    }
    }
    @Override
    public void keyTyped(KeyEvent e) {
    // TODO Auto-generated method stub

    }
    @Override
    public void keyPressed(KeyEvent e) {
    // TODO Auto-generated method stub
    if(e.getKeyCode()==KeyEvent.VK_ENTER){
    String str=wby.getText();
    String str1=str.substring(str.lastIndexOf("=")+1);
    int d=Integer.parseInt(str1);
    if(d==list.get(number-1).answer){
    wby.setForeground(Color.blue);
    wby.append(" "+"回答正确");
    correct++;
    }else{
    wby.setForeground(Color.RED);
    wby.append(" "+"回答错误");
    error++;
    }
    }
    }
    @Override
    public void keyReleased(KeyEvent e) {
    // TODO Auto-generated method stub

    }

    @Override
    public void mouseClicked(MouseEvent e) {
    // TODO Auto-generated method stub
    if(e.getButton()==e.BUTTON1){
    wby.setForeground(Color.BLACK);
    wby.setText(list.get(number).question);
    number++;
    }
    }
    @Override
    public void mousePressed(MouseEvent e) {
    // TODO Auto-generated method stub

    }
    @Override
    public void mouseReleased(MouseEvent e) {
    // TODO Auto-generated method stub

    }
    @Override
    public void mouseEntered(MouseEvent e) {
    // TODO Auto-generated method stub

    }
    @Override
    public void mouseExited(MouseEvent e) {
    // TODO Auto-generated method stub

    }
    }
    class Problem{
    int a,b;
    int choice;
    int answer=0;
    String question;
    Problem(){
    a=(int)(Math.random()*100);
    b=(int)(Math.random()*100);
    choice=(int)(Math.random()*1);
    if(choice==0){
    question=new String(a+"+"+b+"=");
    answer=a+b;
    }else if(choice==1){
    if(a<b){
    int c=b;
    b=a;
    a=c;
    }
    question=new String(a+"-"+b+"=");
    answer=a-b;
    }
    }
    }
    请问怎么把上面的源代码改成符合
    “(1)要求题目以单项选择题的形式出现。<?xml:namespace prefix="o" ns="urn:schemas-microsoft-com:office:office"></?xml:namespace>
    (2)完成一题后自动判断答案是否正确,分别弹出不同的提示,并自动更新成下一题。
    (3)单击“退出”时,汇总本次计算结果,共完成几题,正确率,并给出相应评语。确定后正式退出。”的要求”还有就是哪些不需要,可删掉?求各路大神