import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Reloj1
extends JFrame{
private Point puntoCentro
; private boolean ban;
public Reloj1(int x,int y,int a,int b)
{
contenido=getContentPane();
contenido.
setBackground(Color.
white); setSize(a-90,b-35);
setLocation(x,y);
setVisible(true);
PuntoCentro
(new Point(x,y
));
contenido.setLayout(null);
objeto=contenido.getGraphics();
ban=true;
setDefaultCloseOperation(EXIT_ON_CLOSE);
while(ban==true)
{
try{
traza();
manecillas();
}
}
public void PuntoCentro
(Point punto
) {
puntoCentro=punto;
}
public void traza()
{
objeto.
setColor(Color.
WHITE); objeto.fillRect(puntoCentro.x-100,puntoCentro.y-100,200,200);
objeto.
setColor(Color.
RED); objeto.fillOval(puntoCentro.x-2,puntoCentro.y-2,5,5);
objeto.
setColor(Color.
BLUE); int hora;
hora =calendario.
get(Calendar.
HOUR_OF_DAY); for(int i=0;i<12;i++)
{
double ang=(AnguloHora(i,60));
int x2=
(int)(90*(Math.
cos(ang
))); int y2=
(int)(90*(Math.
sin(ang
))); objeto.drawString(""+(i+1),((puntoCentro.x)+(x2))-2,((puntoCentro.y)-(y2))+5);
}
}
public void manecillas()
{
int hora,minutos,segundos;
hora =calendario.
get(Calendar.
HOUR_OF_DAY); minutos=calendario.
get(Calendar.
MINUTE); segundos=calendario.
get(Calendar.
SECOND); double an=(AnguloMin(minutos));
double ang=(AnguloHora(hora,minutos));
int x2=
(int)(90*(Math.
cos(an
))); int y2=
(int)(90*(Math.
sin(an
))); objeto.
setColor(Color.
RED);
objeto.fillOval(((puntoCentro.x)+(x2))-2,((puntoCentro.y)-(y2))-2,5,5);
objeto.drawLine(puntoCentro.x,puntoCentro.y,(puntoCentro.x)+(x2),(puntoCentro.y)-(y2));
an=(AnguloMin(segundos));
x2=
(int)(90*(Math.
cos(an
))); y2=
(int)(90*(Math.
sin(an
))); objeto.fillOval(((puntoCentro.x)+(x2))-2,((puntoCentro.y)-(y2))-2,5,5);
objeto.drawLine(puntoCentro.x,puntoCentro.y,(puntoCentro.x)+(x2),(puntoCentro.y)-(y2));
x2=
(int)(60*(Math.
cos(ang
))); y2=
(int)(60*(Math.
sin(ang
))); objeto.fillOval(((puntoCentro.x)+(x2))-2,((puntoCentro.y)-(y2))-2,5,5);
objeto.drawLine(puntoCentro.x,puntoCentro.y,(puntoCentro.x)+(x2),(puntoCentro.y)-(y2));
if(hora<10)
{
h="0";
}
if(minutos<10)
{
m="0";
}
if(segundos<10)
{
s="0";
}
objeto.
setColor(Color.
WHITE); objeto.fillRect(puntoCentro.x-20,(puntoCentro.y)+(puntoCentro.y),80,30);
objeto.
setColor(Color.
BLUE); objeto.drawString(h+hora+":"+m+minutos+":"+s+segundos,puntoCentro.x-20,(puntoCentro.y)+(puntoCentro.y)+20);
}
public double AnguloMin(int min)
{
double minuto;
minuto=
((90-
(min
*6.0))*(Math.
PI/
180)); return minuto;
}
public double AnguloHora(int hor,int min)
{
double hora;
hora=
(((90-
(hor+
(min/
60.0))*30.0))*((Math.
PI)/
180)); return hora;
}
public static void main
(String[] args
) {
Reloj1 reloj= new Reloj1(100,100,300,300);
reloj.setVisible(true);
}
}