Package Opar;
Import Java.awt.Color;
Import java.awt.event.ActionEvent;
Import Java.awt.event.ActionListener;
Import java.awt.event.KeyEvent;
Import Java.awt.event.KeyListener;
Import Java.util.regex.Matcher;
Import Java.util.regex.Pattern;
public class T_event implements ActionListener, KeyListener {
static int t = 0;
static int f = 0;
static int con = 1;//default Moderate
static int del = 0;
private static int sum=1000;
private static int times=0;
void set_t (int t) {
THIS.T = this.t + 1;
}
void Set_f (int f) {
THIS.F = this.f + 1;
}
void Set_del () {
while (new T (). Get_t2 () = = 0 | | New T (). get_t ()% new T (). GET_T2 ()! = 0) {
if (con = = 0)
New T (). Set_rom_rom1 (0, 20);
else if (con = = 1)
New T (). SET_ROM_ROM1 (11, 500);
else if (con = = 2)
New T (). SET_ROM_ROM1 (501, 10000);
New T (). SET_T_T1_T2_T3 ();
}
}
int get_t () {
return t;
}
int Get_f () {
return F;
}
public void actionperformed (ActionEvent e) {
TODO auto-generated Method Stub
if (e.getsource () = = new T (). button_1)//addition
{
del = 0;
New T (). SET_T1 ("+");
}
if (e.getsource () = = new T (). button_2)//subtraction
{
del = 0;
New T (). Set_t1 ("-");
}
if (e.getsource () = = new T (). Button_3)//multiplication
{
del = 0;
New T (). SET_T1 ("*");
}
if (e.getsource () = = new T (). Btnnewbutton_3)//division
{
This. Set_del ();
del = 1;
New T (). SET_T1 ("/");
}
if (E.getsource () ==new T (). Get_btnnewbutton_4 ())
{
this.t=0;//initialization
this.f=0;//initialization
this.times=0;
New T (). Get_t12 (). SetText ();
this.sum=10000;
New T (). SET_T_T1_T2_T3 ();
New T (). Set_t_t1_t2_t3 (TRUE);
}
if (e.getsource () = = new T (). Get_btnnewbutton ())//Simple
{
New T (). Set_rom_rom1 (0, 20);
New T (). SET_T_T1_T2_T3 ();
con = 0;
if (del = = 1)
This. Set_del ();
}
if (e.getsource () = = new T (). Get_btnnewbutton_1 ())//Moderate
{
New T (). SET_ROM_ROM1 (11, 500);
New T (). SET_T_T1_T2_T3 ();
con = 1;
if (del = = 1)
This. Set_del ();
}
if (e.getsource () = = new T (). Get_btnnewbutton_2 ())//difficult
{
New T (). SET_ROM_ROM1 (501, 10000);
New T (). SET_T_T1_T2_T3 ();
con = 2;
if (del = = 1)
This. Set_del ();
}
if (e.getsource () = = new T (). Button)
System.exit (0);
if (e.getsource () = = new T (). Get_com ()) {
int index = new T (). Get_com (). Getselectedindex ();
Switch (index) {
Case 0:
New T (). Get_frame (). Getcontentpane (). SetBackground (color.red);
Break
Case 1:
New T (). Get_frame (). Getcontentpane ()
. SetBackground (Color.orange);
Break
Case 2:
New T (). Get_frame (). Getcontentpane ()
. SetBackground (Color.yellow);
Break
Case 3:
New T (). Get_frame (). Getcontentpane (). SetBackground (Color.green);
Break
Case 4:
New T (). Get_frame (). Getcontentpane (). SetBackground (Color.Blue);
Break
}
}
}
@Override
public void keypressed (KeyEvent arg0) {
Judging is a carriage return
if (arg0.getkeycode () = = Keyevent.vk_enter) {
if (new T (). Get_t12 (). GetText (). Length ()!=0)
{
Sum=integer.parseint (New T (). Get_t12 (). GetText ());//Enter the number of initialization questions
}
Pattern pattern=pattern.compile ("[0-9]*");! Isnum.matches () | |
Matcher Isnum=pattern.matcher (New T (). GET_T3 ());
if (this.sum>times)
{
if (new T (). Get_t3 (). Matches ("-?[ 0-9]+.*[0-9]* ")) {
New T (). Set_t4_t5_t6_t7 ();
if (new T (). Get_n () = = Integer.parseint (new T (). GET_T3 ())) {
set_t (t);
New T (). Set_t9 ("You are very good, correct!" ");
}
else {
Set_f (f);
New T (). Set_t9 ("You are too careless!") Wrong answer ");
System.out.print (New T (). Get_n () + "" +integer.parseint (New T (). GET_T3 ()));
}
New T (). Set_t8_t10_t11 ();
times++;
Subtraction's
if (con = = 0) {
New T (). Set_rom_rom1 (0, 20);
This. Set_del ();
} else if (con = = 1) {
New T (). SET_ROM_ROM1 (21, 500);
This. Set_del ();
} else if (con = = 2) {
New T (). SET_ROM_ROM1 (501, 10000);
This. Set_del ();
}
New T (). SET_T_T1_T2_T3 ();
if (del = = 1)
This. Set_del ();
} else {
New T (). Set_t9 ("You typed" + New T (). GET_T3 () + "" is an illegal value ");
New T (). Set_t3 ();
}
}
Else
{
New T (). Set_t9 (New T (). Get_t9 (). GetText () + "You have completed" +new T (). Get_t12 (). GetText () + "road title");
New T (). Set_t_t1_t2_t3 (FALSE);
}
}
}
public void keyreleased (KeyEvent arg0) {
}
public void keytyped (KeyEvent arg0) {
}
}
Four interface Operation Code 2