Job 2 has the interface of the arithmetic (not written good night in that)

Source: Internet
Author: User

Import java.awt.*;
Import java.awt.event.ActionEvent;
Import Java.awt.event.ActionListener;
Import Java.util.Random;
Import javax.swing.*;
Class Mypanel extends Panel implements actionlistener{
JButton button;
JTextField Text1, Text2, Text3;
JLabel Label1, Label2;
public int resultnum;

Mypanel ()
{
button = new JButton ("Get topic");
Button.addactionlistener (this);
Text1 = new JTextField (5);
Text1.seteditable (FALSE);
Text2 = new JTextField (5);
Text2.seteditable (FALSE);
Text3 = new JTextField (5);
Label1 = new JLabel ("+");
Label2 = new JLabel ("=");

This.add (button);
This.add (Text1);
This.add (Label1);
This.add (TEXT2);
This.add (Label2);
This.add (TEXT3);
}

public void actionperformed (ActionEvent e) {
Random random = new random ();
int num1 = random.nextint (100);
int num2 = random.nextint (100);
Resultnum = 0;
int sizeof = Random.nextint (4);
String str = "";

Switch (sizeof)
{
Case 0:
str = "+";
Resultnum = Num1 + num2;
Break
Case 1:
str = "-";
Resultnum = num1-num2;
Break
Case 2:
str = "*";
Resultnum = Num1 * NUM2;
Break
Case 3:
str = "/";
Resultnum = num1/num2;
Break
}
Label1.settext (str);
Text1.settext (integer.tostring (NUM1));
Text2.settext (integer.tostring (num2));
}
}
public class Computerframe extends JFrame implements actionlistener{
Mypanel Panel;
JButton button1;
JLabel Label3;

Computerframe ()
{
This.settitle ("Random Calculator");
SetLayout (New FlowLayout ());
panel = new Mypanel ();
button1 = new JButton ("Confirm answer");
Button1.addactionlistener (this);
Label3 = new JLabel ();
This.add (panel);
This.add (button1);
This.add (LABEL3);
SetVisible (TRUE);
Setextendedstate (Frame.maximized_vert);
Setdefaultcloseoperation (Jframe.exit_on_close);
SetBounds (450, 300, 380, 125);
Validate ();
}

public void actionperformed (ActionEvent e) {

if (Panel.text3.getText (). Length () = = 0) {
Label3.settext ("You haven't answered yet");
}
Else
{
int result = Integer.parseint (Panel.text3.getText ());

if (Result! = Panel.resultnum)
{
Label3.settext ("You answer the wrong");
}
Else
{
Label3.settext ("You answer correctly");
}
}
}
}

}

Job 2 has the interface of the arithmetic (not written good night in that)

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.