为什么不行,可以啊
见下面的代码
package com.meiyouzhegewang.gui;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.Toolkit;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
public class KEYClose {
public static void main(String[] args) {
new Themain();
}
}
class Themain
{
private Frame frm;
Themain(){
frm = new Frame();
int width = Toolkit.getDefaultToolkit().getScreenSize().width;
int height = Toolkit.getDefaultToolkit().getScreenSize().height;
frm.setBounds((width-640)/2, (height-360)/2, 640, 360);
frm.setLayout(new FlowLayout());
//添加监听,为何不行
frm.addKeyListener(new KeyAdapter(){
public void keyPressed(KeyEvent e) {
System.exit(0);
}
});
}
}
|