device transfer
commit
085ebeb470
|
@ -0,0 +1,32 @@
|
|||
public class Sensor extends Thread {
|
||||
private final long frequency;
|
||||
|
||||
public Sensor(long frequency) {
|
||||
this.frequency = frequency;
|
||||
start();
|
||||
}
|
||||
|
||||
public long getFrequency() {
|
||||
return this.frequency;
|
||||
}
|
||||
|
||||
protected String reading() {
|
||||
// eigentlich abstract
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
while(true) {
|
||||
System.out.println("reading: " + reading());
|
||||
try {
|
||||
Thread.sleep(this.frequency);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
}
|
||||
public static void main(String... args) {
|
||||
var s = new Sensor(1000);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
import javax.swing.plaf.TableHeaderUI;
|
||||
import java.util.Random;
|
||||
|
||||
public class Thermometer extends Sensor {
|
||||
private final Random rand;
|
||||
|
||||
public Thermometer(long frequency) {
|
||||
super(frequency);
|
||||
this.rand = new Random();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String reading() {
|
||||
return String.format("(%04d freq.): %3d°C", getFrequency(), this.rand.nextInt(100));
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
var s1 = new Thermometer(1000);
|
||||
var s2 = new Thermometer(3000);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue