标签:
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;// 默认适中
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)// 加法
{
del = 0;
new T().Set_T1("+");
}
if (e.getSource() == new T().button_2)// 减法
{
del = 0;
new T().Set_T1("-");
}
if (e.getSource() == new T().button_3)// 乘法
{
del = 0;
new T().Set_T1("*");
}
if (e.getSource() == new T().btnNewButton_3)// 除法
{
this.Set_del();
del = 1;
new T().Set_T1("/");
}
if(e.getSource()==new T().Get_btnNewButton_4())
{
this.t=0;//初始化
this.f=0;//初始化
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())// 简单
{
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())// 适中
{
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())// 困难
{
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) {
//判断是回车
if (arg0.getKeyCode() == KeyEvent.VK_ENTER) {
if(new T().Get_T12().getText().length()!=0)
{
sum=Integer.parseInt(new T().Get_T12().getText());//回车初始化题目数量
}
// 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("你很厉害,答对了!");
}
else {
Set_f(f);
new T().Set_T9("你太大意了!答错了");
System.out.print(new T().Get_n()+" "+Integer.parseInt(new T().Get_T3()));
}
new T().Set_T8_T10_T11();
times++;
//加减乘除的
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("你输入的 “ " + new T().Get_T3() + " ”是非法数值");
new T().Set_T3();
}
}
else
{
new T().Set_T9(new T().Get_T9().getText()+"你已经完成"+new T().Get_T12().getText()+"道题目");
new T().Set_T_T1_T2_T3(false);
}
}
}
public void keyReleased(KeyEvent arg0) {
}
public void keyTyped(KeyEvent arg0) {
}
}
标签:
原文地址:http://www.cnblogs.com/imfjj/p/4411032.html