📄 inpairsbuttoneventlistener.java
字号:
/*
* @(#)InPairsButtonEventListener.java 1.0 03/08/22
* Copyright 2003 Entao Zhang, All rights reserved.
*/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
/**
* 拼图记忆方式的事件处理类.本类使用了多线程对话的处理方式保证延时及
* swing界面的更新.
*/
public class InPairsButtonEventListener extends
ComponentsEventListener implements ActionListener,Runnable{
private int loc,swap;
private int grids[];
private boolean pause=false;
private InPairsButtonManager cm;
public InPairsButtonEventListener(ImageRevertUnitPane ir,InPairsButtonManager cm){
super(ir);
this.cm=cm;
Thread t=new Thread(this);
t.setPriority(Thread.MIN_PRIORITY);
t.start();
}
public void addListener(Component c){
((JButton)c).addActionListener(this);
}
public void actionPerformed(ActionEvent e){
if (ir.isConfused()){
if (pause){
return;
}
grids=ir.grids;
swap=ir.swap;
loc=Integer.parseInt(((Component)e.getSource()).getName());
ir.swap=loc;
ir.cm.swapStateChange(false);
if (swap!=-1){
if(grids[swap]!=grids[loc]){
cm.sum-=2;
synchronized(this){
notify();
}
}
ir.swap=-1;
}
cm.sum++;
if(cm.sum==ir.gridLength){
ir.done();
}
}else{
ir.questionToStart();
}
}
public void run(){
while(true){
try {
synchronized(this){
wait();
}
pause=true;
Thread.sleep(500);
ir.cm.componentStateChange(swap);
ir.cm.componentStateChange(loc);
pause=false;
}catch (InterruptedException e) {}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -