import java.awt.*; import java.awt.event.*; import java.applet.Applet; import java.util.*; public class Kell2 extends Applet implements Runnable{ int tund, minut; TextField tfTunnid=new TextField(); TextField tfMinutid=new TextField(); public Kell2(){ add(tfTunnid); add(tfMinutid); paigutaAeg(); new Thread(this).start(); } void paigutaAeg(){ Calendar aeg=new GregorianCalendar(); tfTunnid.setText(String.valueOf(aeg.get(Calendar.HOUR))); tfMinutid.setText(String.valueOf(aeg.get(Calendar.MINUTE))); } public void paint(Graphics g){ double nurk; int rkx=getWidth()/2; //pool akna laiusest int rky=getHeight()/2; int r=Math.min(getWidth(), getHeight())/3; double nurgavahe=6.28/12; for(int tunninr=0; tunninr<12; tunninr++){ nurk=(3.14/2)-tunninr*nurgavahe; int tunnix=rkx+(int)(r*Math.cos(nurk)); int tunniy=rky-(int)(r*Math.sin(nurk)); int r2=r*4/5; int tunnix2=rkx+(int)(r2*Math.cos(nurk)); int tunniy2=rky-(int)(r2*Math.sin(nurk)); int r3=r*5/4; int tunnix3=rkx+(int)(r3*Math.cos(nurk))-5; int tunniy3=rky-(int)(r3*Math.sin(nurk))+5; g.drawLine(tunnix2, tunniy2, tunnix, tunniy); g.drawString(String.valueOf(tunninr), tunnix3, tunniy3); } g.drawOval(rkx-r, rky-r, 2*r, 2*r); nurk=(3.14/2)-(tund+minut/60.0)*nurgavahe; int r4=r*3/5; //tunniosuti pikkus int tunnix4=rkx+(int)(r4*Math.cos(nurk)); int tunniy4=rky-(int)(r4*Math.sin(nurk)); g.drawLine(rkx, rky, tunnix4, tunniy4); nurgavahe=6.28/60; nurk=(3.14/2)-minut*nurgavahe; int r5=r*4/5; //tunniosuti pikkus int tunnix5=rkx+(int)(r5*Math.cos(nurk)); int tunniy5=rky-(int)(r5*Math.sin(nurk)); g.drawLine(rkx, rky, tunnix5, tunniy5); } public void run(){ while(true){ paigutaAeg(); tund=Integer.parseInt(tfTunnid.getText()); minut=Integer.parseInt(tfMinutid.getText()); repaint(); try{Thread.sleep(1000);}catch(Exception e){} } } public static void main(String argumendid[]){ Frame f=new Frame("Joonistus"); f.add(new Kell2()); f.setSize(300, 200); f.setVisible(true); } }