日期:2014-05-20 浏览次数:20851 次
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class TestFrame extends JFrame
{
public TestFrame()
{
addKeyListener(new KeyAdapter()
{
public void keyPressed(KeyEvent event)
{
if (event.getKeyCode() == KeyEvent.VK_ESCAPE)
{
System.exit(0);
}
}
});
}
public static void main(String[] args)
{
EventQueue.invokeLater(new Runnable()
{
public void run()
{
JFrame frame = new TestFrame();
frame.setSize(400, 300);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
});
}
}
Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener(){
.............
});
import java.awt.AWTEvent;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Toolkit;
import java.awt.event.AWTEventListener;
import java.awt.event.KeyEvent;
import javax.swing.JFrame;
public class Escape {
public static void main(final String[] args) {
java.awt.EventQueue.invokeLater(new Runnable(){
public void run(){
final JFrame frame = new JFrame("Example");
final Toolkit toolkit = Toolkit.getDefaultToolkit();
toolkit.addAWTEventListener(new AWTEventListener(){
@Override public void eventDispatched(AWTEvent e){