import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.util.GregorianCalendar;
import javax.swing.JLabel;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Paolo
*/
public Orologio() {
this.start();
this.setVisible(true);
this.setLocation(0, 0);
this.setSize(100, 100);
}
public void start() {
this.
start = new Thread(this);
this.start.start();
}
public void stop() {
this.start.stop();
}
@Override
protected void paintComponent
(Graphics g
) {
int angolo = 360 / 12;
int angolosecmin = 360 / 60;
int angolosec = sec * angolosecmin - 90;
int angolomin = min * angolosecmin - 90;
int angoloore = ore * angolo - 90;
Angle secondi = new Angle(angolosec);
Angle minuti = new Angle(angolomin);
Angle hour = new Angle(angoloore);
int lunghezza = this.getSize().width / 2;
int secX = (int) (secondi.getX() * lunghezza) + lunghezza;
int secY = (int) (secondi.getY() * lunghezza) + lunghezza;
int minX = (int) (minuti.getX() * lunghezza) + lunghezza;
int minY = (int) (minuti.getY() * lunghezza) + lunghezza;
int oreX = (int) (hour.getX() * (lunghezza - (lunghezza / 3))) + lunghezza;
int oreY = (int) (hour.getY() * (lunghezza - (lunghezza / 3))) + lunghezza;
g.fillOval(0, 0, lunghezza * 2, lunghezza * 2);
g.drawOval(0, 0, lunghezza * 2, lunghezza * 2);
g.drawLine(lunghezza, lunghezza, secX, secY);
g.drawLine(lunghezza, lunghezza, minX, minY);
g.drawLine(lunghezza, lunghezza, oreX, oreY);
super.paintComponent(g);
}
@Override
public void setSize(int width, int height) {
if (width > height) {
width = height;
} else if (height > width) {
height = width;
}
super.setSize(width, height);
}
@Override
this.setSize(dimension.width, dimension.height);
}
public void run() {
while (true) {
this.repaint();
try {
}
}
}
}