62,628
社区成员
发帖
与我相关
我的任务
分享public class MsgQueue {
// 声明一个消息队列对象
private Vector<HashMap<String, String>> queue = null;
public Vector<HashMap<String, String>> getQueue() {
return queue;
}
public void setQueue(Vector<HashMap<String, String>> queue) {
this.queue = queue;
}
static Myuser32 myuser32 = Myuser32.INSTANCE;
static User32 user32 = User32.INSTANCE;
// 创建消息队列对象
public MsgQueue() {
queue = new Vector<HashMap<String, String>>();
}
// 将用户传入的map加入消息队列列尾
public synchronized void send(HashMap<String, String> map) {
queue.addElement(map);
}
// 将消息队列的元素取出到模拟人工作的方法中
public synchronized HashMap<String, String> recv() {
// 判断如果队列中没有值终止方法
if (queue.size() == 0) {
return null;
}
System.out.println("一开始的大小"+queue.size());
// 将队列中的第一个元素取出
HashMap<String, String> mapping = (HashMap<String, String>) queue
.firstElement();
// 然后将第一个元素删除
// queue.removeElementAt(0);
// 将第一个元素返回
return mapping;
}
// 删除用户需要删除的map
public String delete(HashMap<String, String> map)
throws InterruptedException {
System.out.println("我需要的"+queue.size());
// 遍历消息队列中的map进行比对
for (int i = 1; i < queue.size(); i++) {
HashMap<String, String> hashMap = (HashMap<String, String>) queue
.get(i);
System.out.println("1111111111111111111111111111");
if (map.equals(hashMap)) {
queue.remove(hashMap);
System.out.println("222222222222222222222222222222");
return "删除成功";
} else {
HWND hwndCancel = myuser32.FindWindowEx(
user32.FindWindow(null, "快速转换"), null, "Button", "取消");
myuser32.SendMessage(hwndCancel, 0xF5, 0, null);
while (myuser32.FindWindowEx(
user32.FindWindow(null, "CADdoctor EX6"), null,
"Button", "确定") == null) {
System.out.println("33333333333333333333333333333333");
Thread.sleep(1000);
}
return "取消转换成功";
}
}
return null;
}
// 删除消息队列中的第一个元素
public void remove() {
queue.removeElementAt(0);
}
}
public class Implement {
Myuser32 myuser32 = Myuser32.INSTANCE;
User32 user32 = User32.INSTANCE;
MsgQueue msgqueue = new MsgQueue();
// 新建模拟操作类和消息队列类
Simulation simulation = new Simulation();
public MsgQueue setElement(UserAndPath userAndPath) {
// 获取用户名和用户传入的绝对路径
String user = userAndPath.getUser();
String route = userAndPath.getPath();
// 新建Map对象将用户名和路径传入map中
HashMap<String, String> map = new HashMap<String, String>();
map.put(user, route);
// 将map放入消息队列
msgqueue.send(map);
System.out.println(msgqueue.getQueue().size());
return msgqueue;
}
public void begin() throws InterruptedException, AWTException,
IOException {
if(msgqueue.getQueue().size()>0){
// 运行模拟操作方法
simulation.runtime(msgqueue);
}
}
public String deleteElement(HashMap<String, String> map) {
Vector<HashMap<String, String>> queue = msgqueue.getQueue();
System.out.println("我需要的" + queue.size());
// 遍历消息队列中的map进行比对
for (int i = 1; i < queue.size(); i++) {
HashMap<String, String> hashMap = (HashMap<String, String>) queue
.get(i);
if (map.equals(hashMap)) {
queue.remove(hashMap);
return "删除成功";
} else {
HWND hwndCancel = myuser32.FindWindowEx(
user32.FindWindow(null, "快速转换"), null, "Button", "取消");
myuser32.SendMessage(hwndCancel, 0xF5, 0, null);
while (myuser32.FindWindowEx(
user32.FindWindow(null, "CADdoctor EX6"), null,
"Button", "确定") == null) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
System.out.println("阻塞失败");
}
}
return "取消转换成功";
}
}
return null;
}
}