swing判断程序是否已经运行。。。
try {
//
String os_name = System.getProperty("os.name");
// 指定文件锁路径
String path = null;
if (os_name.indexOf("Windows") > -1) {
// 如果是Windows操作系统
path = System.getProperty("user.home")
+ System.getProperty("file.separator");
} else {
path = "/usr/temp/";
}
File dir = new File(path);
if (!dir.exists()) {
dir.mkdirs();
}
// 程序名称
String applicationName = "sms";
RandomAccessFile fis = new RandomAccessFile(path + applicationName
+ ".lock", "rw");
FileChannel lockfc = fis.getChannel();
FileLock flock = lockfc.tryLock();
System.out.println(OnProcess.isLink());
if (flock == null) {
ShowMessageDialog show=new ShowMessageDialog();
show.show(2, "程序已经运行到托盘!请点击托盘图标运行程序..");
return true;
}
用这种简单方式只能判断程序已经运行了
但有个问题
如果我的程序第一次运行了,并且在托盘处托盘了
如果我再点击一次开始启动程序,要怎么才能找到先前那个进程
让托盘的程序弹出
大家看看快拨那个就知道了
谢谢高人指点啊