62,614
社区成员
发帖
与我相关
我的任务
分享
package com.test.swing;
import java.awt.Dimension;
import java.awt.KeyboardFocusManager;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.Collections;
import javax.swing.JFrame;
public class Test extends JFrame {
public Test(){
super();
//this.setPreferredSize(new Dimension(300,200));
this.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, Collections.EMPTY_SET);
this.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, Collections.EMPTY_SET);
this.setSize(new Dimension(300,200));
this.addKeyListener(new KeyListener() {
@Override
public void keyTyped(KeyEvent e) {
//System.out.println(e);
}
@Override
public void keyReleased(KeyEvent e) {
//System.out.println(e);
}
@Override
public void keyPressed(KeyEvent e) {
System.out.println(e);
}
});
this.setAlwaysOnTop(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// this.pack();
this.setLocationRelativeTo(null);
this.setVisible(true);
}
/**
* @param args
*/
public static void main(String[] args) {
new Test();
}
}
this.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, Collections.EMPTY_SET); this.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, Collections.EMPTY_SET);