1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
|
import java.awt.*;
import java.applet.*;
import java.math.*;
import java.util.*;
public class reloje extends Applet implements Runnable
{
int x=0,y=0;
int min = 0; //<<<<<<<<<<<<<<<<<<<<<<<<<<
int heure = 0; // pour la suite <<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Thread tr;
public void init()
{
}
public void paint(Graphics g)
{
g.drawOval(200,100 , 150, 150);
g.drawString("12",270,112);
g.drawString("9",202,180);
g.drawString("3",342,180);
g.drawString("6",272,247);
g.drawLine(275, 175,275 + (Integer)(Math.round(ext.abcisse(ext.anglemin
( min )))), 175-(Integer) //<<<<<<<<<<<<<<<<<<<<<<
(Math.round(ext.ordonné(ext.anglemin(min ))))); //<<<<<<<<<<<<<<<<<<<<<<<
//( ext.determinermin() )))), 175-(Integer)
// (Math.round(ext.ordonné(ext.anglemin( ext.determinermin() )))));
g.drawLine(275, 175,275+ (Integer)(Math.round(ext.abcisseh(ext.anglehour( heure )))), 175-(Integer)(Math.round(ext.ordonneh(ext.anglehour( heure )))));
}
public void start()
{
if (tr == null)
{
tr = new Thread(this, "reloje");
tr.start();
}
}
public void run()
{
Thread filActuel = Thread.currentThread(); // <<<<<<<<<<<<<<<<<<<<<<<
while (tr == filActuel) // <<<<<<<<<<<<<<<<<<<<<<<<<<<
{
// ****** Pour obtenir l'heure ******
GregorianCalendar madate = new GregorianCalendar(); //<<<<<<<<<<<<<<<<<<<<<<<<<<<
heure = madate.get(Calendar.HOUR);
min = madate.get(Calendar.MINUTE);
repaint();
try
{
Thread.sleep(1000); // 1 minute c'est trop, 1 seconde c'est bon
}
catch (InterruptedException e)
{
}
}
}
}
class ext
{
int x , y ;
static final float PI=3.141f ;
public static float anglemin(int min)
{
int minu=0 ;
minu = min ;
float alfa=0 ;
if(minu <15){alfa = (PI/2-minu*PI/30) ;
}
else if (15 <= minu & minu< 30){alfa= (15- minu)*PI/30;
}
else if (30<= minu & minu < 45){alfa=3*PI/2-(minu - 30)*PI/30;
}
else if (45<= minu & minu <60){alfa= PI-(minu-45)*PI/30;
}
return alfa ;
}
public static float abcisse(float alfa){float a=0 ;a= (float) Math.cos(alfa)*70;
return a;
}
public static float ordonné(float alfa){float b =0;b = (float) Math.sin(alfa)*70;
return b ;}
public static float anglehour(int hour){
int ho= hour ;
GregorianCalendar madate = new GregorianCalendar();
float alfa=0 ;
int plusdangle=madate.get(Calendar.MINUTE)/12 ;
if(ho <3){
alfa = (PI/2-ho*PI/6)-plusdangle*PI/30 ;}
else if (3 <= ho & ho< 6){
alfa= (3- ho)*PI/6-plusdangle*PI/30 ;}
else if (6<= ho & ho < 9){
alfa=3*PI/2-(ho - 6)*PI/6-plusdangle*PI/30 ; }
else if (9<= ho & ho <12){
alfa= PI-(ho-9)*PI/6-plusdangle*PI/30 ;
}
return alfa ;
}
public static float abcisseh(float alfa){
float a=0 ;
a= (float) Math.cos(alfa)*58;
return a;
}
public static float ordonneh(float alfa){
float b =0;
b = (float) Math.sin(alfa)*58;
return b ;
}
} |
Partager