为什么捕捉不到异常?
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+"=");
}