Software Engineering personal assignments (3)

Source: Internet
Author: User

Source:

Package zuoye2;

Import Java.awt.Container;

Import java.awt.event.ActionEvent;

Import Java.awt.event.ActionListener;

Import javax.swing.*;

Class Jiemian

{

Public Jiemian ()

{

JFrame jf=new JFrame ("arithmetic");

Jf.setbounds (200, 100, 500, 500);

Jf.setlayout (NULL);

Container C=jf.getcontentpane ();

Jcheckbox j1=new Jcheckbox ("Multiplication Law");

Jcheckbox j2=new Jcheckbox ("with brackets");

Jcheckbox j3=new jcheckbox ("negative");

Jcheckbox j4=new Jcheckbox ("surplus number");

JLabel l1=new JLabel ("Please enter a range of values");

JLabel l4=new JLabel ("Please enter the number of parameters (1-10)");

JLabel l2=new JLabel ("-");

JLabel l3=new JLabel ("Please enter the number of questions (1-30)");

JTextField t1=new JTextField ("2");

JTextField t2=new JTextField ("20");

JTextField t3=new JTextField ("30");

JTextField t4=new JTextField ("30");

J1.setbounds (100, 100, 80,20);

J2.setbounds (100, 130, 80,20);

L4.setbounds (100, 160, 180,20);

J3.setbounds (100, 220, 80,20);

J4.setbounds (100, 250, 80,20);

T1.setbounds (100, 190, 50,20);

L1.setbounds (100, 280, 150,20);

T2.setbounds (100, 310, 50,20);

T3.setbounds (180, 310, 50,20);

L2.setbounds (160, 310, 30,20);

L3.setbounds (100, 340, 150,20);

T4.setbounds (100, 370, 50,20);

C.add (J1);

C.add (J2);

C.add (J3);

C.add (L4);

C.add (J4);

C.add (t1);

C.add (L1);

C.add (T2);

C.add (T3);

C.add (L2);

C.add (L3);

C.add (T4);

JButton b1=new JButton ("OK");

JButton b2=new JButton ("exit");

B1.setbounds (350, 150, 70, 50);

B2.setbounds (350, 300, 70, 50);

C.add (B1);

C.add (B2);

B1.addactionlistener (new ActionListener () {

@Override

public void actionperformed (ActionEvent e)

{

Jf.dispose ();

String A1,a2,a3,a4,a5;

int c1,c2,c3,c4,c5;

Boolean f1=false,f2=false,f3=false,f4=false,f5=false;

A1=t1.gettext (). toString ();

A2=t2.gettext (). toString ();

A3=t3.gettext (). toString ();

A4=t4.gettext (). toString ();

if (A2.equals ("") | | A3.equals (""))

{

Joptionpane.showmessagedialog (NULL, "range cannot be empty", "Scope cannot be empty", joptionpane.error_message);

System.exit (0);

}

else if (A4.equals (""))

{

Joptionpane.showmessagedialog (NULL, "number cannot be empty", "number cannot be empty", joptionpane.error_message);

System.exit (0);

}

else if (A1.equals (""))

{

Joptionpane.showmessagedialog (NULL, "Number of arguments cannot be null", "number of arguments cannot be null", joptionpane.error_message);

System.exit (0);

}

else if (Integer.parseint (A1) >10| | Integer.parseint (A1) <=0)

{

Joptionpane.showmessagedialog (NULL, "Number of arguments exceeded", "number of arguments exceeded", joptionpane.error_message);

System.exit (0);

}

else if (Integer.parseint (A4) <=0| | Integer.parseint (A4) >30)

{

Joptionpane.showmessagedialog (NULL, "Incorrect number of topics", "incorrect number of topics", joptionpane.error_message);

System.exit (0);

}

else if (Integer.parseint (A3) <=integer.parseint (A2))

{

Joptionpane.showmessagedialog (NULL, "Incorrect range", "range incorrect", joptionpane.error_message);

System.exit (0);

}

if (j1.isselected ())

{

F1=true;

}

if (j2.isselected ())

{

F2=true;

}

if (j3.isselected ())

{

F3=true;

}

if (j4.isselected ())

{

F4=true;

}

C1=integer.parseint (A1);

C2=integer.parseint (A2);

C3=integer.parseint (A3);

C4=integer.parseint (A4);

Yunsuan a=new Yunsuan (C1,C2,C3,C4,F1,F2,F3,F4);

}

});

B2.addactionlistener (new ActionListener () {

@Override

public void actionperformed (ActionEvent e)

{

Jf.dispose ();

}

});

Jf.setvisible (TRUE);

Jf.setdefaultcloseoperation (Windowconstants.exit_on_close);

}

}

Package zuoye2;

public class M extends Jiemian

{

public static void Main (string[] args)

{

TODO auto-generated Method Stub

Jiemian a=new Jiemian ();

}

}

Package zuoye2;

