📄 animatedelete.java
字号:
package kyodai.map;
import java.awt.*;
import javax.swing.*;
import kyodai.*;
/**
* 消除连连看方块的类
*/
public class AnimateDelete implements Runnable {
static JButton[] dots;
static long delay = 270;
int[] array = new int[44]; //最大距离只可能为2行1列
private int count = 0;
private volatile Thread thread;
////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////
public AnimateDelete(int[]path,int l)
{
array=path;count=l;start();
}
public AnimateDelete(JButton[] dots) {
this.dots = dots;
array = new int[0];
}
public void setSpeed(int speed) {
delay = speed * 12;
}
/*public void test() {
if (array == null || array.length == 0) {
return;
}
for (int i = 0; i < array.length; i++) {
if (array[i] != -1) {
message("[" + array[i] + "] ");
}
}
System.out.println();
}*/
public void start() {
thread = new Thread(this);
thread.start();
}
public void run() {
if (count < 2) {
return;
}
Thread currentThread = Thread.currentThread();
boolean animate = true;
while (thread == currentThread && animate) {
for (int i = 1; i < count - 1; i++) {
dots[array[i]].setEnabled(true);
dots[array[i]].setIcon(Kyodai.GuideIcon);
try {
thread.sleep(delay);
}
catch (InterruptedException ex) {
}
}
for (int i = 1; i < count - 1; i++) {
dots[array[i]].setIcon(null);
dots[array[i]].setEnabled(false);
try {
thread.sleep(delay);
}
catch (InterruptedException ex) {
}
}
for (int i = 0; i < count; i++) {
dots[array[i]].setBorder(Kyodai.unSelected);
}
dots[array[0]].setIcon(null);
dots[array[0]].setEnabled(false);
dots[array[count - 1]].setIcon(null);
dots[array[count - 1]].setEnabled(false);
animate = false;
}
stop();
}
public void stop() {
if (thread != null) {
thread = null;
}
}
void message(String str) {
System.out.println(str);
}
}
////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -