Math problem practice, correct a question, in the text area to print out, answer wrong error, a total of 10 simple math problems
//mathproblem.java mainly involves the interface font
Importjava.awt.*;Importjava.awt.event.*;ImportJavax.swing.JTextArea;ImportJavax.swing.JTextField; Public classMathproblemextendsFrameImplementsActionListener {Private Static Final LongSerialversionuid = 1L; TextArea Ta; JTextField TF1,TF2; Label lb1,lb2; Button BT1,BT2,BT3; Panel P1,P2,P3,P4,P5,P6; Frame F; Font fo; Color color; String Tips1; String TIPS2; inti; Question Qu=NewQuestion (); Mathproblem () {fo=NewFont ("Arial", font.bold,20); Color=Color.Black; Tips1= "Answer right!" "; TIPS2= "Answer the wrong!" "; I=0; Ta=NewTextArea (); Ta.setfont (FO); Ta.setforeground (color); Ta.setsize (480, 180); Ta.seteditable (true); TF1=NewJTextField (20); TF2=NewJTextField (10); Tf1.sethorizontalalignment (Jtextfield.center); Tf1.settext (Qu.math[i]); Tf1.seteditable (true); Tf2.seteditable (true); LB1=NewLabel ("title:"); LB2=NewLabel ("Answer:"); BT1=Newbutton ("OK"); BT2=NewButton ("Previous question"); BT3=NewButton ("Next question"); Bt1.addactionlistener ( This); Bt2.addactionlistener ( This); Bt3.addactionlistener ( This); P1=NewPanel (); P2=NewPanel (); P3=NewPanel (); P1.add (TA); P2.add (LB1); P2.add (TF1); P2.add (LB2); P2.add (TF2); P3.setlayout (NewGridLayout (1,3)); P3.add (BT1); P3.add (BT2); P3.add (BT3); F=NewFrame ("Exercises"); F.setvisible (true); F.setresizable (false); F.setsize (700, 370); F.setlocationrelativeto (NULL); F.add (P1,borderlayout.north); F.add (P2,borderlayout.center); F.add (P3,borderlayout.south); F.addwindowlistener (NewWindowadapter () { Public voidwindowclosing (windowevent e) {system.exit (0); } }); } Public voidactionperformed (ActionEvent e) {if(E.getsource (). Equals (BT1)) {if(Tf2.gettext (). Equals (Qu.mathkey[i])) {Ta.setforeground (color. GREEN); Ta.settext (Qu.math[i]+qu.mathkey[i]+ "\ n" +TIPS1); } Else{ta.settext (TIPS2); Ta.setforeground (color. RED); } } if(E.getsource (). Equals (BT2)) {i--; Ta.setforeground (color); if(i>=0) {Tf1.settext (qu.math[i]); Tf2.settext (NULL); Ta.settext (NULL); } Else{Ta.settext ("It's already the first question!" "); I=0; } } if(E.getsource (). Equals (BT3)) {i++; Ta.setforeground (color); if(i<=9) {Tf1.settext (qu.math[i]); Tf2.settext (NULL); Ta.settext (NULL); } Else{Ta.settext ("It's the last question!" "); I=9; } } } Public Static voidMain (String args[]) {Mathproblem MP=NewMathproblem (); }}
//question.java Placement Questions and Answers
Public classQuestion {string[] math; String mathkey[]={"2", "4", "8", "2", "7", "45", "4", "124", "132", "1"}; Question () {Math=NewString[10]; math[0]= "1+1="; math[1]= "10-6 ="; math[2]= "2*4="; math[3]= "6÷3="; math[4]= "1+2*3="; math[5]= "(100-10) *2="; math[6]= "(7+1) ÷2="; math[7]= "1+123="; math[8]= "64÷2+100="; math[9]= "8+1-8="; }}
Java applet 1