/**This is an applet which acts as an * ana-digi watch! * @see TimeClass * @version 1.0 */ // importing java packages... import java.applet.Applet; import java.awt.*; import java.math.*; //defining the class... public class AnaDigiWatch extends Applet implements Runnable { private static int xCenter = 70; private static int yCenter = 90; private static int radiusSec = 58; private static int radiusMin = 50; private static int radiusHr = 40; private int valueNowSec = 0; private int xEndSec = 70; private int yEndSec = 90; private int valueNowMin = 0; private int xEndMin = 70; private int yEndMin = 90; private int valueNowHr = 0; private int xEndHr = 70; private int yEndHr = 90; boolean isThreadStopped; TimeClass myTime; Thread myThread; public void init() { setBackground(Color.white); setForeground(Color.black); } public void start() { myTime = new TimeClass(); myThread = new Thread(this); isThreadStopped = false; myThread.start(); } public void run() { for ( ; ; ) { try { repaint(); Thread.sleep(1000); myTime.checkPresentTime(); valueNowSec = myTime.getPresentSeconds(); valueNowMin = myTime.getPresentMinutes(); valueNowHr = myTime.getPresent12Hours(); updateXY(valueNowSec, valueNowMin, valueNowHr); if (isThreadStopped) { break; } } catch (Exception e) { } } } public void stop() { isThreadStopped = true; myThread = null; } public void paint(Graphics g) { g.drawString("The AnaDIGI Watch",20,20); g.drawOval(10,30,120,120); g.setColor(Color.red); g.drawLine(xCenter, yCenter, xEndSec, yEndSec); g.setColor(Color.blue); g.drawLine(xCenter, yCenter, xEndMin, yEndMin); g.setColor(Color.black); g.drawLine(xCenter, yCenter, xEndHr, yEndHr); g.drawString(myTime.getPresentTime(),50,170); } private void updateXY(int val1, int val2, int val3) { xEndSec = 70 + (int)(radiusSec * Math.sin(3.14159 + ((- 1) * 3.14159/30) * val1)); yEndSec = 90 + (int)(radiusSec * Math.cos(3.14159 + ((- 1) * 3.14159/30) * val1)); xEndMin = 70 + (int)(radiusMin * Math.sin(3.14159 + ((- 1) * 3.14159/30) * val2)); yEndMin = 90 + (int)(radiusMin * Math.cos(3.14159 + ((- 1) * 3.14159/30) * val2)); xEndHr = 70 + (int)(radiusHr * Math.sin(3.14159 + ((- 1) * 3.14159/6) * val3)); yEndHr = 90 + (int)(radiusHr * Math.cos(3.14159 + ((- 1) * 3.14159/6) * val3)); } }