import java.awt.*; import java.awt.event.*; import java.util.*; import java.applet.Applet; public class Kell2 extends Applet implements ActionListener{ int keskx, kesky; int ringiraadius; Calendar kalender; static final long serialVersionUID=1; public Kell2(){ new javax.swing.Timer(1000, this).start(); } public void paint(Graphics g){ keskx=getWidth()/2; kesky=getHeight()/2; kalender=new GregorianCalendar(); int tunnid=kalender.get(Calendar.HOUR); int minutid=kalender.get(Calendar.MINUTE); //ringiraadius=Math.min(getWidth(), getHeight())/3; ringiraadius=100; double numbriraadius=ringiraadius*0.8; g.drawOval(keskx-ringiraadius, kesky-ringiraadius, ringiraadius*2, ringiraadius*2); for(int tunninr=1; tunninr<=12; tunninr++){ double nurk=Math.toRadians(90-tunninr*30); double dy=Math.sin(nurk)*numbriraadius; double dx=Math.sqrt(dy*dy+numbriraadius*numbriraadius- 2*dy*numbriraadius*Math.cos(3.14/2-nurk)); if(tunninr>6){ dx=-dx; } g.drawString(String.valueOf(tunninr), keskx+(int)dx-3, kesky-(int)dy+3); double tnurk=Math.toRadians(90-(tunnid+(minutid/60.0))*30); double traadius=numbriraadius*0.7; double tdy=Math.sin(tnurk)*traadius; double tdx=Math.sqrt(tdy*tdy+traadius*traadius- 2*tdy*traadius*Math.cos(3.14/2-tnurk)); if(tunnid>6){tdx=-tdx;} g.drawLine(keskx, kesky, keskx+(int)tdx, kesky-(int)tdy); //Lisage ka minutiosuti double mnurk=Math.toRadians(90-minutid*6); double mdy=Math.sin(mnurk)*numbriraadius; double mdx=Math.sqrt(mdy*mdy+numbriraadius*numbriraadius- 2*mdy*numbriraadius*Math.cos(3.14/2-mnurk)); if(minutid>30){mdx=-mdx;} g.drawLine(keskx, kesky, keskx+(int)mdx, kesky-(int)mdy); } } public void actionPerformed(ActionEvent e){ repaint(); } public static void main(String[] arg){ Frame f=new Frame("Kell"); f.add(new Kell2()); f.setSize(400, 400); f.setVisible(true); f.addWindowListener( new WindowAdapter(){ public void windowClosing(WindowEvent e){ System.exit(0); } } ); } }