该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JFrame;
public class AutoHideFrame extends JFrame implements Runnable, MouseListener {
private Thread thread = null;
private boolean hide = false;
AutoHideFrame() {
thread = new Thread(this);
this.setTitle("AutoHide");
this.setSize(400, 300);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setVisible(true);
this.addMouseListener(this);
thread.start();
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
new AutoHideFrame();
}
public void run() {
// TODO Auto-generated method stub
while (true) {
if (Thread.currentThread().equals(thread)) {
double x = getLocation().getX();
double y = getLocation().getY();
System.out.println("x:=" + x + " y=" + y);
if (y <= 0) {
this.setLocation((int) x,
(int) (-getSize().getHeight() + 5));
hide = true;
}
}
}
}
public void mouseClicked(MouseEvent arg0) {
// TODO Auto-generated method stub
}
public void mouseEntered(MouseEvent arg0) {
// TODO Auto-generated method stub
if (hide == true) {
this.setLocation((int) getLocation().getX(), 1);
hide = false;
}
}
public void mouseExited(MouseEvent arg0) {
// TODO Auto-generated method stub
}
public void mousePressed(MouseEvent arg0) {
// TODO Auto-generated method stub
}
public void mouseReleased(MouseEvent arg0) {
// TODO Auto-generated method stub
}
}