第二次作业——全国中小学生数学(四则运算)竞赛(更改版)

 

PS:Login类内的save方法中有一个设置路径,因为我的路径是:String dirname="C:/Users/Administrator/Desktop/OYKS/OYKS/Strongest";所以老师在调试前需要麻烦老师更改一下路径才能进运行。

PS:Login类内的背景图片与更改皮肤的效果,请老师在底下下载一下图片,创建一个背景图片的文件夹再,一并运行吧。辛苦了老师。

  1 package size;
  2 import java.awt.*;
  3 import javax.swing.*;
  4 
  5 
  6 
  7 import java.awt.event.*;
  8 import java.io.*;
  9 import java.util.ArrayList;
 10 import java.util.Date;
 11 public class Login extends JFrame implements ActionListener{
 12     private static final long serialVersionUID = 1L;
 13     private JTextField textField;
 14      public JButton btnNewButton_1,btnNewButton;
 15      public int w=0,ww;
 16      public JLabel Label1;
 17     public Login()
 18     {
 19         super("登陆界面");
 20         getContentPane().setBackground(new Color(0, 0, 139));
 21         getContentPane().setForeground(new Color(0, 0, 205));
 22         setSize(342,265);
 23         setVisible(true);                       //将窗口设置为可视
 24         setResizable(false);
 25         setAlwaysOnTop(true);//设置此窗口永远为最上方 是window的方法
 26         setLocationRelativeTo(null);
 27         getContentPane().setLayout(null);
 28         
 29         JPanel panel_1 = new JPanel();
 30         panel_1.setBounds(86, 85, 162, 21);
 31         getContentPane().add(panel_1);
 32         panel_1.setLayout(null);
 33         
 34  
 35         
 36         textField = new JTextField();
 37         textField.setBounds(0, 0, 162, 21);
 38         panel_1.add(textField);
 39         textField.setColumns(10);
 40         
 41         btnNewButton = new JButton("\u767B\u9646");
 42         btnNewButton.setFont(new Font("幼圆", Font.BOLD, 12));
 43         btnNewButton.setForeground(new Color(255, 0, 0));
 44         btnNewButton.setBounds(51, 157, 93, 23);
 45         btnNewButton.addActionListener(this);
 46         getContentPane().add(btnNewButton);
 47         
 48         btnNewButton_1 = new JButton("\u6CE8\u518C");
 49         btnNewButton_1.setFont(new Font("幼圆", Font.BOLD, 12));
 50         btnNewButton_1.setForeground(new Color(255, 0, 0));
 51         btnNewButton_1.setBounds(193, 157, 93, 23);
 52         btnNewButton_1.addActionListener(this);
 53         getContentPane().add(btnNewButton_1);
 54         
 55         JLabel label = new JLabel("\u767B\u5F55\u540D");
 56         label.setForeground(new Color(255, 0, 0));
 57         label.setFont(new Font("幼圆", Font.BOLD, 19));
 58         label.setBounds(138, 38, 66, 21);
 59         getContentPane().add(label);
 60         
 61         JPanel panel = new JPanel();
 62         panel.setBounds(0, 0, 336, 237);
 63         getContentPane().add(panel);
 64         Label1 = new JLabel(new ImageIcon("背景图片/6.png."));
 65         //getContentPane().add(Label1);
 66         panel.add(Label1);
 67     }
 68     public void save(String mm)                  //*******************************************************************************
 69     {
 70     String dirname="C:/Users/Administrator/Desktop/OYKS/OYKS/Strongest";
 71     try{
 72         File dir=new File(dirname);
 73         if(!dir.exists())
 74             dir.mkdir();
 75         else
 76         if(!dir.isDirectory())
 77         {
 78             System.out.print(dirname+"不是目录路径");
 79             return;
 80         }
 81         
 82     File afile=new File(dir,"ys.txt");
 83     afile.createNewFile();
 84     
 85     
 86     BufferedWriter bs = new BufferedWriter(new FileWriter(afile,true));    //使用BufferedWriter写入文本时不用将文本转换成字节数组       追加式的。
 87     bs.write(mm);
 88     bs.flush();
 89     bs.close();
 90     
 91     
 92     
 93     
 94     }
 95     catch (IOException e)
 96     {
 97         System.out.print("IOexception throun:"+e);
 98     }
 99     
100     }                                        //*
101     
102     public String []reademp(File output)        //文件读取
103     {
104         ArrayList<String> ee = new ArrayList<String>();//动态数组ArrayList的ee对象里面放的必须是employee类型的
105         try {
106             
107             BufferedReader br = new BufferedReader(new FileReader(output));    //通过FileReader打开,然后在BufferedReader中进行缓冲读取
108             String temp = "";        //它可以包装字符流,将字符流放入缓存里,先把字符读到缓存里,到缓存满了或者flush的时候,再读入内存,
109             while ((temp = br.readLine()) != null) {//读到文本为空为止。
110                 String xx=temp;
111                 ee.add(xx);
112             }
113         } catch (IOException e) {
114            
115             JOptionPane.showMessageDialog(this,"第一次使用,需要注册噢~!" 
116                     , "提示",  
117                     JOptionPane.INFORMATION_MESSAGE);  
118         }
119             String[] MM = new String[ee.size()];
120             for (int i = 0; i < ee.size(); i++) {
121                 MM[i] = ee.get(i);        //    将动态数组对象内容赋值给EMPO数组;
122             }
123             return MM;
124             
125         
126     }
127     
128     public void actionPerformed(ActionEvent e) 
129     {
130         if(e.getSource()==btnNewButton)
131         {
132         File file = new File("ys.txt");
133         String[] xxx=reademp(file);
134         String sign=textField.getText();
135         
136         
137         for(w=0;w<xxx.length;w++)
138         {
139             System.out.print(xxx[w]);
140             if(sign.equals(xxx[w]))
141             {
142                 ww=1;
143                 new Select();
144                 
145             }
146             
147         }
148         if(ww==0)
149         {
150             JOptionPane.showMessageDialog(this,"未查找到该用户!" 
151                     , "提示",  
152                     JOptionPane.INFORMATION_MESSAGE);  
153         }
154         }
155         else if(e.getSource()==btnNewButton_1)
156         {
157             save(textField.getText()+'\n');
158             JOptionPane.showMessageDialog(this,"恭喜你,注册成功!" 
159                     , "提示",  
160                     JOptionPane.INFORMATION_MESSAGE);  
161         }
162     }
163     public static void main(String[]args)
164     {
165         new Login();
166     }
167 }
Login
  1 package size;
  2 
  3 //import test2;
  4 
  5 import java.awt.*;
  6 import javax.swing.*;
  7 import java.awt.event.*;
  8 import java.util.Random;
  9 import java.util.Scanner;
 10 public class NewFrame extends JFrame implements ActionListener{
 11     
 12     public JButton btnNewButton_1,btnNewButton;
 13     public JComboBox List;
 14     public JTextField textField_2;
 15     public JTextField textField_zhengshi1;
 16     public JTextField textField_daan1;
 17     public JTextField textField_zhengshi2;
 18     public JTextField textField_daan2;
 19     public JTextField textField_zhengshi3;
 20     public JTextField textField_daan3;
 21     public JTextField textField_zhengshi4;
 22     public JTextField textField_daan4;
 23     public JTextField textField_zhengshi5;
 24     public JTextField textField_daan5;
 25     public JTextField textField_duicuo1;
 26     public JTextField textField_duicuo2;
 27     public JTextField textField_duicuo3;
 28     public JTextField textField_duicuo4;
 29     public JTextField textField_duicuo5;
 30     public JTextField textField_zhengque1;
 31     public JTextField textField_zhengque2;
 32     public JTextField textField_zhengque3;
 33     public JTextField textField_zhengque4;
 34     public JTextField textField_zhengque5;
 35     public JTextField textField_shijian1;
 36     public JTextField textField_shijian2;
 37     public JTextField textField_shijian3;
 38     public JTextField textField_shijian4;
 39     public JTextField textField_shijian5;
 40     public JTextField textField_zq;
 41     public JTextField textField_zql;
 42     public JTextField textField_allshijian;
 43     public JButton button_daan;
 44     public JButton btnNewButton_queding;
 45     public JButton btnNewButton_jixv;
 46     public String x;
 47     public String []c=new String [10];
 48     public Test t;
 49     public static int num=0;
 50     public static int num1=0;
 51     public long begin,end,sum;
 52     public JLabel Label1;
 53     private JLabel label_4;
 54     private JLabel label_5;
 55     private JLabel label_6;
 56     private JLabel label_7;
 57     private JPanel panel_1;
 58     public NewFrame(String a[])
 59     {
 60         
 61         super("四则运算");
 62         c=a;
 63         getContentPane().setLayout(null);
 64         JPanel panel = new JPanel();
 65         panel.setForeground(new Color(255, 0, 102));
 66         setSize(725, 463);
 67         panel.setBounds(0, 0, 719, 435);
 68         getContentPane().add(panel);
 69         panel.setLayout(null);
 70         
 71         
 72          String[] zw={"随机","1","2","3","4","5"};
 73             List=new JComboBox(zw);
 74             List.setEnabled(false);
 75             List.addActionListener(this);
 76             List.setFont(new Font("宋体", Font.PLAIN, 13));
 77             List.setBounds(10, 10, 75, 21);
 78             panel.add(List);
 79             
 80             textField_zhengshi1 = new JTextField();
 81             textField_zhengshi1.setEditable(false);
 82             textField_zhengshi1.setBounds(10, 77, 240, 21);
 83             panel.add(textField_zhengshi1);
 84             textField_zhengshi1.setColumns(50);
 85             textField_zhengshi1.setText(a[0]);
 86             textField_zhengshi1.addActionListener(this);
 87             
 88             textField_daan1 = new JTextField();
 89             textField_daan1.setBounds(286, 77, 102, 21);
 90             panel.add(textField_daan1);
 91             textField_daan1.addActionListener(this);
 92             textField_daan1.setColumns(20);
 93             
 94             textField_zhengshi2 = new JTextField();
 95             textField_zhengshi2.setEditable(false);
 96             textField_zhengshi2.setBounds(10, 120, 240, 21);
 97             panel.add(textField_zhengshi2);
 98             textField_zhengshi2.setText(a[2]);
 99             textField_zhengshi2.setColumns(50);
100             
101             textField_daan2 = new JTextField();
102             textField_daan2.setBounds(286, 120, 102, 21);
103             panel.add(textField_daan2);
104             textField_daan2.addActionListener(this);
105             textField_daan2.setColumns(20);
106             
107             textField_zhengshi3 = new JTextField();
108             textField_zhengshi3.setEditable(false);
109             textField_zhengshi3.setBounds(10, 163, 240, 21);
110             panel.add(textField_zhengshi3);
111             textField_zhengshi3.setText(a[4]);
112             textField_zhengshi3.setColumns(50);
113             
114             textField_daan3 = new JTextField();
115             textField_daan3.setBounds(286, 163, 102, 21);
116             panel.add(textField_daan3);
117             textField_daan3.addActionListener(this);
118             textField_daan3.setColumns(20);
119             
120             textField_zhengshi4 = new JTextField();
121             textField_zhengshi4.setEditable(false);
122             textField_zhengshi4.setBounds(10, 206, 240, 21);
123             panel.add(textField_zhengshi4);
124             textField_zhengshi4.setText(a[6]);
125             textField_zhengshi4.setColumns(50);
126             
127             textField_daan4 = new JTextField();
128             textField_daan4.setText("");
129             textField_daan4.setBounds(286, 206, 102, 21);
130             panel.add(textField_daan4);
131             textField_daan4.addActionListener(this);
132             textField_daan4.setColumns(10);
133             
134             textField_zhengshi5 = new JTextField();
135             textField_zhengshi5.setEditable(false);
136             textField_zhengshi5.setBounds(10, 249, 240, 21);
137             panel.add(textField_zhengshi5);
138             textField_zhengshi5.setText(a[8]);
139             textField_zhengshi5.setColumns(50);
140             
141             textField_daan5 = new JTextField();
142             textField_daan5.setBounds(286, 249, 102, 21);
143             panel.add(textField_daan5);
144             textField_daan5.addActionListener(this);
145             textField_daan5.setColumns(20);
146             
147             textField_duicuo1 = new JTextField();
148             textField_duicuo1.setForeground(Color.RED);
149             textField_duicuo1.setBackground(Color.WHITE);
150             textField_duicuo1.setBounds(422, 77, 37, 21);
151             panel.add(textField_duicuo1);
152             textField_duicuo1.setColumns(10);
153             
154             textField_duicuo2 = new JTextField();
155             textField_duicuo2.setForeground(Color.RED);
156             textField_duicuo2.setEnabled(true);
157             textField_duicuo2.setText("");
158             textField_duicuo2.setBounds(422, 120, 37, 21);
159             panel.add(textField_duicuo2);
160             textField_duicuo2.setColumns(10);
161             
162             textField_duicuo3 = new JTextField();
163             textField_duicuo3.setForeground(Color.RED);
164             textField_duicuo3.setEnabled(true);
165             textField_duicuo3.setText("");
166             textField_duicuo3.setBounds(422, 163, 37, 21);
167             panel.add(textField_duicuo3);
168             textField_duicuo3.setColumns(10);
169             
170             textField_duicuo4 = new JTextField();
171             textField_duicuo4.setForeground(Color.RED);
172             textField_duicuo4.setEnabled(true);
173             textField_duicuo4.setText("");
174             textField_duicuo4.setBounds(422, 206, 37, 21);
175             panel.add(textField_duicuo4);
176             textField_duicuo4.setColumns(10);
177             
178             textField_duicuo5 = new JTextField();
179             textField_duicuo5.setForeground(Color.RED);
180             textField_duicuo5.setEnabled(true);
181             textField_duicuo5.setText("");
182             textField_duicuo5.setBounds(422, 249, 37, 21);
183             panel.add(textField_duicuo5);
184             textField_duicuo5.setColumns(10);
185             
186             textField_zhengque1 = new JTextField();
187             textField_zhengque1.setForeground(Color.BLUE);
188             textField_zhengque1.setEditable(false);
189             textField_zhengque1.setBounds(499, 77, 102, 21);
190             panel.add(textField_zhengque1);
191             textField_zhengque1.setColumns(20);
192             
193             textField_zhengque2 = new JTextField();
194             textField_zhengque2.setForeground(Color.BLUE);
195             textField_zhengque2.setEditable(false);
196             textField_zhengque2.setEnabled(true);
197             textField_zhengque2.setText("");
198             textField_zhengque2.setBounds(499, 120, 102, 21);
199             panel.add(textField_zhengque2);
200             textField_zhengque2.setColumns(20);
201             
202             textField_zhengque3 = new JTextField();
203             textField_zhengque3.setForeground(Color.BLUE);
204             textField_zhengque3.setEditable(false);
205             textField_zhengque3.setBounds(499, 163, 102, 21);
206             panel.add(textField_zhengque3);
207             textField_zhengque3.setColumns(20);
208             
209             textField_zhengque4 = new JTextField();
210             textField_zhengque4.setForeground(Color.BLUE);
211             textField_zhengque4.setEditable(false);
212             textField_zhengque4.setBounds(499, 206, 102, 21);
213             panel.add(textField_zhengque4);
214             textField_zhengque4.setColumns(20);
215             
216             textField_zhengque5 = new JTextField();
217             textField_zhengque5.setForeground(Color.BLUE);
218             textField_zhengque5.setEditable(false);
219             textField_zhengque5.setEnabled(true);
220             textField_zhengque5.setText("");
221             textField_zhengque5.setBounds(499, 249, 102, 21);
222             panel.add(textField_zhengque5);
223             textField_zhengque5.setColumns(20);
224             
225             textField_shijian1 = new JTextField();
226             textField_shijian1.setForeground(new Color(255, 0, 102));
227             textField_shijian1.setEditable(false);
228             textField_shijian1.setBounds(621, 77, 66, 21);
229             panel.add(textField_shijian1);
230             textField_shijian1.setColumns(30);
231             
232             textField_shijian2 = new JTextField();
233             textField_shijian2.setForeground(new Color(255, 0, 102));
234             textField_shijian2.setEnabled(true);
235             textField_shijian2.setEditable(false);
236             textField_shijian2.setText("");
237             textField_shijian2.setBounds(621, 120, 66, 21);
238             panel.add(textField_shijian2);
239             textField_shijian2.setColumns(30);
240             
241             textField_shijian3 = new JTextField();
242             textField_shijian3.setForeground(new Color(255, 0, 102));
243             textField_shijian3.setEnabled(true);
244             textField_shijian3.setEditable(false);
245             textField_shijian3.setText("");
246             textField_shijian3.setBounds(621, 163, 66, 21);
247             panel.add(textField_shijian3);
248             textField_shijian3.setColumns(30);
249             
250             textField_shijian4 = new JTextField();
251             textField_shijian4.setForeground(new Color(255, 0, 102));
252             textField_shijian4.setEnabled(true);
253             textField_shijian4.setEditable(false);
254             textField_shijian4.setText("");
255             textField_shijian4.setBounds(621, 206, 66, 21);
256             panel.add(textField_shijian4);
257             textField_shijian4.setColumns(30);
258             
259             textField_shijian5 = new JTextField();
260             textField_shijian5.setForeground(new Color(255, 0, 102));
261             textField_shijian5.setEnabled(true);
262             textField_shijian5.setEditable(false);
263             textField_shijian5.setText("");
264             textField_shijian5.setBounds(621, 249, 66, 21);
265             panel.add(textField_shijian5);
266             textField_shijian5.setColumns(30);
267             
268             textField_zq = new JTextField();
269             textField_zq.setEditable(false);
270             textField_zq.setBounds(10, 340, 66, 21);
271             panel.add(textField_zq);
272             textField_zq.setColumns(20);
273             
274             textField_zql = new JTextField();
275             textField_zql.setEnabled(true);
276             textField_zql.setEditable(false);
277             textField_zql.setText("");
278             textField_zql.setBounds(96, 340, 66, 21);
279             panel.add(textField_zql);
280             textField_zql.setColumns(20);
281             
282             textField_allshijian = new JTextField();
283             textField_allshijian.setEditable(false);
284             textField_allshijian.setBounds(621, 340, 66, 21);
285             panel.add(textField_allshijian);
286             textField_allshijian.setColumns(30);
287             
288             button_daan = new JButton("答案");
289             button_daan.addActionListener(this);
290             button_daan.setBounds(351, 391, 81, 23);
291             panel.add(button_daan);
292             
293             btnNewButton_queding = new JButton("确定");
294             btnNewButton_queding.setBounds(471, 391, 81, 23);
295             btnNewButton_queding.addActionListener(this);
296             panel.add(btnNewButton_queding);
297             
298             btnNewButton_jixv = new JButton("继续答题");
299             btnNewButton_jixv.setBounds(590, 391, 97, 23);
300             btnNewButton_jixv.addActionListener(this);
301             panel.add(btnNewButton_jixv);
302             
303             JLabel label = new JLabel("\u9898\u76EE");
304             label.setBounds(10, 52, 54, 15);
305             panel.add(label);
306             
307             JLabel label_1 = new JLabel("\u8F93\u5165\u7B54\u6848");
308             label_1.setBounds(286, 52, 54, 15);
309             panel.add(label_1);
310             
311             JLabel label_2 = new JLabel("\u5224\u65AD");
312             label_2.setBounds(422, 52, 54, 15);
313             panel.add(label_2);
314             
315             JLabel label_3 = new JLabel("\u53C2\u8003\u7B54\u6848");
316             label_3.setBounds(499, 52, 54, 15);
317             panel.add(label_3);
318             
319             label_4 = new JLabel("\u7B54\u9898\u65F6\u95F4");
320             label_4.setBounds(621, 52, 54, 15);
321             panel.add(label_4);
322             
323             label_5 = new JLabel("\u603B\u65F6\u95F4");
324             label_5.setBounds(621, 315, 54, 15);
325             panel.add(label_5);
326             
327             label_6 = new JLabel("\u6B63\u786E\u9898\u6570");
328             label_6.setForeground(Color.RED);
329             label_6.setBounds(10, 315, 54, 15);
330             panel.add(label_6);
331             
332             label_7 = new JLabel("\u6B63\u786E\u7387");
333             label_7.setForeground(Color.RED);
334             label_7.setBounds(96, 315, 54, 15);
335             panel.add(label_7);
336             
337             panel_1 = new JPanel();
338             panel_1.setBounds(0, 0, 719, 435);
339             panel.add(panel_1);
340             //String bb="背景图片/5.jpg.";
341             Label1 = new JLabel(new ImageIcon("背景图片/5.jpg."));
342             //System.out.print();
343             panel_1.add(Label1);
344             Test t=new Test();
345            // t.start();
346             begin=System.currentTimeMillis();
347             
348             
349         
350         
351     
352         setVisible(true);                       //将窗口设置为可视
353         setResizable(false);
354         setAlwaysOnTop(true);//设置此窗口永远为最上方 是window的方法
355         setLocationRelativeTo(null);
356         getContentPane().setLayout(null);
357         
358     }
359     public void setx(String x)
360     {
361         this.x=x;
362     }
363     public String getx()
364     {
365         return x;
366     }
367     public void actionPerformed(ActionEvent e) {
368         if(e.getSource()==button_daan)
369         {
370             textField_zhengque1.setText(c[1]);
371             textField_zhengque2.setText(c[3]);
372             textField_zhengque3.setText(c[5]);
373             textField_zhengque4.setText(c[7]);
374             textField_zhengque5.setText(c[9]);
375             
376         }
377         //try{
378                //10000毫秒以后结束线程
379             //Thread.sleep(5000);
380         else if(e.getSource()==textField_daan1)//职务
381             {
382                     if(textField_daan1.getText().equals(c[1]))
383                     {
384                         textField_duicuo1.setText("√");
385                         
386                         sum=(System.currentTimeMillis()-begin)/1000;
387                         textField_shijian1.setText(String.valueOf(sum)+"s");
388                         textField_daan2.requestFocusInWindow(); 
389                         num++;num1++;
390                         textField_zq.setText(String.valueOf(num));
391                         float x=(float)num/num1*100;
392                         textField_zql.setText(String.valueOf(x));
393                     }
394                     else
395                     {
396                     textField_duicuo1.setText("×");
397                     sum=(System.currentTimeMillis()-begin)/1000;
398                     textField_shijian1.setText(String.valueOf(sum)+"s");
399                     num1++;
400                     
401                     textField_daan2.requestFocusInWindow(); 
402                     textField_zq.setText(String.valueOf(num));
403                     float x=(float)num/num1*100;
404                     textField_zql.setText(String.valueOf(x));
405                     }
406             }
407                     
408                     
409                     
410                     
411                     else if(e.getSource()==textField_daan2)//职务
412                     {
413                         if(textField_daan2.getText().equals(c[3]))
414                         {
415                             textField_duicuo2.setText("√");
416                             sum=(System.currentTimeMillis()-begin)/1000-sum;                
417                             textField_shijian2.setText(String.valueOf(sum)+"s");
418                             num++;num1++;
419                             textField_zq.setText(String.valueOf(num));
420                             float x=(float)num/num1*100;
421                             textField_zql.setText(String.valueOf(x));
422                         }
423                         else
424                         {
425                             
426                             if(c[3].equals(""))
427                             {
428                                 textField_duicuo2.setText("none");
429                             }
430                             
431                             else
432                             {
433                             textField_duicuo2.setText("×");
434                             sum=(System.currentTimeMillis()-begin)/1000-sum;
435                             textField_shijian2.setText(String.valueOf(sum)+"s");
436                             num1++;
437                             textField_zq.setText(String.valueOf(num));
438                             float x=(float)num/num1*100;
439                             textField_zql.setText(String.valueOf(x));
440                             }
441                             
442                         }
443                         textField_daan3.requestFocusInWindow(); 
444                     }
445                     else if(e.getSource()==textField_daan3)//职务
446                     {
447                         Test t=new Test();
448                         t.start();
449                         
450                         if(textField_daan3.getText().equals(c[5]))
451                         {
452                             textField_duicuo3.setText("√");
453                             sum=(System.currentTimeMillis()-begin)/1000-sum;
454                             textField_shijian3.setText(String.valueOf(sum)+"s");
455                             num++;num1++;
456                             textField_zq.setText(String.valueOf(num));
457                             float x=(float)num/num1*100;
458                             textField_zql.setText(String.valueOf(x));
459                         }
460                         else
461                         {
462                             if(c[5].equals(""))
463                             {
464                                 textField_duicuo3.setText("none");
465                             }
466                             else
467                             {
468                             textField_duicuo3.setText("×");
469                             sum=(System.currentTimeMillis()-begin)/1000-sum;
470                             textField_shijian3.setText(String.valueOf(sum)+"s");
471                             num1++;
472                             textField_zq.setText(String.valueOf(num));
473                             float x=(float)num/num1*100;
474                             textField_zql.setText(String.valueOf(x));
475                             }
476                         }
477                         textField_daan4.requestFocusInWindow(); 
478                     }
479                     else if(e.getSource()==textField_daan4)//职务
480                     {
481                         if(textField_daan4.getText().equals(c[7]))
482                         {
483                             textField_duicuo4.setText("√");
484                             sum=(System.currentTimeMillis()-begin)/1000-sum;
485                             textField_shijian4.setText(String.valueOf(sum)+"s");
486                             num++;num1++;
487                             textField_zq.setText(String.valueOf(num));
488                             float x=(float)num/num1*100;
489                             textField_zql.setText(String.valueOf(x));
490                         }
491                         else
492                         {
493                             if(c[7].equals(""))
494                             {
495                                 textField_duicuo4.setText("none");
496                             }
497                             else
498                             {
499                             textField_duicuo4.setText("×");
500                             //sum=System.currentTimeMillis()/1000-sum;
501                             sum=(System.currentTimeMillis()-begin)/1000-sum;
502                             textField_shijian4.setText(String.valueOf(sum)+"s");
503                             num1++;
504                             //textField_shijian4.setText(String.valueOf((System.currentTimeMillis()-begin)/1000));
505                             textField_zq.setText(String.valueOf(num));
506                             float x=(float)num/num1*100;
507                             textField_zql.setText(String.valueOf(x));
508                             }
509                         }
510                         textField_daan5.requestFocusInWindow(); 
511                     }
512                     else if(e.getSource()==textField_daan5)//职务
513                     {
514                         if(textField_daan5.getText().equals(c[9]))
515                         {
516                             sum=(System.currentTimeMillis()-begin)/1000-sum;
517                             //sum=System.currentTimeMillis()/1000-sum;
518                             textField_shijian5.setText(String.valueOf(sum)+"s");
519                             //textField_shijian5.setText(String.valueOf((System.currentTimeMillis()-begin)/1000));
520                             textField_duicuo5.setText("√");
521                             num++;num1++;
522                             textField_zq.setText(String.valueOf(num));
523                             float x=(float)num/num1*100;
524                             textField_zql.setText(String.valueOf(x));
525                             
526                             
527                         }
528                         else
529                         {
530                             if(c[9].equals(""))
531                             {
532                                 textField_duicuo5.setText("none");
533                             }
534                             else
535                             {
536                             textField_duicuo5.setText("×");
537                             //sum=System.currentTimeMillis()/1000-sum;
538                             sum=(System.currentTimeMillis()-begin)/1000-sum;
539                             textField_shijian5.setText(String.valueOf(sum)+"s");
540                             //textField_shijian5.setText(String.valueOf((System.currentTimeMillis()-begin)/1000));
541                             num1++;
542                             textField_zq.setText(String.valueOf(num));
543                             float x=(float)num/num1*100;
544                             textField_zql.setText(String.valueOf(x));
545                             }
546                         }
547                         btnNewButton_queding.requestFocusInWindow(); 
548                     }
549             
550         
551         
552         else if(e.getSource()==btnNewButton_queding)//职务
553         {
554             //t.stop();
555             textField_allshijian.setText(String.valueOf((System.currentTimeMillis()-begin)/1000)+"s");
556         }
557         else if(e.getSource()==btnNewButton_jixv)//职务
558         {
559             
560             setVisible(false); 
561             new NewFrame1("背景图片/5.jpg.");
562             
563         }
564         
565         
566         
567     }
568 }
NewFrame
  1 package size;
  2 
  3 //import test2;
  4 
  5 import java.awt.*;
  6 import javax.swing.*;
  7 import java.awt.event.*;
  8 import java.util.Random;
  9 import java.util.Scanner;
 10 public class NewFrame1 extends JFrame implements ActionListener{
 11     
 12     public JButton btnNewButton_1,btnNewButton;
 13     public JComboBox List;
 14     public JTextField textField_2;
 15     public JTextField textField_zhengshi1;
 16     public JTextField textField_daan1;
 17     public JTextField textField_zhenshi2;
 18     public JTextField textField_daan2;
 19     public JTextField textField_zhengshi3;
 20     public JTextField textField_daan;
 21     public JTextField textField_zhengshi4;
 22     public JTextField textField;
 23     public JTextField textField_zhengshi5;
 24     public JTextField textField_daan5;
 25     public JTextField textField_duicuo1;
 26     public JTextField textField_duicuo2;
 27     public JTextField textField_duicuo3;
 28     public JTextField textField_duicuo4;
 29     public JTextField textField_duicuo5;
 30     public JTextField textField_zhengque1;
 31     public JTextField textField_zhengque2;
 32     public JTextField textField_zhrngque3;
 33     public JTextField textField_zhengque4;
 34     public JTextField textField_zhengque5;
 35     public JTextField textField_shijian1;
 36     public JTextField textField_shijian2;
 37     public JTextField textField_shijian3;
 38     public JTextField textField_shijian4;
 39     public JTextField textField_shijian5;
 40     public JTextField textField_zq;
 41     public JTextField textField_zql;
 42     public JTextField textField_allshijian;
 43     public JButton btnNewButton_queding;
 44     public JButton btnNewButton_jixv;
 45     public JPanel panel_1;
 46     public JButton button_pifu;
 47     public String x;
 48     public JLabel Label1;
 49     private JLabel label;
 50     public NewFrame1(String c)
 51     {
 52         super("四则运算");
 53         getContentPane().setLayout(null);
 54         JPanel panel = new JPanel();
 55         panel.setForeground(Color.GRAY);
 56         setSize(725, 463);
 57         panel.setBounds(0, 0, 719, 435);
 58         getContentPane().add(panel);
 59         panel.setLayout(null);
 60         
 61         
 62          String[] zw={"随机","1","2","3","4","5"};
 63             List=new JComboBox(zw);
 64             List.addActionListener(this);
 65             List.setFont(new Font("宋体", Font.PLAIN, 13));
 66             List.setBounds(10, 10, 75, 21);
 67             panel.add(List);
 68             
 69             textField_zhengshi1 = new JTextField();
 70             textField_zhengshi1.setEditable(false);
 71             textField_zhengshi1.setBounds(10, 77, 358, 21);
 72             panel.add(textField_zhengshi1);
 73             textField_zhengshi1.setColumns(50);
 74             textField_zhengshi1.addActionListener(this);
 75             
 76             textField_daan1 = new JTextField();
 77             textField_daan1.setEditable(false);
 78             textField_daan1.setBounds(402, 77, 66, 21);
 79             panel.add(textField_daan1);
 80             textField_daan1.setColumns(20);
 81             
 82             textField_zhenshi2 = new JTextField();
 83             textField_zhenshi2.setEditable(false);
 84             textField_zhenshi2.setBounds(10, 120, 358, 21);
 85             panel.add(textField_zhenshi2);
 86             textField_zhenshi2.setColumns(50);
 87             
 88             textField_daan2 = new JTextField();
 89             textField_daan2.setEditable(false);
 90             textField_daan2.setBounds(402, 120, 66, 21);
 91             panel.add(textField_daan2);
 92             textField_daan2.setColumns(20);
 93             
 94             textField_zhengshi3 = new JTextField();
 95             textField_zhengshi3.setEditable(false);
 96             textField_zhengshi3.setBounds(10, 163, 358, 21);
 97             panel.add(textField_zhengshi3);
 98             textField_zhengshi3.setColumns(50);
 99             
100             textField_daan = new JTextField();
101             textField_daan.setEditable(false);
102             textField_daan.setBounds(402, 163, 66, 21);
103             panel.add(textField_daan);
104             textField_daan.setColumns(20);
105             
106             textField_zhengshi4 = new JTextField();
107             textField_zhengshi4.setEditable(false);
108             textField_zhengshi4.setBounds(10, 206, 358, 21);
109             panel.add(textField_zhengshi4);
110             textField_zhengshi4.setColumns(50);
111             
112             textField = new JTextField();
113             textField.setEditable(false);
114             textField.setText("");
115             textField.setBounds(402, 206, 66, 21);
116             panel.add(textField);
117             textField.setColumns(10);
118             
119             textField_zhengshi5 = new JTextField();
120             textField_zhengshi5.setEditable(false);
121             textField_zhengshi5.setBounds(10, 249, 358, 21);
122             panel.add(textField_zhengshi5);
123             textField_zhengshi5.setColumns(50);
124             
125             textField_daan5 = new JTextField();
126             textField_daan5.setEditable(false);
127             textField_daan5.setBounds(402, 249, 66, 21);
128             panel.add(textField_daan5);
129             textField_daan5.setColumns(20);
130             
131             textField_duicuo1 = new JTextField();
132             textField_duicuo1.setEditable(false);
133             textField_duicuo1.setBounds(488, 77, 37, 21);
134             panel.add(textField_duicuo1);
135             textField_duicuo1.setColumns(10);
136             
137             textField_duicuo2 = new JTextField();
138             textField_duicuo2.setEditable(false);
139             textField_duicuo2.setEnabled(true);
140             textField_duicuo2.setText("");
141             textField_duicuo2.setBounds(488, 120, 37, 21);
142             panel.add(textField_duicuo2);
143             textField_duicuo2.setColumns(10);
144             
145             textField_duicuo3 = new JTextField();
146             textField_duicuo3.setEnabled(true);
147             textField_duicuo3.setEditable(false);
148             textField_duicuo3.setText("");
149             textField_duicuo3.setBounds(488, 163, 37, 21);
150             panel.add(textField_duicuo3);
151             textField_duicuo3.setColumns(10);
152             
153             textField_duicuo4 = new JTextField();
154             textField_duicuo4.setEnabled(true);
155             textField_duicuo4.setEditable(false);
156             textField_duicuo4.setText("");
157             textField_duicuo4.setBounds(488, 206, 37, 21);
158             panel.add(textField_duicuo4);
159             textField_duicuo4.setColumns(10);
160             
161             textField_duicuo5 = new JTextField();
162             textField_duicuo5.setEnabled(true);
163             textField_duicuo5.setEditable(false);
164             textField_duicuo5.setText("");
165             textField_duicuo5.setBounds(488, 249, 37, 21);
166             panel.add(textField_duicuo5);
167             textField_duicuo5.setColumns(10);
168             
169             textField_zhengque1 = new JTextField();
170             textField_zhengque1.setEditable(false);
171             textField_zhengque1.setBounds(535, 77, 66, 21);
172             panel.add(textField_zhengque1);
173             textField_zhengque1.setColumns(20);
174             
175             textField_zhengque2 = new JTextField();
176             textField_zhengque2.setEditable(false);
177             textField_zhengque2.setEnabled(true);
178             textField_zhengque2.setText("");
179             textField_zhengque2.setBounds(535, 120, 66, 21);
180             panel.add(textField_zhengque2);
181             textField_zhengque2.setColumns(20);
182             
183             textField_zhrngque3 = new JTextField();
184             textField_zhrngque3.setEditable(false);
185             textField_zhrngque3.setBounds(535, 163, 66, 21);
186             panel.add(textField_zhrngque3);
187             textField_zhrngque3.setColumns(20);
188             
189             textField_zhengque4 = new JTextField();
190             textField_zhengque4.setEditable(false);
191             textField_zhengque4.setBounds(535, 206, 66, 21);
192             panel.add(textField_zhengque4);
193             textField_zhengque4.setColumns(20);
194             
195             textField_zhengque5 = new JTextField();
196             textField_zhengque5.setEditable(false);
197             textField_zhengque5.setEnabled(true);
198             textField_zhengque5.setText("");
199             textField_zhengque5.setBounds(535, 249, 66, 21);
200             panel.add(textField_zhengque5);
201             textField_zhengque5.setColumns(20);
202             
203             textField_shijian1 = new JTextField();
204             textField_shijian1.setEditable(false);
205             textField_shijian1.setBounds(621, 77, 66, 21);
206             panel.add(textField_shijian1);
207             textField_shijian1.setColumns(30);
208             
209             textField_shijian2 = new JTextField();
210             textField_shijian2.setEnabled(true);
211             textField_shijian2.setEditable(false);
212             textField_shijian2.setText("");
213             textField_shijian2.setBounds(621, 120, 66, 21);
214             panel.add(textField_shijian2);
215             textField_shijian2.setColumns(30);
216             
217             textField_shijian3 = new JTextField();
218             textField_shijian3.setEnabled(true);
219             textField_shijian3.setEditable(false);
220             textField_shijian3.setText("");
221             textField_shijian3.setBounds(621, 163, 66, 21);
222             panel.add(textField_shijian3);
223             textField_shijian3.setColumns(30);
224             
225             textField_shijian4 = new JTextField();
226             textField_shijian4.setEnabled(true);
227             textField_shijian4.setEditable(false);
228             textField_shijian4.setText("");
229             textField_shijian4.setBounds(621, 206, 66, 21);
230             panel.add(textField_shijian4);
231             textField_shijian4.setColumns(30);
232             
233             textField_shijian5 = new JTextField();
234             textField_shijian5.setEnabled(true);
235             textField_shijian5.setEditable(false);
236             textField_shijian5.setText("");
237             textField_shijian5.setBounds(621, 249, 66, 21);
238             panel.add(textField_shijian5);
239             textField_shijian5.setColumns(30);
240             
241             textField_zq = new JTextField();
242             textField_zq.setEditable(false);
243             textField_zq.setBounds(10, 340, 66, 21);
244             panel.add(textField_zq);
245             textField_zq.setColumns(20);
246             
247             textField_zql = new JTextField();
248             textField_zql.setEnabled(true);
249             textField_zql.setEditable(false);
250             textField_zql.setText("");
251             textField_zql.setBounds(96, 340, 66, 21);
252             panel.add(textField_zql);
253             textField_zql.setColumns(20);
254             
255             textField_allshijian = new JTextField();
256             textField_allshijian.setEditable(false);
257             textField_allshijian.setBounds(621, 340, 66, 21);
258             panel.add(textField_allshijian);
259             textField_allshijian.setColumns(30);
260             
261             JButton button_daan = new JButton("答案");
262             button_daan.setEnabled(false);
263             button_daan.addActionListener(new ActionListener() {
264                 public void actionPerformed(ActionEvent e) {
265                 }
266             });
267             button_daan.setBounds(351, 391, 81, 23);
268             panel.add(button_daan);
269             
270             btnNewButton_queding = new JButton("确定");
271             btnNewButton_queding.setEnabled(false);
272             btnNewButton_queding.setBounds(471, 391, 81, 23);
273             panel.add(btnNewButton_queding);
274             
275             btnNewButton_jixv = new JButton("继续答题");
276             btnNewButton_jixv.setEnabled(false);
277             btnNewButton_jixv.setBounds(590, 391, 97, 23);
278             panel.add(btnNewButton_jixv);
279             
280             label = new JLabel("\u9898\u76EE\u6570\u91CF");
281             label.setForeground(Color.GRAY);
282             label.setBackground(Color.RED);
283             label.setBounds(95, 13, 54, 15);
284             panel.add(label);
285             
286             button_pifu = new JButton("\u66F4\u6539\u76AE\u80A4");
287             button_pifu.setBounds(218, 391, 93, 23);
288             button_pifu.addActionListener(this);
289             panel.add(button_pifu);
290             
291             panel_1 = new JPanel();
292             panel_1.setBounds(0, 0, 719, 435);
293             panel.add(panel_1);
294             //String bb="背景图片/5.jpg.";
295             Label1 = new JLabel(new ImageIcon(c));
296             //System.out.print();
297             panel_1.add(Label1);
298             
299             
300         
301         
302     
303         setVisible(true);                       //将窗口设置为可视
304         setResizable(false);
305         setAlwaysOnTop(true);//设置此窗口永远为最上方 是window的方法
306         setLocationRelativeTo(null);
307         getContentPane().setLayout(null);
308     }
309     public void setx(String x)
310     {
311         this.x=x;
312     }
313     public String getx()
314     {
315         return x;
316     }
317     public void actionPerformed(ActionEvent e) {
318         if(e.getSource()==List)//职务
319         {
320             //emp[i]=new employee();
321             if(List.getSelectedItem().equals("随机"))
322             {
323                 //System.out.print("@@@@@@@@@@@@@@@@@@@@");
324                 
325                 Random z=new Random();
326                 //int c=z.nextInt(4)+1;
327                 //System.out.print(c);
328                 x=String.valueOf(z.nextInt(4)+1);
329                 new Test2(x);
330             }
331             else
332             {
333             x=(String) List.getSelectedItem();
334             
335             new Test2(x);
336             }
337             setVisible(false); 
338             //textField_zhengshi1.setText(a[0]);
339         }
340         else if(e.getSource()==button_pifu)//职务
341         {
342             
343             setVisible(false);
344             Random a=new Random();
345             int b=a.nextInt(4)+1;
346             //背景图片/5.jpg.
347             String c="背景图片/";
348             c+=String.valueOf(b);
349             c+=".jpg.";
350             //System.out.print(c);
351             Label1 = new JLabel(new ImageIcon(c));
352             panel_1.add(Label1);
353             new NewFrame1(c);
354 
355         }
356     }
357     
358 }
NewFrame1
  1 package size;
  2 
  3 //import test2;
  4 
  5 import java.awt.*;
  6 import javax.swing.*;
  7 import java.awt.event.*;
  8 import java.util.Random;
  9 import java.util.Scanner;
 10 public class NewFrame2 extends JFrame implements ActionListener{
 11     
 12     public JButton btnNewButton_1,btnNewButton;
 13     public JComboBox List;
 14     public JTextField textField_2;
 15     public JTextField textField_zhengshi1;
 16     public JTextField textField_daan1;
 17     public JTextField textField_zhenshi2;
 18     public JTextField textField_daan2;
 19     public JTextField textField_zhengshi3;
 20     public JTextField textField_daan;
 21     public JTextField textField_zhengshi4;
 22     public JTextField textField;
 23     public JTextField textField_zhengshi5;
 24     public JTextField textField_daan5;
 25     public JTextField textField_duicuo1;
 26     public JTextField textField_duicuo2;
 27     public JTextField textField_duicuo3;
 28     public JTextField textField_duicuo4;
 29     public JTextField textField_duicuo5;
 30     public JTextField textField_zhengque1;
 31     public JTextField textField_zhengque2;
 32     public JTextField textField_zhrngque3;
 33     public JTextField textField_zhengque4;
 34     public JTextField textField_zhengque5;
 35     public JTextField textField_shijian1;
 36     public JTextField textField_shijian2;
 37     public JTextField textField_shijian3;
 38     public JTextField textField_shijian4;
 39     public JTextField textField_shijian5;
 40     public JTextField textField_zq;
 41     public JTextField textField_zql;
 42     public JTextField textField_allshijian;
 43     public JButton btnNewButton_queding;
 44     public JButton btnNewButton_jixv;
 45     public String x;
 46     private JLabel label;
 47     private JPanel panel_1;
 48     public JButton button_pifu;
 49     public JLabel Label1;
 50     public NewFrame2(String cc)
 51     {
 52         super("阶乘运算");
 53         getContentPane().setLayout(null);
 54         JPanel panel = new JPanel();
 55         panel.setForeground(Color.GRAY);
 56         setSize(725, 463);
 57         panel.setBounds(0, 0, 719, 435);
 58         getContentPane().add(panel);
 59         panel.setLayout(null);
 60         
 61         
 62          String[] zw={"随机","1","2","3","4","5"};
 63             List=new JComboBox(zw);
 64             List.addActionListener(this);
 65             List.setFont(new Font("宋体", Font.PLAIN, 13));
 66             List.setBounds(10, 10, 75, 21);
 67             panel.add(List);
 68             
 69             textField_zhengshi1 = new JTextField();
 70             textField_zhengshi1.setEditable(false);
 71             textField_zhengshi1.setBounds(10, 77, 358, 21);
 72             panel.add(textField_zhengshi1);
 73             textField_zhengshi1.setColumns(50);
 74             textField_zhengshi1.addActionListener(this);
 75             
 76             textField_daan1 = new JTextField();
 77             textField_daan1.setEditable(false);
 78             textField_daan1.setBounds(402, 77, 66, 21);
 79             panel.add(textField_daan1);
 80             textField_daan1.setColumns(20);
 81             
 82             textField_zhenshi2 = new JTextField();
 83             textField_zhenshi2.setEditable(false);
 84             textField_zhenshi2.setBounds(10, 120, 358, 21);
 85             panel.add(textField_zhenshi2);
 86             textField_zhenshi2.setColumns(50);
 87             
 88             textField_daan2 = new JTextField();
 89             textField_daan2.setEditable(false);
 90             textField_daan2.setBounds(402, 120, 66, 21);
 91             panel.add(textField_daan2);
 92             textField_daan2.setColumns(20);
 93             
 94             textField_zhengshi3 = new JTextField();
 95             textField_zhengshi3.setEditable(false);
 96             textField_zhengshi3.setBounds(10, 163, 358, 21);
 97             panel.add(textField_zhengshi3);
 98             textField_zhengshi3.setColumns(50);
 99             
100             textField_daan = new JTextField();
101             textField_daan.setEditable(false);
102             textField_daan.setBounds(402, 163, 66, 21);
103             panel.add(textField_daan);
104             textField_daan.setColumns(20);
105             
106             textField_zhengshi4 = new JTextField();
107             textField_zhengshi4.setEditable(false);
108             textField_zhengshi4.setBounds(10, 206, 358, 21);
109             panel.add(textField_zhengshi4);
110             textField_zhengshi4.setColumns(50);
111             
112             textField = new JTextField();
113             textField.setEditable(false);
114             textField.setText("");
115             textField.setBounds(402, 206, 66, 21);
116             panel.add(textField);
117             textField.setColumns(10);
118             
119             textField_zhengshi5 = new JTextField();
120             textField_zhengshi5.setEditable(false);
121             textField_zhengshi5.setBounds(10, 249, 358, 21);
122             panel.add(textField_zhengshi5);
123             textField_zhengshi5.setColumns(50);
124             
125             textField_daan5 = new JTextField();
126             textField_daan5.setEditable(false);
127             textField_daan5.setBounds(402, 249, 66, 21);
128             panel.add(textField_daan5);
129             textField_daan5.setColumns(20);
130             
131             textField_duicuo1 = new JTextField();
132             textField_duicuo1.setEditable(false);
133             textField_duicuo1.setBounds(488, 77, 37, 21);
134             panel.add(textField_duicuo1);
135             textField_duicuo1.setColumns(10);
136             
137             textField_duicuo2 = new JTextField();
138             textField_duicuo2.setEditable(false);
139             textField_duicuo2.setEnabled(true);
140             textField_duicuo2.setText("");
141             textField_duicuo2.setBounds(488, 120, 37, 21);
142             panel.add(textField_duicuo2);
143             textField_duicuo2.setColumns(10);
144             
145             textField_duicuo3 = new JTextField();
146             textField_duicuo3.setEnabled(true);
147             textField_duicuo3.setEditable(false);
148             textField_duicuo3.setText("");
149             textField_duicuo3.setBounds(488, 163, 37, 21);
150             panel.add(textField_duicuo3);
151             textField_duicuo3.setColumns(10);
152             
153             textField_duicuo4 = new JTextField();
154             textField_duicuo4.setEnabled(true);
155             textField_duicuo4.setEditable(false);
156             textField_duicuo4.setText("");
157             textField_duicuo4.setBounds(488, 206, 37, 21);
158             panel.add(textField_duicuo4);
159             textField_duicuo4.setColumns(10);
160             
161             textField_duicuo5 = new JTextField();
162             textField_duicuo5.setEnabled(true);
163             textField_duicuo5.setEditable(false);
164             textField_duicuo5.setText("");
165             textField_duicuo5.setBounds(488, 249, 37, 21);
166             panel.add(textField_duicuo5);
167             textField_duicuo5.setColumns(10);
168             
169             textField_zhengque1 = new JTextField();
170             textField_zhengque1.setEditable(false);
171             textField_zhengque1.setBounds(535, 77, 66, 21);
172             panel.add(textField_zhengque1);
173             textField_zhengque1.setColumns(20);
174             
175             textField_zhengque2 = new JTextField();
176             textField_zhengque2.setEditable(false);
177             textField_zhengque2.setEnabled(true);
178             textField_zhengque2.setText("");
179             textField_zhengque2.setBounds(535, 120, 66, 21);
180             panel.add(textField_zhengque2);
181             textField_zhengque2.setColumns(20);
182             
183             textField_zhrngque3 = new JTextField();
184             textField_zhrngque3.setEditable(false);
185             textField_zhrngque3.setBounds(535, 163, 66, 21);
186             panel.add(textField_zhrngque3);
187             textField_zhrngque3.setColumns(20);
188             
189             textField_zhengque4 = new JTextField();
190             textField_zhengque4.setEditable(false);
191             textField_zhengque4.setBounds(535, 206, 66, 21);
192             panel.add(textField_zhengque4);
193             textField_zhengque4.setColumns(20);
194             
195             textField_zhengque5 = new JTextField();
196             textField_zhengque5.setEditable(false);
197             textField_zhengque5.setEnabled(true);
198             textField_zhengque5.setText("");
199             textField_zhengque5.setBounds(535, 249, 66, 21);
200             panel.add(textField_zhengque5);
201             textField_zhengque5.setColumns(20);
202             
203             textField_shijian1 = new JTextField();
204             textField_shijian1.setEditable(false);
205             textField_shijian1.setBounds(621, 77, 66, 21);
206             panel.add(textField_shijian1);
207             textField_shijian1.setColumns(30);
208             
209             textField_shijian2 = new JTextField();
210             textField_shijian2.setEnabled(true);
211             textField_shijian2.setEditable(false);
212             textField_shijian2.setText("");
213             textField_shijian2.setBounds(621, 120, 66, 21);
214             panel.add(textField_shijian2);
215             textField_shijian2.setColumns(30);
216             
217             textField_shijian3 = new JTextField();
218             textField_shijian3.setEnabled(true);
219             textField_shijian3.setEditable(false);
220             textField_shijian3.setText("");
221             textField_shijian3.setBounds(621, 163, 66, 21);
222             panel.add(textField_shijian3);
223             textField_shijian3.setColumns(30);
224             
225             textField_shijian4 = new JTextField();
226             textField_shijian4.setEnabled(true);
227             textField_shijian4.setEditable(false);
228             textField_shijian4.setText("");
229             textField_shijian4.setBounds(621, 206, 66, 21);
230             panel.add(textField_shijian4);
231             textField_shijian4.setColumns(30);
232             
233             textField_shijian5 = new JTextField();
234             textField_shijian5.setEnabled(true);
235             textField_shijian5.setEditable(false);
236             textField_shijian5.setText("");
237             textField_shijian5.setBounds(621, 249, 66, 21);
238             panel.add(textField_shijian5);
239             textField_shijian5.setColumns(30);
240             
241             textField_zq = new JTextField();
242             textField_zq.setEditable(false);
243             textField_zq.setBounds(10, 340, 66, 21);
244             panel.add(textField_zq);
245             textField_zq.setColumns(20);
246             
247             textField_zql = new JTextField();
248             textField_zql.setEnabled(true);
249             textField_zql.setEditable(false);
250             textField_zql.setText("");
251             textField_zql.setBounds(96, 340, 66, 21);
252             panel.add(textField_zql);
253             textField_zql.setColumns(20);
254             
255             textField_allshijian = new JTextField();
256             textField_allshijian.setEditable(false);
257             textField_allshijian.setBounds(621, 340, 66, 21);
258             panel.add(textField_allshijian);
259             textField_allshijian.setColumns(30);
260             
261             JButton button_daan = new JButton("答案");
262             button_daan.setEnabled(false);
263             button_daan.addActionListener(new ActionListener() {
264                 public void actionPerformed(ActionEvent e) {
265                 }
266             });
267             button_daan.setBounds(351, 391, 81, 23);
268             panel.add(button_daan);
269             
270             btnNewButton_queding = new JButton("确定");
271             btnNewButton_queding.setEnabled(false);
272             btnNewButton_queding.setBounds(471, 391, 81, 23);
273             panel.add(btnNewButton_queding);
274             
275             btnNewButton_jixv = new JButton("继续答题");
276             btnNewButton_jixv.setEnabled(false);
277             btnNewButton_jixv.setBounds(590, 391, 97, 23);
278             panel.add(btnNewButton_jixv);
279             
280             label = new JLabel("\u9898\u76EE\u6570\u91CF");
281             label.setForeground(Color.GRAY);
282             label.setBackground(Color.RED);
283             label.setBounds(95, 13, 54, 15);
284             panel.add(label);
285             
286             button_pifu = new JButton("\u66F4\u6539\u76AE\u80A4");
287             button_pifu.setBounds(218, 391, 93, 23);
288             button_pifu.addActionListener(this);
289             panel.add(button_pifu);
290             
291             panel_1 = new JPanel();
292             panel_1.setBounds(0, 0, 719, 435);
293             panel.add(panel_1);
294             //String bb="背景图片/5.jpg.";
295             Label1 = new JLabel(new ImageIcon("背景图片/5.jpg."));
296             //System.out.print();
297             panel_1.add(Label1);
298             Test t=new Test();
299            // t.start();
300      
301             
302             
303         
304         
305     
306         setVisible(true);                       //将窗口设置为可视
307         setResizable(false);
308         setAlwaysOnTop(true);//设置此窗口永远为最上方 是window的方法
309         setLocationRelativeTo(null);
310         getContentPane().setLayout(null);
311     }
312     public void setx(String x)
313     {
314         this.x=x;
315     }
316     public String getx()
317     {
318         return x;
319     }
320     public void actionPerformed(ActionEvent e) {
321         if(e.getSource()==List)//职务
322         {
323     
324             if(List.getSelectedItem().equals("随机"))
325             {
326                 
327                 
328                 Random z=new Random();
329                 //int c=z.nextInt(4)+1;
330                 //System.out.print(c);
331                 x=String.valueOf(z.nextInt(4)+1);
332                 new Test1(x);
333             }
334             else
335             {
336             x=(String) List.getSelectedItem();
337             
338             new Test1(x);
339             }
340             setVisible(false); 
341             //textField_zhengshi1.setText(a[0]);
342         }
343         else if(e.getSource()==button_pifu)//职务
344         {
345             setVisible(false);
346             Random a=new Random();
347             int b=a.nextInt(4)+1;
348             //背景图片/5.jpg.
349             String c="背景图片/";
350             c+=String.valueOf(b);
351             c+=".jpg.";
352             //System.out.print(c);
353             Label1 = new JLabel(new ImageIcon(c));
354             panel_1.add(Label1);
355             new NewFrame1(c);
356             
357             
358             
359         }
360         
361         
362         
363     }
364 
365 
366 
367     
368 }
NewFrame2
  1 package size;
  2 
  3 //import test2;
  4 
  5 import java.awt.*;
  6 import javax.swing.*;
  7 import java.awt.event.*;
  8 import java.util.Random;
  9 import java.util.Scanner;
 10 public class NewFrame3 extends JFrame implements ActionListener{
 11     
 12     private static final String String = null;
 13     public JButton btnNewButton_1,btnNewButton;
 14     public JComboBox List;
 15     public JTextField textField_2;
 16     public JTextField textField_zhengshi1;
 17     public JTextField textField_daan1;
 18     public JTextField textField_zhengshi2;
 19     public JTextField textField_daan2;
 20     public JTextField textField_zhengshi3;
 21     public JTextField textField_daan3;
 22     public JTextField textField_zhengshi4;
 23     public JTextField textField_daan4;
 24     public JTextField textField_zhengshi5;
 25     public JTextField textField_daan5;
 26     public JTextField textField_duicuo1;
 27     public JTextField textField_duicuo2;
 28     public JTextField textField_duicuo3;
 29     public JTextField textField_duicuo4;
 30     public JTextField textField_duicuo5;
 31     public JTextField textField_zhengque1;
 32     public JTextField textField_zhengque2;
 33     public JTextField textField_zhengque3;
 34     public JTextField textField_zhengque4;
 35     public JTextField textField_zhengque5;
 36     public JTextField textField_shijian1;
 37     public JTextField textField_shijian2;
 38     public JTextField textField_shijian3;
 39     public JTextField textField_shijian4;
 40     public JTextField textField_shijian5;
 41     public JTextField textField_zq;
 42     public JTextField textField_zql;
 43     public JTextField textField_allshijian;
 44     public JButton button_daan;
 45     public JButton btnNewButton_queding;
 46     public JButton btnNewButton_jixv;
 47     public String x;
 48     public String []c=new String [10];
 49     public Test t;
 50     public static int num=0;
 51     public static int num1=0;
 52     public long begin,end,sum;
 53     private JLabel label_4;
 54     private JLabel label_5;
 55     private JLabel label_6;
 56     private JLabel label_7;
 57     public NewFrame3(String a[])
 58     {
 59         
 60         super("阶乘运算");
 61         c=a;
 62         getContentPane().setLayout(null);
 63         JPanel panel = new JPanel();
 64         panel.setForeground(new Color(255, 0, 102));
 65         setSize(725, 463);
 66         panel.setBounds(0, 0, 719, 435);
 67         getContentPane().add(panel);
 68         panel.setLayout(null);
 69         
 70         
 71          String[] zw={"随机","1","2","3","4","5"};
 72             List=new JComboBox(zw);
 73             List.setEnabled(false);
 74             List.addActionListener(this);
 75             List.setFont(new Font("宋体", Font.PLAIN, 13));
 76             List.setBounds(10, 10, 75, 21);
 77             panel.add(List);
 78             
 79             textField_zhengshi1 = new JTextField();
 80             textField_zhengshi1.setEditable(false);
 81             textField_zhengshi1.setBounds(10, 77, 240, 21);
 82             panel.add(textField_zhengshi1);
 83             textField_zhengshi1.setColumns(50);
 84             textField_zhengshi1.setText(a[0]);
 85             textField_zhengshi1.addActionListener(this);
 86             
 87             textField_daan1 = new JTextField();
 88             textField_daan1.setBounds(286, 77, 102, 21);
 89             panel.add(textField_daan1);
 90             textField_daan1.addActionListener(this);
 91             textField_daan1.setColumns(20);
 92             
 93             textField_zhengshi2 = new JTextField();
 94             textField_zhengshi2.setEditable(false);
 95             textField_zhengshi2.setBounds(10, 120, 240, 21);
 96             panel.add(textField_zhengshi2);
 97             textField_zhengshi2.setText(a[2]);
 98             textField_zhengshi2.setColumns(50);
 99             
100             textField_daan2 = new JTextField();
101             textField_daan2.setBounds(286, 120, 102, 21);
102             panel.add(textField_daan2);
103             textField_daan2.addActionListener(this);
104             textField_daan2.setColumns(20);
105             
106             textField_zhengshi3 = new JTextField();
107             textField_zhengshi3.setEditable(false);
108             textField_zhengshi3.setBounds(10, 163, 240, 21);
109             panel.add(textField_zhengshi3);
110             textField_zhengshi3.setText(a[4]);
111             textField_zhengshi3.setColumns(50);
112             
113             textField_daan3 = new JTextField();
114             textField_daan3.setBounds(286, 163, 102, 21);
115             panel.add(textField_daan3);
116             textField_daan3.addActionListener(this);
117             textField_daan3.setColumns(20);
118             
119             textField_zhengshi4 = new JTextField();
120             textField_zhengshi4.setEditable(false);
121             textField_zhengshi4.setBounds(10, 206, 240, 21);
122             panel.add(textField_zhengshi4);
123             textField_zhengshi4.setText(a[6]);
124             textField_zhengshi4.setColumns(50);
125             
126             textField_daan4 = new JTextField();
127             textField_daan4.setText("");
128             textField_daan4.setBounds(286, 206, 102, 21);
129             panel.add(textField_daan4);
130             textField_daan4.addActionListener(this);
131             textField_daan4.setColumns(10);
132             
133             textField_zhengshi5 = new JTextField();
134             textField_zhengshi5.setEditable(false);
135             textField_zhengshi5.setBounds(10, 249, 240, 21);
136             panel.add(textField_zhengshi5);
137             textField_zhengshi5.setText(a[8]);
138             textField_zhengshi5.setColumns(50);
139             
140             textField_daan5 = new JTextField();
141             textField_daan5.setBounds(286, 249, 102, 21);
142             panel.add(textField_daan5);
143             textField_daan5.addActionListener(this);
144             textField_daan5.setColumns(20);
145             
146             textField_duicuo1 = new JTextField();
147             textField_duicuo1.setForeground(Color.RED);
148             textField_duicuo1.setBackground(Color.WHITE);
149             textField_duicuo1.setBounds(422, 77, 37, 21);
150             panel.add(textField_duicuo1);
151             textField_duicuo1.setColumns(10);
152             
153             textField_duicuo2 = new JTextField();
154             textField_duicuo2.setForeground(Color.RED);
155             textField_duicuo2.setEnabled(true);
156             textField_duicuo2.setText("");
157             textField_duicuo2.setBounds(422, 120, 37, 21);
158             panel.add(textField_duicuo2);
159             textField_duicuo2.setColumns(10);
160             
161             textField_duicuo3 = new JTextField();
162             textField_duicuo3.setForeground(Color.RED);
163             textField_duicuo3.setEnabled(true);
164             textField_duicuo3.setText("");
165             textField_duicuo3.setBounds(422, 163, 37, 21);
166             panel.add(textField_duicuo3);
167             textField_duicuo3.setColumns(10);
168             
169             textField_duicuo4 = new JTextField();
170             textField_duicuo4.setForeground(Color.RED);
171             textField_duicuo4.setEnabled(true);
172             textField_duicuo4.setText("");
173             textField_duicuo4.setBounds(422, 206, 37, 21);
174             panel.add(textField_duicuo4);
175             textField_duicuo4.setColumns(10);
176             
177             textField_duicuo5 = new JTextField();
178             textField_duicuo5.setForeground(Color.RED);
179             textField_duicuo5.setEnabled(true);
180             textField_duicuo5.setText("");
181             textField_duicuo5.setBounds(422, 249, 37, 21);
182             panel.add(textField_duicuo5);
183             textField_duicuo5.setColumns(10);
184             
185             textField_zhengque1 = new JTextField();
186             textField_zhengque1.setForeground(Color.BLUE);
187             textField_zhengque1.setEditable(false);
188             textField_zhengque1.setBounds(499, 77, 102, 21);
189             panel.add(textField_zhengque1);
190             textField_zhengque1.setColumns(20);
191             
192             textField_zhengque2 = new JTextField();
193             textField_zhengque2.setForeground(Color.BLUE);
194             textField_zhengque2.setEditable(false);
195             textField_zhengque2.setEnabled(true);
196             textField_zhengque2.setText("");
197             textField_zhengque2.setBounds(499, 120, 102, 21);
198             panel.add(textField_zhengque2);
199             textField_zhengque2.setColumns(20);
200             
201             textField_zhengque3 = new JTextField();
202             textField_zhengque3.setForeground(Color.BLUE);
203             textField_zhengque3.setEditable(false);
204             textField_zhengque3.setBounds(499, 163, 102, 21);
205             panel.add(textField_zhengque3);
206             textField_zhengque3.setColumns(20);
207             
208             textField_zhengque4 = new JTextField();
209             textField_zhengque4.setForeground(Color.BLUE);
210             textField_zhengque4.setEditable(false);
211             textField_zhengque4.setBounds(499, 206, 102, 21);
212             panel.add(textField_zhengque4);
213             textField_zhengque4.setColumns(20);
214             
215             textField_zhengque5 = new JTextField();
216             textField_zhengque5.setForeground(Color.BLUE);
217             textField_zhengque5.setEditable(false);
218             textField_zhengque5.setEnabled(true);
219             textField_zhengque5.setText("");
220             textField_zhengque5.setBounds(499, 249, 102, 21);
221             panel.add(textField_zhengque5);
222             textField_zhengque5.setColumns(20);
223             
224             textField_shijian1 = new JTextField();
225             textField_shijian1.setForeground(new Color(255, 0, 102));
226             textField_shijian1.setEditable(false);
227             textField_shijian1.setBounds(621, 77, 66, 21);
228             panel.add(textField_shijian1);
229             textField_shijian1.setColumns(30);
230             
231             textField_shijian2 = new JTextField();
232             textField_shijian2.setForeground(new Color(255, 0, 102));
233             textField_shijian2.setEnabled(true);
234             textField_shijian2.setEditable(false);
235             textField_shijian2.setText("");
236             textField_shijian2.setBounds(621, 120, 66, 21);
237             panel.add(textField_shijian2);
238             textField_shijian2.setColumns(30);
239             
240             textField_shijian3 = new JTextField();
241             textField_shijian3.setForeground(new Color(255, 0, 102));
242             textField_shijian3.setEnabled(true);
243             textField_shijian3.setEditable(false);
244             textField_shijian3.setText("");
245             textField_shijian3.setBounds(621, 163, 66, 21);
246             panel.add(textField_shijian3);
247             textField_shijian3.setColumns(30);
248             
249             textField_shijian4 = new JTextField();
250             textField_shijian4.setForeground(new Color(255, 0, 102));
251             textField_shijian4.setEnabled(true);
252             textField_shijian4.setEditable(false);
253             textField_shijian4.setText("");
254             textField_shijian4.setBounds(621, 206, 66, 21);
255             panel.add(textField_shijian4);
256             textField_shijian4.setColumns(30);
257             
258             textField_shijian5 = new JTextField();
259             textField_shijian5.setForeground(new Color(255, 0, 102));
260             textField_shijian5.setEnabled(true);
261             textField_shijian5.setEditable(false);
262             textField_shijian5.setText("");
263             textField_shijian5.setBounds(621, 249, 66, 21);
264             panel.add(textField_shijian5);
265             textField_shijian5.setColumns(30);
266             
267             textField_zq = new JTextField();
268             textField_zq.setEditable(false);
269             textField_zq.setBounds(10, 340, 66, 21);
270             panel.add(textField_zq);
271             textField_zq.setColumns(20);
272             
273             textField_zql = new JTextField();
274             textField_zql.setEnabled(true);
275             textField_zql.setEditable(false);
276             textField_zql.setText("");
277             textField_zql.setBounds(96, 340, 66, 21);
278             panel.add(textField_zql);
279             textField_zql.setColumns(20);
280             
281             textField_allshijian = new JTextField();
282             textField_allshijian.setEditable(false);
283             textField_allshijian.setBounds(621, 340, 66, 21);
284             panel.add(textField_allshijian);
285             textField_allshijian.setColumns(30);
286             
287             button_daan = new JButton("答案");
288             button_daan.addActionListener(this);
289             button_daan.setBounds(351, 391, 81, 23);
290             panel.add(button_daan);
291             
292             btnNewButton_queding = new JButton("确定");
293             btnNewButton_queding.setBounds(471, 391, 81, 23);
294             btnNewButton_queding.addActionListener(this);
295             panel.add(btnNewButton_queding);
296             
297             btnNewButton_jixv = new JButton("继续答题");
298             btnNewButton_jixv.setBounds(590, 391, 97, 23);
299             btnNewButton_jixv.addActionListener(this);
300             panel.add(btnNewButton_jixv);
301             
302             JLabel label = new JLabel("\u9898\u76EE");
303             label.setBounds(10, 52, 54, 15);
304             panel.add(label);
305             
306             JLabel label_1 = new JLabel("\u8F93\u5165\u7B54\u6848");
307             label_1.setBounds(286, 52, 54, 15);
308             panel.add(label_1);
309             
310             JLabel label_2 = new JLabel("\u5224\u65AD");
311             label_2.setBounds(422, 52, 54, 15);
312             panel.add(label_2);
313             
314             JLabel label_3 = new JLabel("\u53C2\u8003\u7B54\u6848");
315             label_3.setBounds(499, 52, 54, 15);
316             panel.add(label_3);
317             
318             label_4 = new JLabel("\u7B54\u9898\u65F6\u95F4");
319             label_4.setBounds(621, 52, 54, 15);
320             panel.add(label_4);
321             
322             label_5 = new JLabel("\u603B\u65F6\u95F4");
323             label_5.setBounds(621, 315, 54, 15);
324             panel.add(label_5);
325             
326             label_6 = new JLabel("\u6B63\u786E\u9898\u6570");
327             label_6.setForeground(Color.RED);
328             label_6.setBounds(10, 315, 54, 15);
329             panel.add(label_6);
330             
331             label_7 = new JLabel("\u6B63\u786E\u7387");
332             label_7.setForeground(Color.RED);
333             label_7.setBounds(96, 315, 54, 15);
334             panel.add(label_7);
335             Test t=new Test();
336            // t.start();
337             begin=System.currentTimeMillis();
338             
339             
340         
341         
342     
343         setVisible(true);                       //将窗口设置为可视
344         setResizable(false);
345         setAlwaysOnTop(true);//设置此窗口永远为最上方 是window的方法
346         setLocationRelativeTo(null);
347         getContentPane().setLayout(null);
348         
349     }
350     public void setx(String x)
351     {
352         this.x=x;
353     }
354     public String getx()
355     {
356         return x;
357     }
358     public void actionPerformed(ActionEvent e) {
359         if(e.getSource()==button_daan)
360         {
361             textField_zhengque1.setText(c[1]);
362             textField_zhengque2.setText(c[3]);
363             textField_zhengque3.setText(c[5]);
364             textField_zhengque4.setText(c[7]);
365             textField_zhengque5.setText(c[9]);
366             
367         }
368         
369         else if(e.getSource()==textField_daan1)//职务
370             {
371                     if(textField_daan1.getText().equals(c[1]))
372                     {
373                         textField_duicuo1.setText("√");
374                         //t.stop();
375                         //end=System.currentTimeMillis();
376                         sum=(System.currentTimeMillis()-begin)/1000;
377                         textField_shijian1.setText(String.valueOf(sum)+"s");
378                         textField_daan2.requestFocusInWindow(); 
379                         num++;num1++;
380                         textField_zq.setText(String.valueOf(num));
381                         float x=(float)num/num1*100;
382                         textField_zql.setText(String.valueOf(x));
383                     }
384                     else
385                     {
386                     textField_duicuo1.setText("×");
387                     sum=(System.currentTimeMillis()-begin)/1000;
388                     textField_shijian1.setText(String.valueOf(sum)+"s");
389                     num1++;
390                     //textField_shijian1.setText(String.valueOf(t.time));
391                     //t.stop();textField_daan2.requestFocusInWindow(); 
392                     textField_daan2.requestFocusInWindow(); 
393                     textField_zq.setText(String.valueOf(num));
394                     float x=(float)num/num1*100;
395                     textField_zql.setText(String.valueOf(x));
396                     }
397             }
398                     
399                     
400                     
401                     
402                     else if(e.getSource()==textField_daan2)//职务
403                     {
404                         if(textField_daan2.getText().equals(c[3]))
405                         {
406                             textField_duicuo2.setText("√");
407                             sum=(System.currentTimeMillis()-begin)/1000-sum;
408                             //sum=System.currentTimeMillis()/1000-sum;
409                             textField_shijian2.setText(String.valueOf(sum)+"s");
410                             //textField_shijian2.setText(String.valueOf((System.currentTimeMillis()-begin)/1000));
411                             num++;num1++;
412                             textField_zq.setText(String.valueOf(num));
413                             float x=(float)num/num1*100;
414                             textField_zql.setText(String.valueOf(x));
415                         }
416                         else
417                         {
418                             
419                             if(c[3].equals(""))
420                             {
421                                 textField_duicuo2.setText("none");
422                             }
423                             
424                             else
425                             {
426                             textField_duicuo2.setText("×");
427                             //sum=System.currentTimeMillis()/1000-sum;
428                             sum=(System.currentTimeMillis()-begin)/1000-sum;
429                             textField_shijian2.setText(String.valueOf(sum)+"s");
430                             num1++;
431                             //textField_shijian2.setText(String.valueOf((System.currentTimeMillis()-begin)/1000));
432                             textField_zq.setText(String.valueOf(num));
433                             float x=(float)num/num1*100;
434                             textField_zql.setText(String.valueOf(x));
435                             }
436                             
437                         }
438                         textField_daan3.requestFocusInWindow(); 
439                     }
440                     else if(e.getSource()==textField_daan3)//职务
441                     {
442                         Test t=new Test();
443                         t.start();
444                         
445                         if(textField_daan3.getText().equals(c[5]))
446                         {
447                             textField_duicuo3.setText("√");
448                             sum=(System.currentTimeMillis()-begin)/1000-sum;
449                             //sum=System.currentTimeMillis()/1000-sum;
450                             textField_shijian3.setText(String.valueOf(sum)+"s");
451                             num++;num1++;
452                             textField_zq.setText(String.valueOf(num));
453                             float x=(float)num/num1*100;
454                             textField_zql.setText(String.valueOf(x));
455                             //textField_shijian3.setText(String.valueOf((System.currentTimeMillis()-begin)/1000));
456                         }
457                         else
458                         {
459                             if(c[5].equals(""))
460                             {
461                                 textField_duicuo3.setText("none");
462                             }
463                             else
464                             {
465                             textField_duicuo3.setText("×");
466                             //sum=System.currentTimeMillis()/1000-sum;
467                             sum=(System.currentTimeMillis()-begin)/1000-sum;
468                             textField_shijian3.setText(String.valueOf(sum)+"s");
469                             num1++;
470                             //textField_shijian3.setText(String.valueOf((System.currentTimeMillis()-begin)/1000));
471                             textField_zq.setText(String.valueOf(num));
472                             float x=(float)num/num1*100;
473                             textField_zql.setText(String.valueOf(x));
474                             }
475                         }
476                         textField_daan4.requestFocusInWindow(); 
477                     }
478                     else if(e.getSource()==textField_daan4)//职务
479                     {
480                         if(textField_daan4.getText().equals(c[7]))
481                         {
482                             textField_duicuo4.setText("√");
483                             sum=(System.currentTimeMillis()-begin)/1000-sum;
484                             //sum=System.currentTimeMillis()/1000-sum;
485                             textField_shijian4.setText(String.valueOf(sum)+"s");
486                             num++;num1++;
487                             textField_zq.setText(String.valueOf(num));
488                             float x=(float)num/num1*100;
489                             textField_zql.setText(String.valueOf(x));
490                             //textField_shijian4.setText(String.valueOf((System.currentTimeMillis()-begin)/1000));
491                         }
492                         else
493                         {
494                             if(c[7].equals(""))
495                             {
496                                 textField_duicuo4.setText("none");
497                             }
498                             else
499                             {
500                             textField_duicuo4.setText("×");
501                             //sum=System.currentTimeMillis()/1000-sum;
502                             sum=(System.currentTimeMillis()-begin)/1000-sum;
503                             textField_shijian4.setText(String.valueOf(sum)+"s");
504                             num1++;
505                             //textField_shijian4.setText(String.valueOf((System.currentTimeMillis()-begin)/1000));
506                             textField_zq.setText(String.valueOf(num));
507                             float x=(float)num/num1*100;
508                             textField_zql.setText(String.valueOf(x));
509                             }
510                         }
511                         textField_daan5.requestFocusInWindow(); 
512                     }
513                     else if(e.getSource()==textField_daan5)//职务
514                     {
515                         if(textField_daan5.getText().equals(c[9]))
516                         {
517                             sum=(System.currentTimeMillis()-begin)/1000-sum;
518                             //sum=System.currentTimeMillis()/1000-sum;
519                             textField_shijian5.setText(String.valueOf(sum)+"s");
520                             //textField_shijian5.setText(String.valueOf((System.currentTimeMillis()-begin)/1000));
521                             textField_duicuo5.setText("√");
522                             num++;num1++;
523                             textField_zq.setText(String.valueOf(num));
524                             float x=(float)num/num1*100;
525                             textField_zql.setText(String.valueOf(x));
526                             
527                             
528                         }
529                         else
530                         {
531                             if(c[9].equals(""))
532                             {
533                                 textField_duicuo5.setText("none");
534                             }
535                             else
536                             {
537                             textField_duicuo5.setText("×");
538                             //sum=System.currentTimeMillis()/1000-sum;
539                             sum=(System.currentTimeMillis()-begin)/1000-sum;
540                             textField_shijian5.setText(String.valueOf(sum)+"s");
541                             //textField_shijian5.setText(String.valueOf((System.currentTimeMillis()-begin)/1000));
542                             num1++;
543                             textField_zq.setText(String.valueOf(num));
544                             float x=(float)num/num1*100;
545                             textField_zql.setText(String.valueOf(x));
546                             }
547                         }
548                         btnNewButton_queding.requestFocusInWindow(); 
549                     }
550         
551         
552         
553         else if(e.getSource()==btnNewButton_queding)//职务
554         {
555             //t.stop();
556             textField_allshijian.setText(String.valueOf((System.currentTimeMillis()-begin)/1000)+"s");
557         }
558         else if(e.getSource()==btnNewButton_jixv)//职务
559         {
560             //t.stop();
561             //textField_allshijian.setText(String.valueOf((System.currentTimeMillis()-begin)/1000)+"s");
562             setVisible(false); 
563             new NewFrame1("背景图片/5.jpg.");
564             
565         }
566         
567         
568     }
569 }
NewFrame3
 1 package size;
 2 import java.awt.*;
 3 import javax.swing.*;
 4 import java.awt.event.*;
 5 import java.io.*;
 6 import java.util.Date;
 7 public class Select extends JFrame implements ActionListener{
 8     public JButton btnNewButton_jiecheng;
 9     public JButton btnNewButton_size;
10     public Select()
11     {
12         super("选择界面");
13         setSize(345,266);
14         setVisible(true);                       //将窗口设置为可视
15         setResizable(false);
16         setAlwaysOnTop(true);//设置此窗口永远为最上方 是window的方法
17         setLocationRelativeTo(null);
18         getContentPane().setLayout(null);
19         
20         JPanel panel = new JPanel();
21         panel.setBackground(new Color(0, 0, 139));
22         panel.setForeground(Color.BLUE);
23         panel.setBounds(0, 0, 339, 239);
24         getContentPane().add(panel);
25         panel.setLayout(null);
26         
27          btnNewButton_size = new JButton("\u56DB\u5219\u8FD0\u7B97");
28         btnNewButton_size.setForeground(Color.RED);
29         btnNewButton_size.setBounds(128, 76, 93, 23);
30         btnNewButton_size.addActionListener(this);
31         panel.add(btnNewButton_size);
32         
33         btnNewButton_jiecheng = new JButton("\u9636\u4E58\u8FD0\u7B97");
34         btnNewButton_jiecheng.setForeground(Color.RED);
35         btnNewButton_jiecheng.setBounds(128, 142, 93, 23);
36         btnNewButton_jiecheng.addActionListener(this);
37         panel.add(btnNewButton_jiecheng);
38     }
39     public void actionPerformed(ActionEvent e) 
40     {
41         if(e.getSource()==btnNewButton_size)
42         {
43             
44             new NewFrame1("背景图片/5.jpg.");
45         }
46         else if(e.getSource()==btnNewButton_jiecheng)
47         {
48             new NewFrame2("背景图片/4.jpg.");
49         }
50     }
51 }
Select
 1 package size;
 2 import java.text.SimpleDateFormat;
 3 import java.util.*;
 4 
 5 public class Test implements Runnable {
 6 
 7  //定义一个线程
 8  Thread thread;
 9  //用于停止线程的标志
10  private boolean flag=true;
11  public long time,beginTime;
12  public Test(){
13   thread=new Thread(this);
14  }
15  //因为该类实现了Runnable,就必须有run方法,当线程启动时,会调用这个run方法
16  public void run(){
17   //获得当前的时间,毫秒为单位
18   //long beginTime=System.currentTimeMillis();
19   beginTime=System.currentTimeMillis();
20   
21   //定义已过去的时间
22   time=0;
23   while(flag){
24    //这里写实现计时的代码
25    //在这里,获得已过去的时间
26    time=(System.currentTimeMillis()-beginTime)/1000;
27   // System.out.println("已过"+time+"毫秒");
28    //System.out.println("显示当前时间:"+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(System.currentTimeMillis()));
29 
30    //System.out.print(time);
31    //暂停线程1秒钟,不暂停的话可以把下面代码去掉
32    try{
33     Thread.sleep(1000);
34    }catch(InterruptedException e1){
35     e1.printStackTrace();
36    }
37    /*if(time==7)
38    {
39        try {
40         thread.wait();
41     } catch (InterruptedException e) {
42         // TODO Auto-generated catch block
43         e.printStackTrace();
44         //System.out.print("tingxia lai le");
45     }
46    }*/
47   }
48  }
49  //这里是启动线程的方法,也就是启动线程
50  public void start(){
51   thread.start();
52  }
53  //这里是暂停的方法,暂停线程
54  public void Pause(){
55   try{
56    thread.wait();
57   }catch(InterruptedException e){
58    e.printStackTrace();
59   }
60  }
61  //这里是继续的方法,唤醒线程
62  public void Resume(){
63   thread.notifyAll();
64  }
65  //停止线程
66  public void stop(){
67   //把flag设成false,则在run中的while循环就会停止循环
68   flag=false;
69  }
70  
71  public static void main(String []args){
72   //用于测试
73   Test t=new Test();
74   Test t1=new Test();
75   //开始线程
76   t.start();
77   t1.start();
78   //System.out.print(t.time);
79  //System.out.println("显示当前时间:"+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(System.currentTimeMillis()));
80   try{
81    //10000毫秒以后结束线程
82   Thread.sleep(5000);
83   }catch(InterruptedException e1){
84   e1.printStackTrace();
85   }
86 
87   //结束线程
88   t.stop();
89 
90    
91    }
92  
93 }
Test
 1 package size;
 2 
 3 import java.math.*;
 4 import java.text.DecimalFormat;
 5 import java.util.Random;
 6 
 7 public class Test1 {
 8     public int i,j=1,l;
 9     public BigDecimal k= new BigDecimal(1);
10     
11     //DecimalFormat df=new DecimalFormat("#,##");
12       //String result=df.format(dValue)
13     String []v=new String [10];
14 
15     Test1(String a)
16     {
17         for(l=0;l<10;l++)
18         {
19             v[l]="";
20         }
21         l=0;
22         for(int f=0;f<Integer.parseInt(a);f++)
23         {
24         BigDecimal.valueOf(j);
25         
26         Random z=new Random();
27         i=z.nextInt(9)+1;
28         v[l]=String.valueOf(i);
29         v[l]+="!";
30         System.out.print(i+"!=");
31         do
32         {
33             k=k.multiply(BigDecimal.valueOf(j)); 
34             j++;
35             
36         }while(j<=i);
37         System.out.print(k+"\n");//df.format(k)
38         l++;v[l]=String.valueOf(k);l++;
39         k=new BigDecimal(1);
40         j=1;
41         }
42         
43         new NewFrame3(v);
44     }
45     
46 }
Test1
  1 package size;
  2 import java.util.Random;
  3 import java.util.Scanner;
  4 
  5 
  6 public class Test2 {
  7     public int sighfh,fuhaosl;
  8     public float sighsz1,sighsz2,answer2,sum2=0,sum3=0;
  9     public float []sighsz=new float[30];
 10     public String []fuhaoq={"+","-","*","/"};
 11     public String []fuhao=new String[30];
 12     public String fuhao2,answer1,s;
 13     public String []zhengshi=new String[200];
 14     public String []first=new String[100];
 15     public String []second=new String[100];
 16     public String []three=new String[100];
 17     public String temp1="null";
 18     public int i=0,jia=0,jian=0,q=0,x=0,chen=0,chu=0,temp2,j=0,c,op=0;
 19     public float sum=0;
 20     public Test2(String x)
 21     {
 22         String[]xx=new String[10];
 23         for(c=0;c<10;c++)
 24             xx[c]="";
 25         c=0;
 26         for(int x1=0;x1<Integer.parseInt(x);x1++)
 27         {
 28         Random z=new Random();
 29         sighsz1=z.nextFloat()*10;
 30 
 31         int k=0;
 32         sighsz1=(float)(Math.round(sighsz1*100))/100;
 33 
 34         zhengshi[k]=String.valueOf(sighsz1);
 35 
 36         fuhaosl=z.nextInt(3)+1;
 37         //fuhaosl=4;
 38         //System.out.printf("fuhaosl=%d\n",fuhaosl);
 39 
 40         for(i=1;i<=fuhaosl;i++)
 41         {                                                                    
 42             sighfh=z.nextInt(4);
 43 
 44             switch(sighfh)
 45             {
 46             case 0:zhengshi[k]+="\t+\t";sighsz[k]=z.nextFloat()*100;sighsz[k]=(float)(Math.round(sighsz[k]*100))/100;
 47             zhengshi[k]+=String.valueOf(sighsz[k]);
 48 
 49             jia++;
 50 
 51             break;
 52             case 1:zhengshi[k]+="\t-\t";
 53             sighsz[k]=z.nextFloat()*100;sighsz[k]=(float)(Math.round(sighsz[k]*100))/100;
 54             zhengshi[k]+=String.valueOf(sighsz[k]);
 55 
 56             jian++;
 57             break;
 58             case 2:zhengshi[k]+="\t*\t";
 59             sighsz[k]=z.nextFloat()*100;sighsz[k]=(float)(Math.round(sighsz[k]*100))/100;
 60             zhengshi[k]+=String.valueOf(sighsz[k]);
 61 
 62             chen++;
 63             break;
 64             case 3:zhengshi[k]+="\t/\t";
 65             sighsz[k]=z.nextFloat()*100;sighsz[k]=(float)(Math.round(sighsz[k]*100))/100;
 66             zhengshi[k]+=String.valueOf(sighsz[k]);
 67 
 68             chu++;
 69             break;
 70 
 71             }
 72 
 73         }
 74         zhengshi[k]+="\t=\t";
 75         //System.out.printf("%s",zhengshi[k]);
 76         String temp="";
 77         //zhengshi[k]="1.1\t+\t2.2\t+\t3.3\t*\t5.5\t=\t";
 78 
 79         System.out.printf("%s",zhengshi[k]);
 80         String []first=new String[200];
 81         String []second=new String[200];
 82 
 83         String[] zhengshi1=new String[200];
 84         int q=0,i1=0,i2=0,j=0;
 85         i=0;
 86 
 87         temp = zhengshi[k];
 88         //temp="\t=\t";
 89         zhengshi1= temp.trim().split("\t");
 90         while(op<=fuhaosl*2+1)
 91         {
 92             xx[c]+=zhengshi1[op];
 93             //System.out.print(zhengshi1[op]);
 94             op++;
 95         }
 96         
 97         int y=0;
 98         while(zhengshi1[y]==null)
 99         {
100             if(zhengshi1[y].equals("/"))
101             {
102                 while(Float.parseFloat(zhengshi1[y+1])/1==0)
103                 {
104                     zhengshi1[y+1]=String.valueOf((float)(Math.round(sighsz1*100))/100);
105                 }
106             }
107             y++;
108         }
109         
110         i=0;j=0;k=0;
111         while(zhengshi1[i].equals("=")==false )
112         {
113             //System.out.print(i);
114             
115             try
116             {
117                 if(Float.parseFloat(zhengshi1[i])>=0 && Float.parseFloat(zhengshi1[i])<=100)
118                 {
119                     first[j]=zhengshi1[i];//System.out.print(first[j]+"我进栈了,"+"现在的i是"+i);
120                     j++;i++;
121                 }
122             }
123             catch(NumberFormatException E)
124             {
125                 if(second[0]==null)
126                 {
127                     second[k]=zhengshi1[i];
128                     ///System.out.print(second[k]+"我进栈了,"+"现在的i是"+i);
129                     k++;i++;
130                 }
131                 else
132                 {
133                 
134                     if(compare(second[k-1],zhengshi1[i],first))
135                     {
136         
137                             if(first[k].equals(null))
138                             {
139                                 second[k]=zhengshi1[i];//System.out.print(second[k]+"我进栈了,"+"现在的i是"+i+"!!!!");
140                                 k++;i++;
141                             }
142                             else
143                             {
144                                 if(second[k-1].equals("+"))
145                                 {
146                                     sum=Float.parseFloat(first[k-1])+Float.parseFloat(first[k]);
147                                     //System.out.print(first[k-1]+","+first[k]+"我们出栈了,"+"现在的i是"+i);
148                                     //System.out.print(second[k-1]+"我出栈了,"+"现在的i是"+i);
149                                     first[k-1]=String.valueOf(sum);first[k]=null;second[k-1]=zhengshi1[i];
150                                     //System.out.print("\n答案暂时是:"+sum+"\n");
151                                     j--;i++;
152                                 }
153                                 else if(second[k-1].equals("-"))
154                                 {
155                                     sum=Float.parseFloat(first[k-1])-Float.parseFloat(first[k]);
156                                     //System.out.print(first[k-1]+","+first[k]+"我们出栈了,"+"现在的i是"+i);
157                                     //System.out.print(second[k-1]+"我出栈了,"+"现在的i是"+i);
158                                     first[k-1]=String.valueOf(sum);first[k]=null;second[k-1]=zhengshi1[i];
159                                     //System.out.print("\n答案暂时是:"+sum+"\n");
160                                     j--;i++;
161                                 }
162                                 else if(second[k-1].equals("*"))
163                                 {
164                                     sum=Float.parseFloat(first[k-1])*Float.parseFloat(first[k]);
165                                     //System.out.print(first[k-1]+","+first[k]+"我们出栈了,"+"现在的i是"+i);
166                                     //System.out.print(second[k-1]+"我出栈了,"+"现在的i是"+i);
167                                     first[k-1]=String.valueOf(sum);first[k]=null;second[k-1]=zhengshi1[i];
168                                     //System.out.print("\n答案暂时是:"+sum+"\n");
169                                     j--;i++;
170                                 }
171                                 else if(second[k-1].equals("/"))
172                                 {
173                                     sum=Float.parseFloat(first[k-1])/Float.parseFloat(first[k]);
174                                     //System.out.print(first[k-1]+","+first[k]+"我们出栈了,"+"现在的i是"+i);
175                                     //System.out.print(second[k-1]+"我出栈了,"+"现在的i是"+i);
176                                     first[k-1]=String.valueOf(sum);first[k]=null;second[k-1]=zhengshi1[i];
177                                     //System.out.print("\n答案暂时是:"+sum+"\n");
178                                     j--;i++;
179                                 }
180                                     
181                             }
182                         }
183                         
184                     
185                     else
186                     {
187                         
188                         second[k]=zhengshi1[i];
189                         //System.out.print(second[k]+","+second[k]+"我进栈了,"+"现在的i是"+i);
190                         
191                         i++;k++;
192                         
193                     }
194                     
195                 }
196             }
197     
198             
199 
200 
201         }
202         
203         /*if(second[0]==null)
204         {
205             System.out.print("答案为:"+sum);
206             System.out.print("结束战斗!!!");
207         }
208         else
209         {*/
210             
211             while(second[0]!=null)
212             {
213                 //if(second[sign]!=null)                                            //*********************************************
214                 //System.out.print("kkk===="+k);
215                 if(second[k-1].equals("+"))
216                 {
217                     sum=Float.parseFloat(first[k-1])+Float.parseFloat(first[k]);
218                     //System.out.print("\n答案暂时是:"+sum+"\n");
219                     first[k-1]=String.valueOf(sum);first[k]=null;second[k-1]=null;
220                     j--;k=k-1;i++;
221                     //if(second(1)!=null)//*********************************************
222                     
223                     //System.out.print("\n答案为:"+sum);
224                 }
225                 else if(second[k-1].equals("-"))
226                 {
227                     sum=Float.parseFloat(first[k-1])-Float.parseFloat(first[k]);
228                     //System.out.print("\n答案暂时是:"+sum+"\n");
229                     first[k-1]=String.valueOf(sum);first[k]=null;second[k-1]=null;
230                     j--;k=k-1;i++;
231                     
232                     //System.out.print("\n答案为:"+sum);
233                 }
234                 else if(second[k-1].equals("*"))
235                 {
236                     sum=Float.parseFloat(first[k-1])*Float.parseFloat(first[k]);
237                     //System.out.print("\n答案暂时是:"+sum+"\n");
238                     first[k-1]=String.valueOf(sum);first[k]=null;second[k-1]=null;
239                     j--;k=k-1;i++;
240                     
241                     //System.out.print("\n答案为:"+sum);
242                 }
243                 else if(second[k-1].equals("/"))
244                 {
245                     sum=Float.parseFloat(first[k-1])/Float.parseFloat(first[k]);
246                     //System.out.print("\n答案暂时是:"+sum+"\n");
247                     first[k-1]=String.valueOf(sum);first[k]=null;second[k-1]=null;
248                     j--;k=k-1;i++;
249                     
250                     //System.out.print("\n答案为:"+sum);
251                 }
252                 
253             }
254             sum=(float)(Math.round(sum*100))/100;
255             System.out.print("\n答案为:"+sum+"\t");
256             c++;
257             xx[c]=String.valueOf(sum);c++;op=0;
258         }
259         int qw=0;
260         new NewFrame(xx);
261         
262         
263     }
264     boolean compare(String x1,String x2,String x3[]) //true 出栈,flase 进栈
265     {
266         int i,j,k;
267         if(x2.equals("+") || x2.equals("-"))
268             return true;
269         else
270         {
271             if(x1.equals("*") || x1.equals("/"))
272             {
273                 return true;
274             }
275             else
276             {
277                 return false;
278             }
279         }
280     }
281     /*public static void main(String[]args)
282     {
283         Scanner in=new Scanner(System.in);
284         String b=String.valueOf(in.nextInt());
285         test2 a=new test2 (b);
286     }*/
287 
288 }
Test2

posted @ 2015-04-10 17:47  就是kv啊  Views(227)  Comments(1Edit  收藏  举报