Job Four: Pair programming Project---arithmetic

Source: Internet
Author: User
Tags gettext

Teammate Shitong



Import Java.awt.borderlayout;import Java.awt.container;import Java.awt.flowlayout;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.jpanel;import Javax.swing.JPasswordField;import Javax.swing.jtextfield;public class Yunsuan extends jframe{JLabel l1 = new JLabel ("Correct number of questions:"); Private JFrame frame = new JFrame ("Arithmetic"); Private Container C = Frame.getcontentpane (); Private JButton KO = new JButton ("OK"); Private JTextField A = new JTextField (6); Private JTextField AA = new JTextField (4); Private JTextField AAA = new JTextField (4); Private JTextField B = new JTextField (6); Private JTextField BB = new JTextField (4); Private JTextField BBB = new JTextField (4); Private JTextField C = new JTextField (6); Private JTextField CC = new JTextField (4); Private JTextField CCC = new JTextField (4); Private JTextField D = new JTextField (6); Private JTextField DD = new JTextField (4); Private JTextField DDD = new JTextField (4); Private JTextField E = new JTextField (6); Private JTextField EE = new JTextField (4); Private JTextField EEE = new JTextField (4); Private JPasswordField Password = new JPasswordField (); Private JButton OK = new JButton ("OK"); Private JTextField QQ = new JTextField (6); int num=0; int an[]=new int [5]; String Bn[]=new string [5]; String Cn[]=new string [5]; Yunsuan (int a[],string b[]) {an=a; Bn=b; JPanel Fieldpanel = new JPanel (); Fieldpanel.add (A); A.setbounds (30, 10, 100, 20); A.setvisible (TRUE); Fieldpanel.add (AA); Aa.setbounds (40, 10, 100, 20); Fieldpanel.add (AAA); Aaa.setbounds (50, 10, 100, 20); Fieldpanel.add (B); B.setbounds (30, 15, 50, 20); Fieldpanel.add (BB); Bb.setbounds (40, 15, 100, 20); Fieldpanel.add (BBB); Bbb.setbounds (50, 10, 100, 20); Fieldpanel.add (C); C.setbounds (30, 20, 50, 20); Fieldpanel.add (CC); Cc.setbounds (40, 20, 100, 20); Fieldpanel.add (CCC); Ccc.setbounds (50, 10, 100, 20); Fieldpanel.add (D);D. SetBounds (30, 25, 50, 20); Fieldpanel.add (DD);DD. SetBounds (40, 25, 100, 20); Fieldpanel.add (DDD);DDD. SetBounds (50, 10, 100, 20); Fieldpanel.add (E); E.setbounds (30, 30, 50, 20); Fieldpanel.add (EE); Ee.setbounds (40, 30, 100, 20); Fieldpanel.add (EEE); Eee.setbounds (50, 10, 100, 20); Fieldpanel.add (KO); Ko.setbounds (30, 50, 20, 20); Fieldpanel.add (L1); L1.setbounds (20, 60, 100, 20); Fieldpanel.add (QQ); Qq.setbounds (40, 70, 100, 20); Ko.addactionlistener (new ActionListener () {public void actionperformed (ActionEvent arg0) {cn[0] =aa.gettext (); Cn[1]=bb.gettext (); Cn[2]=cc.gettext (); Cn[3]=dd.gettext (); Cn[4]=ee.gettext (); Aaa.settext (string.valueof (an[0)); Bbb.settext (string.valueof (an[1)); Ccc.settext (string.valueof (an[2)); Ddd.settext (string.valueof (an[3)); Eee.settext (string.valueof (an[4)); for (int i=0;i<an.length;i++) if (string.valueof (An[i]). Equals (Cn[i])) num++; Qq.settext (string.valueof (num)); } }); Fieldpanel.setverifyinputwhenfocustarget (TRUE); A.settext (Bn[0]); B.settext (bn[1]); C.settext (bn[2]); D.settext (Bn[3]); E.settext (Bn[4]); This.add (Fieldpanel); This.setbounds (+, +, +); This.setvisible (true); } }
    
Import Java.awt.borderlayout;import Java.awt.container;import Java.awt.flowlayout;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.jpanel;import Javax.swing.JPasswordField;import        Javax.swing.jtextfield;public class Login {private JFrame frame = new JFrame ("Arithmetic");        Private Container C = Frame.getcontentpane ();        Private JTextField username = new JTextField ();        Private JPasswordField Password = new JPasswordField ();    Private JButton OK = new JButton ("OK");        Private JButton Cancel = new JButton ("Cancel");            Public Login () {frame.setsize (300,200);        C.setlayout (New BorderLayout ());        Initframe ();    Frame.setvisible (TRUE); } private void Initframe () {//Top Ok.addactionlistener (new ActionListener () {p ublic void actionperformed (ActionEvent arg0) {new SuANFA ();        }        });            JPanel Titlepanel = new JPanel ();            Titlepanel.setlayout (New FlowLayout ());            Titlepanel.add (New JLabel ("Student Login"));                    C.add (Titlepanel, "North");                central form JPanel Fieldpanel = new JPanel ();                Fieldpanel.setlayout (NULL);                JLabel L1 = new JLabel ("Study No.:");            L1.setbounds (50, 20, 50, 20);                JLabel L2 = new JLabel ("Password:");            L2.setbounds (50, 60, 50, 20);                Fieldpanel.add (L1);                Fieldpanel.add (L2);            Username.setbounds (110,20,120,20);            Password.setbounds (110,60,120,20);            Fieldpanel.add (username);            Fieldpanel.add (password);                C.add (Fieldpanel, "Center");            Bottom button JPanel buttonpanel = new JPanel ();            Buttonpanel.setlayout (New FlowLayout ());            Buttonpanel.add (OK);                Buttonpanel.add (cancel); C.Add (Buttonpanel, "South");    } public static void Main (string[] args) {new Login (); }        }
    
Import Java.util.random;public class Suanfa {int a,b,c,d;    int an[]=new int [5];    String Bn[]=new string [5];    Random cn =new Random ();        SUANFA () {int i=0;        do{a=cn.nextint (100);        B=cn.nextint (100);        D=cn.nextint (100)%4+1;                Switch (d) {case 1:an[i]=a+b;                Bn[i]=string.valueof (a) + "+" +string.valueof (b) + "=";                i++;            Break                Case 2:an[i]=a-b;                Bn[i]=string.valueof (a) + "-" +string.valueof (b) + "=";            I++;break;            Case 3:an[i]=a*b;            Bn[i]=string.valueof (a) + "*" +string.valueof (b) + "=";                i++;            Break            Case 4:an[i]=a/b;            Bn[i]=string.valueof (a) + "/" +string.valueof (b) + "=";        I++;break;        }}while (i<5); for (int j=0;j<bn.length;j++) {System.out.println (bn[j]);            System.out.println (An[j]);  } new Yunsuan (AN,BN);  }    } 

Job Four: Pair programming Project---arithmetic

Related Article

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.