驾驶员:许佳豪

领航员:吴哲永  博客地址:http://www.cnblogs.com/dbssb/

在上次的结对编程作业中完成了:

  • 用户答题结束以后,程序可以显示用户答题所用的时间
  • 用户可以选择出题的个数(最多不能超过5个题目),答题结束可以显示用户答错的题目个数和答对的题目个数
  • 用户在第一次答题时,需要用户输入用户名,用户下次启动后,程序需要记住用户前一次输入的用户名 
  • 程序可以出单个整数阶乘的题目:如:4!=24

四个扩展方向,此次作业添加了:

  • 可以出表达式里含有负整数(负整数最小不小于-100)的题目,且负数需要带括号,用户输入的结果不用带括号。如: 2*(-4) = -8
  • 程序可以设置皮肤功能,可以改变界面的颜色即可。

两个扩展方向。

主类:

 1 package 四则运算;
 2 
 3 public class Test {
 4 
 5     public static void main(String[] args) {
 6         
 7         MyFrame a=new MyFrame();
 8 
 9     }
10 
11 }

窗体类:

  1 package 四则运算;
  2 
  3 import java.*;
  4 import java.util.*;
  5 
  6 import javax.swing.*;
  7 
  8 import java.awt.*;
  9 import java.awt.event.*;
 10 import java.io.*;
 11 
 12 public class MyFrame extends JFrame
 13 {
 14     JMenuBar M1=new JMenuBar();
 15     JMenu M2=new JMenu("更换颜色");
 16     JMenuItem M3=new JMenuItem("黄色");
 17     JMenuItem M4=new JMenuItem("橙色");
 18     JMenuItem M5=new JMenuItem("白色");
 19     JMenuItem M6=new JMenuItem("蓝色");
 20     JMenuItem M7=new JMenuItem("绿色");
 21     JLabel L1=new JLabel("请输入题数(最多不超过5题):");
 22     JLabel L2=new JLabel("第一题:");
 23     JLabel L3=new JLabel("   =   ");
 24     JLabel L4=new JLabel("第二题:");
 25     JLabel L5=new JLabel("   =   ");
 26     JLabel L6=new JLabel("第三题:");
 27     JLabel L7=new JLabel("   =   ");
 28     JLabel L8=new JLabel("第四题:");
 29     JLabel L9=new JLabel("   =   ");
 30     JLabel L10=new JLabel("第五题:");
 31     JLabel L11=new JLabel("   =   ");
 32     JLabel L12=new JLabel("欢迎您,尊敬的 ");
 33     JLabel L13=new JLabel("用户");
 34     JLabel L14=new JLabel("");
 35     JLabel L15=new JLabel("           ");
 36     JLabel L16=new JLabel("   ");
 37     JLabel L17=new JLabel("   ");
 38     JLabel L18=new JLabel("");
 39     JLabel L19=new JLabel("                               ");
 40     JTextField[]T={
 41             new JTextField(12),new JTextField(12),new JTextField(12),new JTextField(12),new JTextField(12),new JTextField(8),new JTextField(8),new JTextField(8),new JTextField(8),new JTextField(8),new JTextField(5)
 42         };
 43     JButton B1=new JButton("开始答题");
 44     JButton B2=new JButton("提交");
 45     
 46     JFrame f=new JFrame();
 47     
 48     String username=new String();
 49     int i;
 50     int k;
 51     int n;
 52     long begintime;
 53     long endtime;
 54     long time;
 55     int[]a=new int[5];
 56     int[]b=new int[5];
 57     int[]c=new int[5];
 58     int[]d=new int[5];
 59     int[]answer=new int[5];
 60     
 61     
 62     public MyFrame() 
 63     {
 64         getContentPane().setBackground(Color.WHITE);
 65         this.setVisible(true);
 66         this.setTitle("四则运算答题");
 67         Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
 68         setBounds((d.width - 502) / 2, (d.height - 450) / 2, 502, 450);
 69         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 70         this.setResizable(false);
 71         getContentPane().setLayout(new FlowLayout(FlowLayout.CENTER, 12, 10));
 72         setJMenuBar(M1);
 73         M1.add(M2);
 74         M2.add(M3);
 75         M2.add(M4);
 76         M2.add(M5);
 77         M2.add(M6);
 78         M2.add(M7);
 79         L12.setForeground(Color.RED);
 80         L12.setFont(new Font("宋体", Font.BOLD, 25));
 81         getContentPane().add(L12);
 82         L13.setForeground(SystemColor.textHighlight);
 83         L13.setFont(new Font("宋体", Font.BOLD, 25));
 84         getContentPane().add(L13);
 85         L1.setFont(new Font("宋体", Font.PLAIN, 20));
 86         getContentPane().add(L1);
 87         T[10].setFont(

相关文章:

  • 2021-12-05
  • 2021-08-14
  • 2022-01-28
  • 2021-08-04
猜你喜欢
相关资源
相似解决方案