import java.awt.*; import java.awt.event.*; import java.applet.Applet; import java.util.*; public class Kell1 extends Applet{ int keskx, kesky, raadius; int kellatund; double[] leiaOtspunkt(double nurk, double raadius){ double[] vastus=new double[2]; vastus[0] = keskx+raadius*Math.cos(nurk-Math.PI/2); vastus[1] = kesky+raadius*Math.sin(nurk-Math.PI/2); return vastus; } public void paint(Graphics g){ keskx=getWidth()/2; kesky=getHeight()/2; Calendar c=new GregorianCalendar(); kellatund=c.get(Calendar.HOUR); int kellaminut=c.get(Calendar.MINUTE); int kellasekund=c.get(Calendar.SECOND); raadius=Math.min(getWidth()/2, getHeight()/2); double numbriraadius=raadius*0.8; double tunninurk=Math.PI/6; double minutinurk=Math.PI/30; double[] t=leiaOtspunkt(kellatund*tunninurk, raadius*0.5); double[] m=leiaOtspunkt(kellaminut*minutinurk, raadius*0.7); double[] s=leiaOtspunkt(kellasekund*minutinurk, raadius*0.9); g.drawLine(keskx, kesky, (int)t[0], (int)t[1]); g.drawLine(keskx, kesky, (int)m[0], (int)m[1]); g.drawLine(keskx, kesky, (int)s[0], (int)s[1]); for(int tund=1; tund<=12; tund++){ double[] n=leiaOtspunkt(tund*tunninurk, numbriraadius); g.drawString(String.valueOf(tund), (int)n[0], (int)n[1]); } } public static void main(String[] arg){ Frame f=new Frame("Kell"); f.add(new Kell1()); f.setSize(300, 300); f.setVisible(true); } }