import java.awt.*; import java.applet.Applet; import java.util.*; import javax.swing.*; import java.awt.event.*; public class Kell1 extends Applet implements ActionListener{ double kx, ky, nr, kr, jsr, jvr, tr, mr, sr; int t=7, m=17, s=27; javax.swing.Timer tm=new javax.swing.Timer(1000, this); public Kell1(){ tm.start(); } public void actionPerformed(ActionEvent e){ repaint(); } public void paint(Graphics g){ kx=getWidth()/2; ky=getHeight()/2; Calendar c=new GregorianCalendar(); t=c.get(Calendar.HOUR); m=c.get(Calendar.MINUTE); s=c.get(Calendar.SECOND); kr=Math.min(kx, ky); nr=kr-15; jsr=kr-25; jvr=kr-30; tr=kr/3; //tunniosuti raadius mr=kr/2; sr=kr*2/3; g.drawOval((int)(kx-kr), (int)(ky-kr), (int)(2*kr), (int)(2*kr)); double tunninurk=Math.toRadians(90-t*30); int tx=(int)(kx+tr*Math.cos(tunninurk)); int ty=(int)(ky-tr*Math.sin(tunninurk)); g.drawLine(tx, ty, (int)kx, (int)ky); double minutinurk=Math.toRadians(90-m*6); int mx=(int)(kx+mr*Math.cos(minutinurk)); int my=(int)(ky-mr*Math.sin(minutinurk)); g.drawLine(mx, my, (int)kx, (int)ky); double sekundinurk=Math.toRadians(90-s*6); int sx=(int)(kx+sr*Math.cos(sekundinurk)); int sy=(int)(ky-sr*Math.sin(sekundinurk)); g.drawLine(sx, sy, (int)kx, (int)ky); //Lisage ka minuti- ja sekundiosuti for(int tund=1; tund<=12; tund++){ double nurk=Math.toRadians(90-tund*30); int nx=(int)(kx+nr*Math.cos(nurk)); int ny=(int)(ky-nr*Math.sin(nurk)); g.drawString(String.valueOf(tund), nx-5, ny+6); int jsx=(int)(kx+jsr*Math.cos(nurk)); int jsy=(int)(ky-jsr*Math.sin(nurk)); int jvx=(int)(kx+jvr*Math.cos(nurk)); int jvy=(int)(ky-jvr*Math.sin(nurk)); g.drawLine(jsx, jsy, jvx, jvy); } } public static void main(String[] arg){ Frame f=new Frame("Kell"); f.add(new Kell1()); f.setSize(300, 300); f.setVisible(true); } }