Import Java.awt.Container;

Import java.awt.event.ActionEvent;

Import Java.awt.event.ActionListener;

Import Java.util.Random;

Import Javax.swing.ImageIcon;

Import Javax.swing.JButton;

Import Javax.swing.JFrame;

Import Javax.swing.JLabel;

Import Javax.swing.JOptionPane;

Import Javax.swing.JTextField;

Import javax.swing.WindowConstants;

public class Yunsuan implements Runnable

{

JFrame jf=new JFrame ("arithmetic");

Container C=jf.getcontentpane ();

int i1,i2,i3,i4,anwser;

Boolean j1,j2,j3,j4;

JTextField J5;

Thread T;

protected void KS ()

{

T=new Thread (this);

}

Public Yunsuan (int c1, int c2, int c3, int c4, Boolean F1, Boolean F2, Boolean F3, Boolean F4)

{

I1=C1;

I2=C2;

I3=C3;

I4=C4;

J1=F1;

J2=F2;

J3=F3;

J4=F4;

JButton bu1=new JButton ("submit");

JButton bu2=new JButton ("exit");

Bu1.setbounds (20, 100, 60, 20);

Bu2.setbounds (100, 100, 60, 20);

C.add (BU1);

C.add (BU2);

KS ();

T.start ();

Bu1.addactionlistener (new ActionListener () {

public void actionperformed (ActionEvent e)

{

String QS;

Qs=j5.gettext (). toString ();

if (Qs.equals (""))

{

Joptionpane.showmessagedialog (NULL, "Empty Answer", "Empty Answer", joptionpane.error_message);

}

else if (Anwser==integer.parseint (QS))

{

T.stop ();

KS ();

C.removeall ();

Bu1.setbounds (20, 100, 60, 20);

Bu2.setbounds (100, 100, 60, 20);

C.add (BU1);

C.add (BU2);

T.start ();

C.repaint ();

Jf.setvisible (TRUE);

}

Else

{

Joptionpane.showmessagedialog (NULL, "answer wrong", "Answer Error", joptionpane.error_message);

}

}

});

Bu2.addactionlistener (new ActionListener () {

@Override

public void actionperformed (ActionEvent e)

{

Jf.dispose ();

}

});

Jf.setbounds (+, c1*150+100, 200);

Jf.setlayout (NULL);

Jf.setvisible (TRUE);

Jf.setdefaultcloseoperation (Windowconstants.exit_on_close);

}

@Override

public void Run ()

{

int c1,c2,c3,c4;

Boolean f1,f2,f3,f4;

Container C=jf.getcontentpane ();

C1=I1;

C2=i2;

C3=i3;

C4=I4;

f1=j1;

F2=j2;

F3=j3;

F4=j4;

int a,b,d = 0,e;

String a1,b1,d1;

JLabel j1,j2,j3,j4,j7;

J1=new JLabel ();

J2=new JLabel ();

J3=new JLabel ();

J4=new JLabel ();

J7=new JLabel ();

JTextField J6;

J5=new JTextField ();

J6=new JTextField ();

Random R1[]=new random[2];

Random r2=new random ();

int i,j=0,k=0,l;

J5=new JTextField ();

J6=new JTextField ();

for (i=0;i<2;i++)

{

R1[i]=new Random ();

}

J5=new JTextField ();

if (f1==true)

{

A=C3-C2;

B=C3-C2;

A=r1[0].nextint (a);

B=r1[1].nextint (b);

A=A+C2;

B=B+C2;

E=r2.nextint (4);

}

Else

{

A=C3-C2;

B=C3-C2;

A=r1[0].nextint (a);

B=r1[1].nextint (b);

A=A+C2;

B=B+C2;

E=r2.nextint (2);

}

e=e+1;

if (F3!=false)

{

if (e==1)

{

A=r1[0].nextint (C3-C2) +c2;

B=r1[1].nextint (C3-C2) +c2;

D=a+b;

A1=string.valueof (a);

B1=string.valueof (b);

D1=string.valueof (d);

J1=new JLabel (A1);

J2=new JLabel ("+");

J3=new JLabel (B1);

J4=new JLabel ("=");

}

if (e==2)

{

A=r1[0].nextint (C3-C2) +c2;

B=r1[1].nextint (C3-C2) +c2;

D=a-b;

A1=string.valueof (a);

B1=string.valueof (b);

D1=string.valueof (d);

J1=new JLabel (A1);

J2=new JLabel ("-");

J3=new JLabel (B1);

J4=new JLabel ("=");

}

}

Else

{

if (e==1)

{

A=r1[0].nextint (C3-C2) +c2;

B=r1[1].nextint (C3-C2) +c2;

D=a+b;

A1=string.valueof (a);

B1=string.valueof (b);

D1=string.valueof (d);

J1=new JLabel (A1);

J2=new JLabel ("+");

J3=new JLabel (B1);

J4=new JLabel ("=");

}

if (e==2)

{

int x;

A=r1[0].nextint (C3-C2) +c2;

B=r1[1].nextint (C3-C2) +c2;

if (b>a)

{

X=b;

B=a;

A=x;

}

D=a-b;

A1=string.valueof (a);

B1=string.valueof (b);

D1=string.valueof (d);

J1=new JLabel (A1);

J2=new JLabel ("-");

J3=new JLabel (B1);

J4=new JLabel ("=");

}

}

if (e==3)

{

A=r1[0].nextint (C3-C2) +c2;

B=r2.nextint (C3-C2) +c2;

D=a*b;

A1=string.valueof (a);

B1=string.valueof (b);

D1=string.valueof (d);

J1=new JLabel (A1);

J2=new JLabel ("X");

J3=new JLabel (B1);

J4=new JLabel ("=");

}

if (F4==false)

{

if (e==4)

{

D=r1[0].nextint (C3-C2) +c2;

B=r1[1].nextint (C3-C2) +c2;

A=b*d;

while (d==0| | b==0)

{

R1[0]=new Random ();

R1[1]=new Random ();

D=r1[0].nextint (20);

B=r1[1].nextint (20);

A=b*d;

}

A1=string.valueof (a);

B1=string.valueof (b);

D1=string.valueof (d);

J1=new JLabel (A1);

J2=new JLabel ("/");

J3=new JLabel (B1);

J4=new JLabel ("=");

}

}

Else

{

if (e==4)

{

J7=new JLabel ("Yu");

A=r1[0].nextint (C3-C2) +c2;

B=r1[1].nextint (C3-C2) +c2;

while (a==0| | b==0)

{

R1[0]=new Random ();

R1[1]=new Random ();

D=r1[0].nextint (20);

B=r1[1].nextint (20);

A=b*d;

}

A1=string.valueof (a);

B1=string.valueof (b);

D1=string.valueof (d);

J1=new JLabel (A1);

J2=new JLabel ("/");

J3=new JLabel (B1);

J4=new JLabel ("=");

}

}

if (e==4&&f4==true)

{

J1.setbounds (50+j*42, 50+ (K/2) *32, 40, 30);

j + +;

J2.setbounds (50+j*42, 50+ (K/2) *32, 40, 30);

j + +;

J3.setbounds (50+j*42, 50+ (K/2) *32, 40, 30);

j + +;

J4.setbounds (50+j*42, 50+ (K/2) *32, 40, 30);

j + +;

J5.setbounds (50+j*42, 50+ (K/2) *32, 40, 30);

j + +;

J7.setbounds (65+j*42,50+ (K/2) *32, 40, 30);

j + +;

J6.setbounds (50+j*42,50+ (K/2) *32, 40, 30);

j + +;

j + +;

j + +;

k++;

if (k!=0&&k%2==0)

{

j=0;

}

C.add (J1);

C.add (J2);

C.add (J3);

C.add (J4);

C.add (J5);

C.add (J6);

C.add (J7);

}

Else

{

J1.setbounds (50+j*42, 50+ (K/2) *32, 40, 30);

j + +;

J2.setbounds (50+j*42, 50+ (K/2) *32, 40, 30);

j + +;

J3.setbounds (50+j*42, 50+ (K/2) *32, 40, 30);

j + +;

J4.setbounds (50+j*42, 50+ (K/2) *32, 40, 30);

j + +;

J5.setbounds (50+j*42, 50+ (K/2) *32, 40, 30);

j + +;

j + +;

j + +;

j + +;

j + +;

k++;

if (k!=0&&k%2==0)

{

j=0;

}

C.add (J1);

C.add (J2);

C.add (J3);

C.add (J4);

C.add (J5);

}

Anwser = D;

C.repaint ();

Jf.setvisible (TRUE);

}

TODO auto-generated Method Stub

}

Design ideas:

1.建立一个frame面板,通过添加复选框来选择是否有乘除法,是否有余数,是否有括号以及是否有负数。

2. Control the calculation range and number of topics by adding a text box.

3. When the OK button is clicked, the current window closes, the data is submitted, and a new frame window is created.

4. Control the calculation problem by random number generation and subtraction (0-3 for subtraction respectively, if there is no multiplication, then 0 or 1 will be generated, thereby excluding the multiplication operation)

5. Control division based on whether to select the remainder. If there is no remainder, the product of the generated two random numbers is used as the dividend, and the second random number as the divisor.

6. If a negative number is selected, the addition and subtraction do not do the processing, or the comparison between the meiosis and the size. If the meiosis is greater than the meiosis, the two are exchanged.

7. By creating a JLabel array to output the title to the window, the title coordinates are accumulated according to the number of questions

8. Fill in the answer by creating a text box

9. Parentheses and tests are not repeated.

10. Thread to control topic change

1.

2.

Software Engineering personal assignments (3)

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.