package Graphics;
public class AnotherCounter implements Runnable {
Thread thread;
private boolean start=true;
private int value;
public AnotherCounter(){
setValue(0);
thread = new Thread(this);
thread.start();
}
public void run() {
while(isStart()){
System.out.println(getValue());
try {
thread.sleep(200);
setValue(getValue() + 1);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}
}
private boolean isStart() {
return start;
}
private void setValue(int value) {
this.value=value;
}
private int getValue() {
return value;
}
public static void main(String[] args) {
AnotherCounter c= new AnotherCounter();
}
}
Tidak ada komentar:
Posting Komentar