import Component native "java/awt/Component" import Contain native "java/awt/Container" import Panel native "java/awt/Panel" import Applet native "java/applet/Applet" import Font native "java/awt/Font" import Graphics native "java/awt/Graphics" import Color native "java/awt/Color" import Date native "java/util/Date" import Math native "java/lang/Math" import Window native "java/awt/Window" import Frame native "java/awt/Frame" class public clock extends Applet { int lastxs; int lastys; int lastxm; int lastym; int lastxh; int lastyh; Date dummy; String lastdate; Font F; Date dat; Color fgcol; Color fgcol2; constructor(){ super(); this.lastxs=0; this.lastys=0; this.lastxm=0; this.lastym=0; this.lastxh=0; this.lastyh=0; this.dummy = Date(null); this.F = new Font("TimesRoman", Font.BOLD, 14); this.dat = new Date(); this.fgcol = Color.blue; this.fgcol2 = Color.darkGray; this.lastdate = this.dat.toLocaleString(); this.dat = Date(null); return; } public void init(){ this.setBackground(Color.yellow); this.resize(300,300); return; } public void circle(int x0, int y0, int r, Graphics g){ g.drawOval(x0-r,y0-r,r+r,r+r); return; } public void waitsec(){ Date d1;int ls,ns; d1=new Date(); ls=d1.getSeconds(); ns=ls; d1=Date(null); while(ls==ns){ d1=new Date(); ls=d1.getSeconds(); d1=Date(null); } return; } public void paint(Graphics g){ int xh, yh, xm, ym, xs, ys, s, m, h, xcenter, ycenter; String today; int lasts; lasts=0; while (this.dummy != Date(null)) { this.waitsec(); this.dat = new Date(); s = this.dat.getSeconds(); m = this.dat.getMinutes(); h = this.dat.getHours(); today = this.dat.toLocaleString(); xcenter=80; ycenter=55; // x = r(cos a) + xcenter, y = r(sin a) + ycenter xs = int(Math.cos(double(s)*3.14/30.0-3.14/2.0)*45.0) + xcenter; ys = int(Math.sin(double(s)*3.14/30.0-3.14/2.0)*45.0) + ycenter; xm = int(Math.cos(double(m)*3.14/30.0-3.14/2.0)*40.0) + xcenter; ym = int(Math.sin(double(m)*3.14/30.0-3.14/2.0)*40.0) + ycenter; xh = int(Math.cos((double(h)*30.0+double(m/2))*3.14/180.0-3.14/2.0)*30.0) + xcenter; yh = int(Math.sin((double(h)*30.0+double(m/2))*3.14/180.0-3.14/2.0)*30.0) + ycenter; // Draw the circle and numbers g.setFont(this.F); g.setColor(this.fgcol); this.circle(xcenter,ycenter,50,g); g.setColor(this.fgcol2); g.drawString("9",xcenter-45,ycenter+3); g.drawString("3",xcenter+40,ycenter+3); g.drawString("12",xcenter-5,ycenter-37); g.drawString("6",xcenter-3,ycenter+45); // Erase if necessary, and redraw g.setColor(this.getBackground()); g.drawString(this.lastdate, 5, 125); if (xs != this.lastxs || ys != this.lastys) { g.drawLine(xcenter, ycenter, this.lastxs, this.lastys); } if (xm != this.lastxm || ym != this.lastym) { g.drawLine(xcenter, ycenter-1, this.lastxm, this.lastym); g.drawLine(xcenter-1, ycenter, this.lastxm, this.lastym); } if (xh != this.lastxh || yh != this.lastyh) { g.drawLine(xcenter, ycenter-1, this.lastxh, this.lastyh); g.drawLine(xcenter-1, ycenter, this.lastxh, this.lastyh); } g.setColor(this.fgcol2); g.drawString(today, 5, 125); g.drawLine(xcenter, ycenter, xs, ys); g.setColor(this.fgcol); g.drawLine(xcenter, ycenter-1, xm, ym); g.drawLine(xcenter-1, ycenter, xm, ym); g.drawLine(xcenter, ycenter-1, xh, yh); g.drawLine(xcenter-1, ycenter, xh, yh); this.lastxs=xs; this.lastys=ys; this.lastxm=xm; this.lastym=ym; this.lastxh=xh; this.lastyh=yh; this.lastdate = today; this.dat=Date(null); } return; } public void start(){ this.dummy=new Date(); return; } public void stop(){ this.dummy=Date(null); return; } public void update(Graphics g){ this.paint(g); return; } }