java jwindow 键盘_各位老哥求救,JWINDOW无法接收到键盘监听
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
下面po代码啊。这是我的类。
class DragWindow extends JWindow{
int positionX;
int positionY;
public DragWindow() {
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
this.addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(MouseEvent e) {
this_mousePressed(e);
}
});
this.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
public void mouseDragged(MouseEvent e) {
this_mouseDragged(e);
}
});
this.addKeyListener(new java.awt.event.KeyAdapter() {
publicvoid keypressed(KeyEvent e){
this_KeyPress(e);
}
});
}
void this_mouseDragged(MouseEvent e) {
Point point = this.getLocation();
this.setLocation(point.x + e.getX() - positionX,point.y + e.getY() - positionY);
}
void this_mousePressed(MouseEvent e) {
positionX = e.getX();
positionY = e.getY();
}
voidthis_KeyPress(KeyEvent e) {
Point point = this.getLocation();
if(e.getKeyCode()==KeyEvent.VK_LEFT)
this.setLocation(point.x - 2,point.y);
if(e.getKeyCode()==KeyEvent.VK_RIGHT)
this.setLocation(point.x + 2,point.y);
if(e.getKeyCode()==KeyEvent.VK_UP)
this.setLocation(point.x,point.y - 2);
if(e.getKeyCode()==KeyEvent.VK_DOWN)
this.setLocation(point.x,point.y + 2);
}
总结
以上是生活随笔为你收集整理的java jwindow 键盘_各位老哥求救,JWINDOW无法接收到键盘监听的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: 沃尔沃s40加速时车身抖动松开油门不抖?
- 下一篇: java文件编码格式环境变量_Jenki