📄 controlledthread2.java
字号:
import java.awt.*;
public class ControlledThread2 extends Thread
{
static final int RUN = 0;
static final int SUSP = 1;
static final int STOP = 2;
private int state = RUN;
private int i;
private Label lb;
public ControlledThread2(Label l)
{
lb = l;
}
public synchronized void setState(int s)
{
state = s;
if (state == RUN)
notify();
}
public synchronized boolean checkState()
{
while (state == SUSP)
{
try {
wait();
}
catch (InterruptedException e) { }
}
if (state == STOP)
return false;
return true;
}
public void run()
{
while (true)
{
i++;
lb.setText(String.valueOf(i));
try {
Thread.sleep(500);
}
catch (InterruptedException e) { }
if ( !checkState() )
break;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -