|
|
|
|
|
|
|
|
import javax.swing.JComponent; |
|
|
import javax.swing.JComponent; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* |
|
|
|
|
|
* @author ahren |
|
|
|
|
|
|
|
|
* Klasse für selbst gezeichnete Zeiger, die sich über einenn eigenen Thread |
|
|
|
|
|
* drehen können. |
|
|
|
|
|
* @author Je-To |
|
|
*/ |
|
|
*/ |
|
|
public class Zeiger extends JComponent implements Runnable |
|
|
public class Zeiger extends JComponent implements Runnable |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
private ExecutorService eService; |
|
|
private ExecutorService eService; |
|
|
private Future task; |
|
|
private Future task; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Initialisierung des Zeigers |
|
|
|
|
|
* @param schlafzeit = Zeit, die der Thread wartet, bevor der Zeiger sich |
|
|
|
|
|
* wieder weiterbewegt |
|
|
|
|
|
* @param zeigerlaenge = verhältnismäßige Zeigerlänge |
|
|
|
|
|
*/ |
|
|
public Zeiger(long schlafzeit, int zeigerlaenge) |
|
|
public Zeiger(long schlafzeit, int zeigerlaenge) |
|
|
{ |
|
|
{ |
|
|
this.schlafzeit = schlafzeit; |
|
|
this.schlafzeit = schlafzeit; |
|
|
|
|
|
|
|
|
task = null; |
|
|
task = null; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Thread für das Ändern des Winkels |
|
|
|
|
|
*/ |
|
|
@Override |
|
|
@Override |
|
|
public void run() |
|
|
public void run() |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
synchronized(this) |
|
|
synchronized(this) |
|
|
{ |
|
|
{ |
|
|
alpha += 0.08; |
|
|
alpha += 0.08; |
|
|
xAussen = xMitte +cos(2*PI*alpha) * radius; |
|
|
|
|
|
yAussen = yMitte + sin(2*PI*alpha) * radius; |
|
|
|
|
|
} |
|
|
} |
|
|
this.repaint(); |
|
|
this.repaint(); |
|
|
try |
|
|
try |
|
|
|
|
|
|
|
|
task = eService.submit(this); |
|
|
task = eService.submit(this); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Zeichnen des Zeigers abhängig vom Winkel Alpha |
|
|
|
|
|
* @param g |
|
|
|
|
|
*/ |
|
|
@Override |
|
|
@Override |
|
|
public void paintComponent(Graphics g) |
|
|
public void paintComponent(Graphics g) |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
float breite = this.getWidth() - 1; |
|
|
float breite = this.getWidth() - 1; |
|
|
float hoehe = this.getHeight() - 1; |
|
|
float hoehe = this.getHeight() - 1; |
|
|
|
|
|
|
|
|
radius = (min(hoehe, breite)/2 *0.9) * 1/ zeigerlaenge; |
|
|
|
|
|
|
|
|
radius = (min(hoehe, breite)/2 * 0.9) * 1/ zeigerlaenge; |
|
|
|
|
|
|
|
|
xMitte = breite/2; |
|
|
xMitte = breite/2; |
|
|
yMitte = hoehe/2; |
|
|
yMitte = hoehe/2; |