该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
下面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);
}