这里有个设置界面可以隐藏的方法,也就是第四题:
// 设置界面可以拖动的方法
Point loc = null;
Point tmp = null;
boolean isDragged = false;
private void setDragable() {
this.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseReleased(java.awt.event.MouseEvent e) {
isDragged = false;
QQMain.this.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
if(QQMain.this.getLocation().y<0){
try {
Thread.sleep(500);
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
QQMain.this.setLocation(QQMain.this.getLocation().x, -590);
}
}
public void mousePressed(java.awt.event.MouseEvent e) {
tmp = new Point(e.getX(), e.getY());
isDragged = true;
QQMain.this.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
}
//鼠标进入事件
@Override
public void mouseEntered(MouseEvent e) {
if(QQMain.this.getLocation().y<0){
try {
Thread.sleep(500);
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
QQMain.this.setLocation(QQMain.this.getLocation().x, 20);
}
}
});
this.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
public void mouseDragged(java.awt.event.MouseEvent e) {
if (isDragged) {
loc = new Point(QQMain.this.getLocation().x + e.getX()
- tmp.x, QQMain.this.getLocation().y + e.getY()
- tmp.y);
QQMain.this.setLocation(loc);//设置当前窗口的位置
}
}
});
}