Import java.awt.*;import java.awt.event.*;import javax.swing.*;p ublic class Size {public static void main (string[] Arg s) {//TODO auto-generated method stub myframe f=new myframe (); }}class MyFrame extends jframe{JLabel l1=new JLabel ("title:"); JLabel l2=new JLabel ("Number of input questions:"); JLabel l3=new JLabel ("Hint:"); JLabel l4=new JLabel (""); Title JLabel l5=new JLabel ("The number of topics cannot be greater than 5"); Hint JTextField t1=new JTextField (6); JButton b1=new JButton ("Start"); JButton b2=new JButton ("confirmation"); JButton b3=new JButton ("Next question"); JButton b4=new JButton ("Skin Change"); JPanel p1=new JPanel (); int n=0,a,b,c,d,j,k,l,m=0,p; Double result; char[]h={' + ', '-', ' * ', '/'},h1={' (', ') ', '! '}; String s1,s2; Color Col[]={color.blue,color.green,color.orange,color.pink,color.gray,color.red,color.light_gray}; MyFrame () {This.settitle ("arithmetic"); This.setsize (300,280); This.setdefaultcloseoperation (Jframe.dispose_on_close); This.add (p1); P1.setlayout (NULL); L1.setbounds (50, 20, 90, 30); P1.add (L1); L4.setbounds (140, 20, 150, 30); P1.add (L4); L2.setbounds (50, 70, 90, 30); P1.add (L2); T1.setbounds (150, 70, 90, 30); P1.add (T1); B4.setbounds (100, 110, 90, 30); P1.add (B4); B1.setbounds (10, 150, 90, 30); P1.add (B1); B2.setbounds (100, 150, 90, 30); P1.add (B2); B2.setenabled (FALSE); B3.setbounds (190, 150,90,30); P1.add (B3); L3.setbounds (50, 200, 50, 30); B3.setenabled (FALSE); P1.add (L3); L5.setbounds (100, 200, 180, 30); P1.add (L5); This.setvisible (TRUE); This.setlocationrelativeto (NULL); B1.addactionlistener (New B ()); B2.addactionlistener (New B ()); B3.addactionlistener (New B ()); B4.addactionlistener (New B ()); } class B implements ActionListener {@Override public void actionperformed (ActionEvent e) { TODO auto-generated Method Stub if (E.getsource () ==b1) {p=n= (int) Double.parsedo Uble (T1.gettext ()); System.out.print (n); if (n>5| | n<1) {Joptionpane.showmessagedialog (null, "the number of inputs cannot be greater than 5 or less than 1", "note", Joptionpane.informat Ion_message); } else {b1.setenabled (false); B2.setenabled (TRUE); B3.setenabled (TRUE); L2.settext ("Input answer:"); L5.settext (NULL); T1.settext (NULL); Star (); }} if (E.getsource () ==b2) {l= (int) double.parsedouble (T1.gettext ()); if (L==result) {m++; S2= "The answer is right! "; L5.settext (S2); } else{s2= "answer wrong!" The answer is: "+String.valueof (result); L5.settext (S2); } b2.setenabled (FALSE); } if (E.getsource () ==b3) {if (n==0) {joptionpane.sh Owmessagedialog (NULL, "Altogether" +p+ "Road topic". The correct number of questions is: "+m," "Score", joptionpane.information_message); B1.setenabled (TRUE); B2.setenabled (FALSE); B3.setenabled (FALSE); L2.settext ("Number of input questions:"); L4.settext (NULL); T1.settext (NULL); } else {l5.settext (null); T1.settext (NULL); Star (); B2.setenabled (TRUE); }} if (E.getsource () ==b4) {int i; i= (int) (Math.random () *6); P1.setbackground (Col[i]); }}} void Star () {a= (int) (Math.random () *10); b= (int) (Math.random () *10); c= (int) (Math.random () *10); d= (int) (Math.random () *10); j= (int) (Math.random ()); k= (int) (Math.random ()); if (d<0) {a= (int) (Math.random () *9+1); S1=string.valueof (a) +string.valueof (h1[2]); L4.settext (S1); Result=1; for (int i=1;i<=a;i++) {result=result*i; }} else {if (b>=0&&c>=0) {s1=string.valueof (a) +s Tring.valueof (H[j]) +string.valueof (b) +string.valueof (H[k]) +string.valueof (c); L4.settext (S1); System.out.println (S1); } else if (b<0&&c>=0) {s1=string.valueof (a) +string.valueof (H[j]) +string . ValueOf (H1[0]) +string.valueof (b) +string.valueof (h1[1]) +string.valueof (H[k]) +string.valueof (c); L4.settext (S1); System.out.println (S1); } else if (b>=0&&c<0) {s1=string.valueof (a) +string.valueof (H[j]) +string . ValueOf (b) +string.valueof (H[k]) +string.valueof (h1[0]) +string.valueof (c) +string.valueof (h1[1]); L4.settext (S1); System.out.println (S1); } else {s1=string.valueof (a) +string.valueof (H[j]) +string.valueof (h1[0]) +string.value of (b) +string.valueof (h1[1]) +string.valueof (H[k]) +string.valueof (h1[0]) +string.valueof (c) +string.valueof (H1[1]) ; L4.settext (S1); System.out.println (S1); } if (k>1)//After the calculation is multiplication, first count the next two number {if (k==2) {ResU Lt=b*c; } else if (k==3) {result=b/c; } if (j==0) {result=result+a; } else if (j==1) {result=a-result; } else if (j==2) {result=a*result; } else if (j==3) {result=a/result; }} else if (k<2) {if (j==0) {result= B+a; } else if (j==1) {result=a-b; } else if (j==2) {result=a*b; } else if (j==3) {result=a/b; } if (k==0) result=result+c; if (k==1) result=result-c; }} System.out.println (Result); n--; }}
Summary: This time and teammates have Cypress (http://www.cnblogs.com/cypress-zeng/) improved procedures, more than the last progress, hope the teacher corrected.
Job 5.2 Testing and encapsulation