import java.awt.Color;
import java.awt.Graphics;
import java.util.Calendar;
import java.util.GregorianCalendar;
import javax.swing.JFrame;
public class ClockApplication extends JFrame {
private int c_x, c_y;
private int radh, radms;
private String name = "";
private int x = 0;
private int y = 0;
public ClockApplication() {
super("Analoguhr");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setAlwaysOnTop(true);
this.setLocationByPlatform(true);
this.setSize(320, 480);
c_x = 150;
c_y = 250;
radh = 50;
radms = 75;
this.setVisible(true);
}
public static void main(String[] args) {
ClockApplication ca = new ClockApplication();
ca.startClock();
}
public void startClock() {
new Thread() {
public void run() {
while (true) {
ClockApplication.this.repaint();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
}
}
}.start();
}
public void paint(Graphics g) {
int h_x, h_y, m_x, m_y, s_x, s_y;
int h, m, s;
Calendar cal = new GregorianCalendar();
cal.setTimeInMillis(System.currentTimeMillis());
h = cal.get(Calendar.HOUR);
m = cal.get(Calendar.MINUTE);
s = cal.get(Calendar.SECOND);
h_x = (int) (radh * Math.sin(2 * Math.PI / 720 * (h * 60 + m)) + c_x);
h_y = (int) (radh
* Math.cos(2 * Math.PI / 720 * (h * 60 + m) + Math.PI) + c_y);
m_x = (int) (radms * Math.sin(2 * Math.PI / 60 * m) + c_x);
m_y = (int) (radms * Math.cos(2 * Math.PI / 60 * m + Math.PI) + c_y);
s_x = (int) (radms * Math.sin(2 * Math.PI / 60 * s) + c_x);
s_y = (int) (radms * Math.cos(2 * Math.PI / 60 * s + Math.PI) + c_y);
g.setColor(Color.DARK_GRAY);
g.fillOval(c_x - radms - 15, c_y - radms - 15, radms * 2 + 30,
radms * 2 + 30);
g.setColor(Color.LIGHT_GRAY);
g.fillOval(c_x - radms - 10, c_y - radms - 10, radms * 2 + 20,
radms * 2 + 20);
g.setColor(Color.PINK);
g.fillRect(c_x + 35, c_y - 10, 20, 20);
g.setColor(Color.DARK_GRAY);
g.drawString("" + cal.get(Calendar.DAY_OF_MONTH), c_x + 38, c_y + 5);
g.drawString(name, c_x + x, c_y + y);
g.fillOval(c_x - 3, c_y - 3, 6, 6);
g.setColor(Color.BLUE);
for (int i = 0; i < 60; i++)
g
.drawLine(
(int) (80 * Math.sin(2 * Math.PI / 60 * i) + c_x),
(int) (80 * Math
.cos(2 * Math.PI / 60 * i + Math.PI) + c_y),
(int) (85 * Math.sin(2 * Math.PI / 60 * i) + c_x),
(int) (85 * Math
.cos(2 * Math.PI / 60 * i + Math.PI) + c_y));
g.setColor(Color.RED);
for (int i = 0; i < 12; i++)
g
.drawLine(
(int) ((radms + 2) * Math.sin(2 * Math.PI / 12 * i) + c_x),
(int) ((radms + 2)
* Math.cos(2 * Math.PI / 12 * i + Math.PI) + c_y),
(int) ((radms + 10)
* Math.sin(2 * Math.PI / 12 * i) + c_x),
(int) ((radms + 10)
* Math.cos(2 * Math.PI / 12 * i + Math.PI) + c_y));
g.setColor(Color.YELLOW);
for (int i = 1; i <= 12; i++)
g.drawString("" + i, (int) (65 * Math.sin(2 * Math.PI / 12 * i)
+ c_x - 5), (int) (65
* Math.cos(2 * Math.PI / 12 * i + Math.PI) + c_y + 5));
g.setColor(Color.BLUE);
g.drawLine(c_x, c_y, h_x, h_y);
g.drawLine(c_x, c_y, m_x, m_y);
g.drawLine(c_x, c_y, s_x, s_y);
}
}