java 捕捉不到的异常,为什么捕捉不到异常!

为什么捕捉不到异常?

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import java.io.*;

public class jiajia extends JFrame implements KeyListener,ActionListener{

public static void main(String args[]){

jiajia frame=new jiajia();

}

Timer time;

int msg,a,b;

JLabel l1,l2,l3;

JTextField t;

public jiajia(){

super("加法");

Container cc=getContentPane();

cc.setLayout(null);

l1=new JLabel("请按enter键确认答案:");

l1.setFont(new Font("楷体",Font.BOLD,18));

l1.setForeground(Color.white);

l1.setSize(200,18);

l1.setLocation(10,10);

cc.add(l1);

l2=new JLabel();

l2.setFont(new Font("楷体",Font.BOLD,18));

l2.setForeground(Color.red);

l2.setVisible(false);

l2.setSize(200,18);

l2.setLocation(220,10);

cc.add(l2);

l3=new JLabel("9+8=");

l3.setFont(new Font("楷体",Font.BOLD,18));

l3.setForeground(Color.red);

l3.setVisible(true);

l3.setSize(100,18);

l3.setLocation(140,150);

cc.add(l3);

t=new JTextField("");

t.setFont(new Font("楷体",Font.BOLD,18));

t.setVisible(true);

t.setSize(80,18);

t.addKeyListener(this);

t.setLocation(185,150);

cc.add(t);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setSize(600,500);

setVisible(true);

msg=0;

time=new Timer(7000,this);

time.start();

newitem(); //覆盖初始值9+8=,如果不调用newitem方法,则不会出题,也不能计算,因为初

始值是字符串。

}

public void newitem(){

a=(int) (Math.random()*9)+1;

b=(int) (Math.random()*9)+1;

l3.setText(a+"+"+b+"=");

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值