Pairing work (Beta)

Source: Internet
Author: User

The students of this pair are:

201306114314 Li Yanjiang

201306114309 She Hongyue

Package Computeproject;import Java.awt.color;import Java.awt.component;import java.awt.font;import Java.awt.graphics;import Java.awt.graphics2d;import Java.awt.image;import Java.awt.rectangle;import Java.awt.toolkit;import Java.awt.event.actionevent;import Java.awt.event.actionlistener;import Java.util.arraylist;import Java.util.random;import Javax.swing.jbutton;import Javax.swing.JFrame;import  Javax.swing.jlabel;import Javax.swing.joptionpane;import Javax.swing.jpanel;import Javax.swing.JTextField;public Class MainFrame extends JFrame implements actionlistener{private JLabel TIME,JBL0,JBL1,JBL2,JBL3,JBL4,JBL5,JBL6,JBL7,  Jbl8,jbl9,jbl10, JBL11,JBL12,JBL13,JBL14,JBL15,JBL16,JBL17,JBL18,JBL19,JBL20; Private JTextField Jtf1,jtf2,jtf3,jtf4,jtf5,jtf6,jtf7,jtf8,jtf9,jtf10, Jtf11,jtf12,jtf13,jtf14,jtf15,jtf16,jtf17, Jtf18,jtf19,jtf20;  Private JButton jb1,jb2,jb3;   Private JPanel JP1,JP2;  Private ArrayList questions,answers,results;  private static int right=0,wrong=0; private int Score=0;     Private String S=null;    Class Bgpanel extends JPanel {public void paintcomponent (Graphics g) {graphics2d GD = (graphics2d) g;     Super.paintcomponent (g);    Image img = Toolkit.getdefaulttoolkit (). GetImage ("images/main.jpg");   Gd.drawimage (IMG, 0, 0, this.getwidth (), This.getheight (), this);} } public MainFrame () {this.   Initquestion ();   JP1 = new JPanel ();    Jp1.setlayout (NULL);    Jp1.setbounds (0,100,800,400);    Jp1.setopaque (FALSE);    JBL1 = new JLabel ("First question:");   Jbl1.setbounds (New Rectangle (120,0,50,30));   Jbl1.setforeground (Color.yellow);    JBL2 = new JLabel ("Second question:");   Jbl2.setbounds (New Rectangle (120,40,50,30));   Jbl2.setforeground (Color.yellow);    JBL3 = new JLabel ("Third question:");   Jbl3.setbounds (New Rectangle (120,80,50,30));   Jbl3.setforeground (Color.yellow);    JBL4 = new JLabel ("Fourth question:");   Jbl4.setbounds (New Rectangle (120,120,50,30));   Jbl4.setforeground (Color.yellow);    JBL5 = new JLabel ("Fifth question:");   Jbl5.setbounds (New Rectangle (120,160,50,30)); Jbl5.Setforeground (Color.yellow);    JBL6 = new JLabel ("Sixth question:");   Jbl6.setbounds (New Rectangle (120,200,50,30));   Jbl6.setforeground (Color.yellow);    JBL7 = new JLabel ("Seventh question:");   Jbl7.setbounds (New Rectangle (120,240,50,30));   Jbl7.setforeground (Color.yellow);    Jbl8 = new JLabel ("Eighth question:");   Jbl8.setbounds (New Rectangle (120,280,50,30));   Jbl8.setforeground (Color.yellow);    JBL9 = new JLabel ("Nineth question:");   Jbl9.setbounds (New Rectangle (120,320,50,30));   Jbl9.setforeground (Color.yellow);    Jbl10 = new JLabel ("Tenth question:");   Jbl10.setbounds (New Rectangle (120,360,50,30));    Jbl10.setforeground (Color.yellow);    Jbl11 = new JLabel ("=");   Jbl11.setbounds (New Rectangle (440,0,50,30));   Jbl11.setforeground (Color.yellow);    jbl12 = new JLabel ("=");   Jbl12.setbounds (New Rectangle (440,40,50,30));     Jbl12.setforeground (Color.yellow);   Jbl13 = new JLabel ("="); Jbl13.setbounds (new Rectangle (440,80,50,30));   Jbl13.setforeground (Color.yellow);    Jbl14 = new JLabel ("="); Jbl14.setbounds (New RecTangle (440,120,50,30));   Jbl14.setforeground (Color.yellow);    Jbl15 = new JLabel ("=");   Jbl15.setbounds (New Rectangle (440,160,50,30));   Jbl15.setforeground (Color.yellow);    Jbl16 = new JLabel ("=");   Jbl16.setbounds (New Rectangle (440,200,50,30));   Jbl16.setforeground (Color.yellow);    JBL17 = new JLabel ("=");   Jbl17.setbounds (New Rectangle (440,240,50,30));    Jbl17.setforeground (Color.yellow);    Jbl18 = new JLabel ("=");   Jbl18.setbounds (New Rectangle (440,280,50,30));   Jbl18.setforeground (Color.yellow);    jbl19 = new JLabel ("=");   Jbl19.setbounds (New Rectangle (440,320,50,30));   Jbl19.setforeground (Color.yellow);    JBL20 = new JLabel ("=");   Jbl20.setbounds (New Rectangle (440,360,50,30));   Jbl20.setforeground (Color.yellow);    JTF1 = new JTextField ();   Jtf1.sethorizontalalignment (Jtextfield.center);  Jtf1.settext (String) questions.get (0));    Jtf1.seteditable (FALSE);   Jtf1.setbounds (New Rectangle (200,0,200,30));    JTF2 = new JTextField (); Jtf2.sethorizontalAlignment (Jtextfield.center);   Jtf2.settext (String) questions.get (1));    Jtf2.seteditable (FALSE);   Jtf2.setbounds (New Rectangle (200,40,200,30));    JTF3 = new JTextField ();   Jtf3.sethorizontalalignment (Jtextfield.center);   Jtf3.settext (String) Questions.get (2));    Jtf3.seteditable (FALSE);   Jtf3.setbounds (New Rectangle (200,80,200,30));    jtf4= new JTextField ();   Jtf4.sethorizontalalignment (Jtextfield.center);    Jtf4.settext (String) Questions.get (3));    Jtf4.seteditable (FALSE);     Jtf4.setbounds (New Rectangle (200,120,200,30));   Jtf5 = new JTextField (); jtf5.sethorizontalalignment (Jtextfield.center);   Jtf5.settext (String) Questions.get (4));    Jtf5.seteditable (FALSE);   Jtf5.setbounds (New Rectangle (200,160,200,30));    Jtf6 = new JTextField ();   Jtf6.sethorizontalalignment (Jtextfield.center);    Jtf6.settext (String) Questions.get (5));    Jtf6.seteditable (FALSE);   Jtf6.setbounds (New Rectangle (200,200,200,30));    Jtf7 = new JTextField (); Jtf7.sethorizontalalignment (JtextfieLd.   CENTER);    Jtf7.settext (String) Questions.get (6));    Jtf7.seteditable (FALSE);   Jtf7.setbounds (New Rectangle (200,240,200,30));    Jtf8 = new JTextField ();   Jtf8.sethorizontalalignment (Jtextfield.center);   Jtf8.settext (String) Questions.get (7));    Jtf8.seteditable (FALSE);   Jtf8.setbounds (New Rectangle (200,280,200,30));    JTF9 = new JTextField ();   Jtf9.sethorizontalalignment (Jtextfield.center);   Jtf9.settext (String) Questions.get (8));    Jtf9.seteditable (FALSE);   Jtf9.setbounds (New Rectangle (200,320,200,30));    JTF10 = new JTextField ();   Jtf10.sethorizontalalignment (Jtextfield.center);    Jtf10.settext (String) Questions.get (9));    Jtf10.seteditable (FALSE);   Jtf10.setbounds (New Rectangle (200,360,200,30));    JTF11 = new JTextField ();   Jtf11.setbounds (New Rectangle (490,0,150,30));    JTF12 = new JTextField ();   Jtf12.setbounds (New Rectangle (490,40,150,30));    Jtf13 = new JTextField ();   Jtf13.setbounds (New Rectangle (490,80,150,30));    Jtf14 = new JTextField (); Jtf14.sEtbounds (New Rectangle (490,120,150,30));    JTF15 = new JTextField ();   Jtf15.setbounds (New Rectangle (490,160,150,30));    JTF16 = new JTextField ();   Jtf16.setbounds (New Rectangle (490,200,150,30));    Jtf17 = new JTextField ();     Jtf17.setbounds (New Rectangle (490,240,150,30));   Jtf18 = new JTextField (); Jtf18.setbounds (new Rectangle (490,280,150,30));    Jtf19 = new JTextField ();   Jtf19.setbounds (New Rectangle (490,320,150,30));    Jtf20 = new JTextField ();       Jtf20.setbounds (New Rectangle (490,360,150,30));   Jp1.add (JBL1);   Jp1.add (JBL2);   Jp1.add (JBL3);   Jp1.add (JBL4);   Jp1.add (JBL5);   Jp1.add (JBL6);   Jp1.add (JBL7);   Jp1.add (JBL8);   Jp1.add (JBL9);   Jp1.add (JBL10);   Jp1.add (JBL11);   Jp1.add (JBL12);   Jp1.add (JBL13);   Jp1.add (JBL14);   Jp1.add (JBL15);   Jp1.add (JBL16);   Jp1.add (JBL17);   Jp1.add (JBL18);   Jp1.add (JBL19);   Jp1.add (JBL20);   Jp1.add (JTF1);   Jp1.add (JTF2);   Jp1.add (JTF3);   Jp1.add (JTF4);   Jp1.add (JTF5);   Jp1.add (JTF6);   Jp1.add (JTF7); Jp1.add (JTF8);   Jp1.add (JTF9);  Jp1.add (JTF10);   Jp1.add (JTF11);  Jp1.add (JTF12);  Jp1.add (JTF13);  Jp1.add (JTF14);  Jp1.add (JTF15);  Jp1.add (JTF16);   Jp1.add (JTF17);   Jp1.add (jtf18); Jp1.add (JTF19);   Jp1.add (JTF20);  JP2 = new JPanel (); jp2.setlayout (null);  Jp2.setbounds (0,500,800,100);      Jp2.setopaque (FALSE);   JB1 = new JButton ("Start"); Jb1.setbounds (New Rectangle (450,10,70,30));   Jb1.addactionlistener (this);  JB2 = new JButton ("submit"); Jb2.setbounds (New Rectangle (530,10,70,30)); Jb2.addactionlistener (this);   JB3 = new JButton ("Exit"); Jb3.setbounds (New Rectangle (610,10,70,30));  Jb3.addactionlistener (this);   Jbl0 = new JLabel ("Time:");  Jbl0.setfont (New Font ("Microsoft Jas Black", font.bold,15));   Jbl0.setforeground (color.red);  Jbl0.setbounds (New Rectangle (100,10,50,30));   Time = new JLabel ();   Time.setforeground (color.red);       Time.setbounds (New Rectangle (160,10,100,30));  Jp2.add (jbl0);  Jp2.add (JB1);  Jp2.add (JB2);  Jp2.add (JB3);     Jp2.add (time); This.setcontentpane (New Bgpanel ()); This.setvIsible (TRUE);  This.setlayout (NULL);  This.settitle ("Arithmetic test system");  This.setsize (800,600); This.setdefaultcloseoperation (Jframe.exit_on_close); This.setresizable (FALSE);   This.add (JP1);  This.add (JP2);   } public int timer=0;     public boolean running=true;public void Starttimer () {New Java.lang.Thread (new Runnable () {public void run () {      while (running) {try{thread.sleep (1000);//Sleep One Second} catch (Exception e) {} timer++;  Time.settext ("used:" + string.valueof (timer) + "seconds"); }}). Start ();  }private void Initquestion () {questions = new ArrayList (10);   Answers = new ArrayList (10); String[] Operations = {"+", "-", "*", "/"};  Random random = new random ();  String operation = NULL;  int NUM1 = 0;     int num2 = 0;    for (int i = 0; i < i++) {//auto-generate operator operation = operations[(int) (random.nextdouble () *10*2/5)];     Automatic generation of 2 x within 100 num1 = (int) (random.nextdouble () *100);     num2 = (int) (random.nextdouble () *100); if (opeRation.equals ("+")) {Answers.add (i, s.valueof (num1+num2));  Questions.add (i, NUM1 + "+" + num2);     } else if (Operation.equals ("-")) {Answers.add (i, s.valueof (num1-num2));     Questions.add (i, NUM1 + "-" +num2);     } else if (Operation.equals ("*")) {Answers.add (i, s.valueof (num1*num2));    Questions.add (i, NUM1 + "*" +num2); } else if (Operation.equals ("/")) {//prevents a divisor of 0 while (num2 = = 0) {num2 = (int) (random.nextdouble () * *   00);    } answers.add (I, s.valueof (num1/num2));   Questions.add (i, NUM1 + "/" +num2);  }}} public void GetResult () {results = new ArrayList (10); Results.add (0,jtf11.gettext ()); Results.add (1,jtf12.gettext ()); Results.add (2,jtf13.gettext ()); Results.add (3,jtf14.gettext ());  Results.add (4,jtf15.gettext ()); Results.add (5,jtf16.gettext ());  Results.add (6,jtf17.gettext ());  Results.add (7,jtf18.gettext ());  Results.add (8,jtf19.gettext ());  Results.add (9,jtf20.gettext ());  public static void Main (String []args) {Component MF = null; MainFrame mf1 = new MainFrame ();   Joptionpane.showmessagedialog (MF, "please click" + "[" + "start" + "]" + "button to start the test!");    public void actionperformed (ActionEvent e) {if (E.getsource () ==jb1) {This.starttimer ();} else if (E.getsource () ==jb2) {This.getresult (); running=false;for (int i=0;i<10;i++) {if (Results.get (i). Equals (     Answers.get (i))) {right++;     } else {wrong++;         }} score = right * 10;     Resultframe RF = new Resultframe (Right,wrong,timer,score);      This.dispose ();    } else if (E.getsource () ==jb3) {this.dispose ();  Joptionpane.showmessagedialog (This, "Thank you for using!");  System.exit (0); }     }  }

Package Computeproject;import Java.awt.color;import Java.awt.graphics;import java.awt.graphics2d;import Java.awt.image;import Java.awt.rectangle;import Java.awt.toolkit;import Java.awt.event.actionevent;import Java.awt.event.actionlistener;import Javax.swing.jbutton;import Javax.swing.jframe;import Javax.swing.JLabel; Import Javax.swing.joptionpane;import Javax.swing.jpanel;import Javax.swing.event.ancestorlistener;public class  Resultframe extends JFrame implements actionlistener{private JLabel jbl1,jbl2,jbl3,jbl4;  Private JButton jb1,jb2; Private JPanel JP1,JP2; private int compare; Class Bgpanel extends JPanel {private int compare;public void paintcomponent (Graphics g) {graphics2d GD = (grap  HICS2D) G;    Super.paintcomponent (g);   Image img = Toolkit.getdefaulttoolkit (). GetImage ("images/result.jpg");    Gd.drawimage (IMG, 0, 0, this.getwidth (), This.getheight (), this); } public void Resultframe (int right,int wrong,int time,int score) {this.compare = SCORE;JP1 = new JPanel ();  Jp1.setbounds (0,50,400,150);  Jp1.setopaque (FALSE);  Jp1.setlayout (NULL);  JBL1 = new JLabel ("correct:" + right + "problem");  Jbl1.setforeground (Color.yellow);  Jbl1.setbounds (New Rectangle (80,0,200,30));  JBL2 = new JLabel ("wrong answer:" + wrong + "problem");   Jbl2.setforeground (Color.yellow); Jbl2.setbounds (New Rectangle (80,40,200,30));  JBL3 = new JLabel ("spents:" + Time + "seconds");    Jbl3.setforeground (Color.yellow);  Jbl3.setbounds (New Rectangle (80,80,200,30));  JBL4 = new JLabel ("Score:" + score);   Jbl4.setforeground (Color.yellow);      Jbl4.setbounds (New Rectangle (80,120,200,30));   Jp1.add (JBL1);   Jp1.add (JBL2);   Jp1.add (JBL3);     Jp1.add (JBL4);   JP2 = new JPanel ();    Jp2.setlayout (NULL);   Jp2.setopaque (FALSE);  Jp2.setbounds (0,200,400,100);   JB1 = new JButton ("View Evaluation");    Jb1.addancestorlistener ((Ancestorlistener) this); Jb1.setbounds (New Rectangle (60,20,100,30));  JB2 = new JButton ("Exit test");   Jb2.addactionlistener ((ActionListener) this); Jb2.setbounds (New ReCtangle (200,20,100,30));  Jp2.add (JB1);     Jp2.add (JB2);  This.setcontentpane (New Bgpanel ());   This.setlayout (NULL);  This.settitle ("Test results");  This.setresizable (FALSE); This.setsize (400,300);    This.add (JP1); This.add (JP2);       This.setvisible (TRUE); } private void Setresizable (Boolean b) {//TODO auto-generated method stub}private void Settitle (String string) {//TODO auto-generated method stub}privat e void Setcontentpane (Bgpanel bgpanel) {//TODO automatically generated method stub}public void actionperformed (ActionEvent e) {if (e.getsource () = =   JB1) {if (compare >=) Joptionpane.showmessagedialog (This, "Congratulations, get a level!");   else if (compare >=) Joptionpane.showmessagedialog (This, "Congratulations, get B level!");  else if (compare >=) Joptionpane.showmessagedialog (This, "Congratulations, get C level!");   else if (compare >=) Joptionpane.showmessagedialog (this, "good risk ah, you just passed!");   else Joptionpane.showmessagedialog (This, "I'm sorry, you didn't pass!");   } else if (E.getsource () ==jb2) {this.dispose ();   System.exit (0); }}private void dispOSE () {//TODO auto-generated method stub}}public resultframe (int right, int wrong, int timer, int score) {//TODO auto-generated constructor stub} @Override public void actionperformed (ActionEvent e) {//TODO auto-generated method stub}}
Do this program when I feel difficult, the interface I and my partner is done, but there are some buttons of the function can not be implemented, I and his Java are not very good, we discussed for a long time also is not how to implement the function of the submission, this is a semi-finished Ah, a little disappointed, do so for a long time or can only make a semi-finished products, feel that they have not learned enough. Do this experiment on their own harvest is still very large, because Java has not touched for some time, now can be good practice, not only to review the previous knowledge, but also to strengthen their own study, we will continue to correct, the best procedures to do it.

  

Pairing work (Beta)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.