M
mlt
Gast
so das ist mein code
ja die uhr wird zwar korrekt gezeichnet ... aber sie läuft halt net .. .weiß immo so garnicht woran es liegen kann ...
und naja ist mein erster thread den ich programmiere .... =/
mfg malte
ps: danke
Code:
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.lang.*;
public class DieUhr{
public static void main(String[] args) {
Frame1 frame1 = new Frame1();
Uhr uc = new Uhr();
Thread t = new Thread (uc);
t.start();
uc.setRunFlag(false);
frame1.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{ System.exit(0);
}
} );
frame1.add(uc);
frame1.setSize(500,500);
frame1.show();
uc.run();
}
}
class Frame1 extends Frame
{
public Frame1()
{
}
}
class Uhr extends Canvas implements Runnable{
int mitte = 250;
Calendar date = new GregorianCalendar();
int hours = date.get(Calendar.HOUR_OF_DAY);
int minutes = date.get(Calendar.MINUTE);
int seconds = date.get(Calendar.SECOND);
private volatile boolean runFlag;
public void setRunFlag (boolean runFlag) {
this.runFlag = runFlag;
}
public boolean getRunFlag() {
return this.runFlag;
}
public void run() {
runFlag=true;
while (runFlag) {
xstu(date.get(Calendar.HOUR_OF_DAY));
xmin(date.get(Calendar.MINUTE));
xsek(date.get(Calendar.SECOND));
try
{
Thread.sleep(1000);
}
catch(InterruptedException e)
{
}
repaint();
}
}
public void paint(Graphics g) {
g.setColor(Color.BLACK);
g.fillRect(0,0,500,500);
g.drawOval(240,240,20,20);
g.setColor(Color.GRAY);
g.fillRect(150,150,200,200);
g.setColor(Color.BLACK);
g.drawOval(240,240,20,20);
g.setColor(Color.WHITE);
g.drawLine(
mitte,mitte,mitte+(int)(60*Math.cos(Math.toRadians(hours%12*30+minutes/2.0-90))),
mitte+(int)(60*Math.sin(Math.toRadians(hours%12*30+minutes/2.0-90))));
g.setColor(Color.WHITE);
g.drawLine(
mitte,mitte,mitte+(int)(85*Math.cos(Math.toRadians(minutes*6-90))),
mitte+(int)(85*Math.sin(Math.toRadians(minutes*6-90))));
g.setColor(Color.RED);
g.setColor(Color.RED);
g.drawLine(
mitte,mitte,mitte+(int)(90*Math.cos(Math.toRadians(seconds*6-90))),
mitte+(int)(90*Math.sin(Math.toRadians(seconds*6-90))));
}
public void xstu(int xstunden)
{
hours=xstunden;
}
public void xmin(int xminuten)
{
minutes=xminuten;
}
public void xsek(int xsekunden)
{
seconds=xsekunden;
}
}
ja die uhr wird zwar korrekt gezeichnet ... aber sie läuft halt net .. .weiß immo so garnicht woran es liegen kann ...
und naja ist mein erster thread den ich programmiere .... =/
mfg malte
ps: danke