import javax.swing.*;
import java.event.*;public class Test{
public static void main(String []agrs){
F f=new F();
f.setVisible(true);
}
}class F extends JFrame{
JPanel cp;
JPanel pan1;F(){
cp=(JPanel)getContendPanel; 
this.addKeyEventListner(new Mv(this));
}
pulic void Mc(EventAction e){
System.exit(0);
}
}class Mv extends KeyeventAdapter{
F f;
Mv(F ff){
this.f=ff;
}
public void keyTyped(EventAction e){
f.Mc(e);

} ------------------------------------------------
上边的这段程序运行时随意按一个键窗口就会关闭但是添一个按钮上去就不好用了代码如下
------------------------------------------------import javax.swing.*;
import java.event.*;public class Test{
public static void main(String []agrs){
F f=new F();
f.setVisible(true);
}
}class F extends JFrame{
JPanel cp;
JButton b1; 
F(){
cp=(JPanel)getContendPanel; 
cp.add(b1); 
this.addKeyEventListner(new Mv(this));
}
pulic void Mc(EventAction e){
System.exit(0);
}
}class Mv extends KeyeventAdapter{
F f;
Mv(F ff){
this.f=ff;
}
public void keyTyped(EventAction e){
f.Mc(e);


------------------------------------------
这样就不好使了,高手帮忙分析一下这个是为什么,由于在网吧上网没有编成工具代码是手写的在加上刚刚学java 肯定会有错的地方,但是程序大概的意思高手一看就应该明白,我感觉java的事件处理这一块应该是挺重要的,但是我看了很多书对这方面的介绍都很少,事件的处理到底重要部重要,有哪些这方面的书推荐一下 ^_^