import java.awt.*;
import javax.swing.*;
import java.util.Date;
public class AnalogUhrGui extends JFrame /*implements TimeCustomer*/{
int mystunde;
int myminute;
int mysekunde;
private ClockThread thread;
private Date date = new Date();
private JPanel p = new JPanel();
public AnalogUhrGui(int stunde, int minute, int sekunde)
{
super("Uhr");
mystunde = stunde;
System.out.println(mystunde);
myminute = minute;
System.out.println(myminute);
mysekunde = sekunde;
System.out.println(mysekunde);
this.setBackground(Color.lightGray);
this.setLocation(200,250);
this.setSize(400,300);
this.setDefaultCloseOperation( EXIT_ON_CLOSE );
this.setContentPane(p);
this.setVisible(true);
thread = new ClockThread(this);
thread.start();
}
public void paint(Graphics g)
{
g.setColor( Color.blue );
g.drawOval(100,50,200,200); //Kreis
g.setColor(Color.red);
//System.out.println("die Stunde is" + stunde);
if (mystunde > 11) {
mystunde -= 12;
}
if (mystunde == 12) {
g.drawLine(200,150,200,50);} //12 Uhr
else if (mystunde == 1) {
......................
.........PEINLICH:)
................
else {
g.drawLine(200,150,200,50); }//60 Sekunden und 0 Sekunden ELSE
g.drawString("12", 195, 45);
g.drawString("3", 305, 150);
g.drawString("9", 90, 150);
g.drawString("6", 195, 265);
}
public void setTime(Date date) {
mystunde = date.getHours();
myminute = date.getMinutes();
mysekunde = date.getSeconds();
}
public void erneuern() {
p.updateUI();
this.repaint();
//this.setVisible(false);
//this.setVisible(true);
}
public static void
drawThickLine( int x, int y, int x2, int y2, int thickness, Graphics g )
{
int b = Math.round( thickness /2), deltax, deltay;
double angle;
//if (y2==y) alpha = 0; else
angle = Math.atan( (double)((y2-y)/(x2-x)) );
deltay = (int)Math.round( (Math.cos(angle)*b) );
deltax = (int)Math.round( (Math.sin(angle)*b) );
Polygon p = new Polygon();
p.addPoint( x-deltax, y+deltay );
p.addPoint( x+deltax, y-deltay );
p.addPoint( x2+deltax, y2-deltay );
p.addPoint( x2-deltax, y2+deltay );
g.fillPolygon( p );
}
}