隐藏的线程实现
来源:互联网 发布:清华大学网络公开课 编辑:程序博客网 时间:2024/05/16 19:02
主要思想就是检测窗口在屏幕上的位置。当窗口靠边的时候就重新设置窗口的位置。
导包就省略了……
public class AutoHideFrame extends JFrame implements Runnable, MouseListener {
private Thread thread = null;
private boolean hide = false;
private Toolkit tk = getToolkit();
private final int TOP = 1;
private final int RIGHT = 2;
private int direction;
AutoHideFrame() {
thread = new Thread(this);
this.setTitle("Auto Hide");
this.setResizable(false);
this.setSize(200, 600);
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)) {
System.out.println("Thread Working...");
double x = getLocation().getX(); //获取当前窗口在屏幕上的X坐标
double y = getLocation().getY();//获取当前窗口在屏幕上的Y坐标
System.out.println("x:=" + x + " y=" + y);
// 靠顶隐藏
if (y <= 0) { //判断窗口靠顶
this.setLocation((int) x,
(int) (-getSize().getHeight() + 10)); //重新设置窗口坐标。+ 10是为了露出来一点
hide = true; //方便监听鼠标移入事件
direction = TOP;
}
//靠右边隐藏
if (x >= tk.getScreenSize().getWidth() - getSize().getWidth()) {
this.setLocation((int) (tk.getScreenSize().getWidth() - 5),
(int) y);
hide = true;
direction = RIGHT;
}
}
}
}
public void mouseClicked(MouseEvent arg0) {
// TODO Auto-generated method stub
}
public void mouseEntered(MouseEvent arg0) {
// TODO Auto-generated method stub
if (hide == true) {
if (direction == TOP) {
this.setLocation((int) getLocation().getX(), 1);
}
if (direction == RIGHT) {
this.setLocation((int) (tk.getScreenSize().getWidth()
- getSize().getWidth()-5), (int)getLocation().getY());
}
hide = false;
}
}
//不关注的方法被删除了,没有写出来。
}
- 隐藏的线程实现
- 隐藏的线程实现2
- 隐藏的线程死锁
- 远程线程嵌入方式 实现DLL的隐藏
- Java的隐藏实现
- 进程隐藏的实现
- 实现进程的隐藏
- 隐藏实现的用处
- 实现进程的隐藏
- java线程:单例隐藏ThreadLocal实现线程数据共享
- 在UI线程中实现定时隐藏UI控件的效果
- Java并发:隐藏的线程死锁
- 进程隐藏方法的实现
- 对话框隐藏的简单实现
- 实现进程的完全隐藏
- 进程隐藏工具的实现
- ring0实现进程的隐藏
- 隐藏虚拟按键的实现
- java Jfram自动隐藏
- ibm aix61 管理员及用户入门(1)
- 最近的一些开发想法
- setuid,setgid,stickybit的三个权限的详细说明
- flash安全策略的理解
- 隐藏的线程实现
- 6位16进制转换器
- asdf
- 隐藏的线程实现2
- 修改grub启动项
- Microsoft eMbedded Visual C++ has discovered no CE platform SDK installed on the desktop please install at least one CE platform
- 使用 VMProtect 出现 未闭合标识的解决方法
- [opendoc]swift实战_纲要
- Silverlight, RIA Services, Data Annotation与本地化资源文件共享