public static void main(String[] args) {
new MyWindow();
}
}
class MyWindow{
private Frame f;
public MyWindow(){
f = new Frame();
f.setBounds(100,200, 200, 200);
f.setVisible(true);
MyEvent();
}
public void MyEvent(){
f.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
// TODO Auto-generated method stub
super.keyPressed(e);
if(e.getKeyCode() == e.VK_ESCAPE){
System.exit(0);
}
}
});
}
}
这个可以实现吧 |