import java.awt.*; import java.awt.event.*; import java.applet.Applet; import java.util.*; public class Kell2 extends Applet implements Runnable{ int minutid = 0; // minutid int tunnid = 0; // tunnid int min = 0; // minuteid ööpäevas int minutidE = 0; // eelmine minut int tunnidE = 0; // eelmine tund TextField tunnidA=new TextField("17",2); // äratustund TextField minutidA=new TextField("25", 2); // äratusminut public Kell2(){ add (tunnidA); add (minutidA); new Thread(this).start(); } public void run (){ while (true) { Graphics g=getGraphics(); while((g=getGraphics())==null); g.setColor(Color.black); g.drawOval(200, 100, 400, 400); g.drawString("3", 580, 304); g.drawString("6", 397, 480); g.drawString("9", 220, 304); g.drawString("12", 392, 120); minutidE = minutid; tunnidE = tunnid; Calendar kalender=new GregorianCalendar(); minutid = kalender.get(Calendar.MINUTE); tunnid = kalender.get(Calendar.HOUR_OF_DAY); // minutid = 0; // tunnid = 9; min = minutid + tunnid*60; // arvutame nurgad double tNurkE = 2 * Math.PI * ((min-1) - 3 * 60)/ (12 * 60); double mNurkE = 2 * Math.PI * ((min-1) - 15)/ 60; double tNurk = 2 * Math.PI * (min - 3 * 60)/ (12 * 60); double mNurk = 2 * Math.PI * (min - 15)/ 60; // joonistame osutid g.setColor(Color.white); g.drawLine(400, 300, 400 + (int)(120 * Math.cos(tNurkE)), 300 + (int)(120 * Math.sin(tNurkE))); g.drawLine(400, 300, 400 + (int)(140 * Math.cos(mNurkE)), 300 + (int)(140 * Math.sin(mNurkE))); g.setColor(Color.black); g.drawLine(400, 300, 400 + (int)(120 * Math.cos(tNurk)), 300 + (int)(120 * Math.sin(tNurk))); g.drawLine(400, 300, 400 + (int)(140 * Math.cos(mNurk)), 300 + (int)(140 * Math.sin(mNurk))); // kirjutame kellaaja nurka g.setColor(Color.white); g.drawString(tunnidE + ":" + minutidE, 10, 30); g.setColor(Color.black); g.drawString(tunnid + ":" + minutid, 10, 30); try{ if ((Integer.parseInt(tunnidA.getText()) == tunnid ) && (Integer.parseInt(minutidA.getText()) == minutid)) { g.setColor(Color.red); g.drawString("Äratus!", 10, 60); g.setColor(Color.black); } }catch(Exception viga){} } } public static void main(String argumendid[]){ Frame f=new Frame(); f.add(new Kell2()); f.setSize(800, 600); f.setVisible(true); } }