f.setVisible(true);
}
public void myEvent()
{
f.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
/*
but.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
System.out.println("关闭。。。按钮干的");
System.exit(0);
}
});
*/
tf.addKeyListener(new KeyAdapter()
{
public void keyPressed(KeyEvent e)
{
int code = e.getKeyCode();
if (!(code>=KeyEvent.VK_0 && code<=KeyEvent.VK_9 ))
{
e.consume();//我已经用了consume方法了为什么,非数字字符还是进来了呢
final Dialog dia = new Dialog(f,"提示信息",true);
dia.setBounds(300,200,200,100);
dia.setLayout(new FlowLayout());
Label lab = new Label("错误字符",Label.CENTER);
Button b =new Button("确定");