Subversion Repositories wimsdev

Rev

Blame | Last modification | View Log | RSS feed

  1. /*
  2.  
  3.     jm.evers 2/2010
  4.     No copyrights. All amateur scriblings.
  5.     Example usage:
  6. <html>
  7.  <body>
  8.     <script type="text/javascript">
  9.  
  10.         function speakTime(){
  11.             var speaktime = document.getElementById('WClock').speakTime();
  12.             document.getElementById('showtime').innerHTML='<hr><font color=red><b>'+speaktime+'</b></font>' ;}
  13.  
  14.         function ReadThis(){
  15.             var reply = document.getElementById('WClock').readApplet();
  16.             document.getElementById('showtime').innerHTML='<hr>first value is pupils\'s timeanswer<br>second value is initial time<br><font color=red><b>'+reply+'</b></font><hr>';
  17.         }
  18.        
  19.         function increase(t,a){
  20.             if(t == 0 ){var reply = document.getElementById('WClock').setApplet("H",a);}
  21.             else
  22.             if(t == 1 ){var reply = document.getElementById('WClock').setApplet("M",a);}
  23.             else
  24.             if(t == 2 ){var reply = document.getElementById('WClock').setApplet("S",a);}
  25.         }
  26.         function reset(){                                                                                                                
  27.             document.getElementById('WClock').restart();
  28.         }
  29.        
  30.     </script>
  31.     <table>
  32.         <tr>
  33.             <td>
  34.                 <div id="showtime"></div>
  35.                 <br>
  36.                 <applet id="WClock" name="WClock" code="WClock.class" archive="WClock.jar" width="300" height="300">
  37.                     <param name = "language" value="nl"><!-- default english; optional nl,fr (fr is no good) -->
  38.                     <param name = "user_modify" value="yes"><!-- user sets time : default yes  0,no,1,yes -->
  39.                     <param name = "use_system_time" value="yes"><!-- optional 1,yes,0,no : overrules other time parameters -->
  40.                     <param name = "use_seconds" value="yes"><!-- optional 1,yes,0,no -->
  41.                     <param name = "hours" value="12"><!-- if not set random hour -->
  42.                     <param name = "minutes" value="15"><!-- if not set: will use random minutes -->
  43.                     <param name = "seconds" value="43"><!-- if not set: will random seconds -->
  44.                     <param name = "background_color" value="#dafff6"><!-- optional  -->
  45.                     <param name = "hour_hand_color" value="#007cff"><!-- optional  -->
  46.                     <param name = "minutes_hand_color" value="#00c3ff"><!-- optional  -->
  47.                     <param name = "seconds_hand_color" value="#ff1300"><!-- optional  -->
  48.                     <param name = "numbers_color" value="#ff1300"><!-- optional  -->
  49.                     <param name = "15_min_color" value="#0044ff"><!-- optional  -->
  50.                     <param name = "5_min_color" value="#0044ff"><!-- optional  -->
  51.                     <param name = "1_min_color" value="#0044ff"><!-- optional  -->
  52.                     <param name = "alpha" value="100"><!-- optional  -->
  53.                     <param name = "15_min_type" value="numbers"><!-- optional : diamonds ,lines ,numbers  or 0,1,2-->
  54.                     <param name = "5_min_type" value="0"><!--  optional : diamonds ,lines ,numbers  or 0,1,2-->
  55.                     <param name = "1_min_type" value="lines"><!--  optional : diamonds ,lines ,numbers or 0,1,2-->
  56.                 </applet>
  57.                 <br>
  58.                 <input type="button" name="read_time" value="read time" onclick="javascript:ReadThis();">
  59.                 <br>
  60.                 <input type="button" name="speak time" value="speak time" onclick="javascript:speakTime();">
  61.                 <br>
  62.                 <input type="button" name="hours +" value="hours +" onclick="javascript:increase(0,1);">
  63.                 <input type="button" name="min +" value="min +" onclick="javascript:increase(1,1);">
  64.                 <input type="button" name="sec +" value="sec +" onclick="javascript:increase(2,1);">
  65.                 <br>
  66.                 <input type="button" name="hours &minus;" value="hours &minus;" onclick="javascript:increase(0,-1);">
  67.                 <input type="button" name="min &minus;" value="min &minus;" onclick="javascript:increase(1,-1);">
  68.                 <input type="button" name="sec &minus;" value="sec &minus;" onclick="javascript:increase(2,-1);">
  69.             </td>
  70.             <td>
  71.                 Mouse &amp; Key Controls [if param "user_modify = yes"]
  72.                 <ul>
  73.                     <li>seconds
  74.                         <ul>
  75.                             <li>s : +1 sec</li>
  76.                             <li>F3 : +1 sec</li>
  77.                             <li>r : -1 sec</li>
  78.                             <li>F4 : -1 sec</li>
  79.                         </ul>
  80.                     </li>
  81.                     <li>minutes
  82.                         <ul>
  83.                             <li>F1 : +1 min</li>
  84.                             <li>m : +1 min</li>
  85.                             <li>cursor -&gt; : +1 min</li>
  86.                             <li>cursor &lt;- : -1 min</li>
  87.                             <li>backspace : -1 min</li>
  88.                             <li>pageup : -15 min</li>
  89.                             <li>pagedown : +15 min</li>
  90.                             <li>space : +1 min</li>
  91.                             <li>left mousebutton : +1 min</li>
  92.                             <li>right mousebutton : -1 min</li>
  93.                             <li>scrollwheel : +/- 1 min</li>
  94.                             <li>mouse drag : +1 min</li>
  95.                         </ul>
  96.                     </li>
  97.                     <li>hours
  98.                         <ul>
  99.                             <li>F2 : +1 hour</li>
  100.                             <li>h : +1 hour</li>
  101.                             <li>F5 : -1 hour</li>
  102.                             <li>- : -1 hour</li>
  103.                             <li>delete : -1 hour</li>
  104.                             <li>1,2,3,4,5,6,7,8,9 : +1,2,3,4,5,6,7,8,9 hours</li>
  105.                         </ul>
  106.                     </li>
  107.                 </ul>
  108.             </td>
  109.         </tr>
  110.     </table>
  111.  </body>
  112. </html>
  113.  
  114. */
  115.  
  116. import java.lang.*;
  117. //import javax.imageio.ImageIO;                                                                                                              
  118. import java.awt.image.BufferedImage;
  119. import javax.swing.*;
  120. import java.applet.Applet;
  121. import java.awt.*;
  122. import java.util.*;
  123. import java.io.*;
  124. import java.awt.Color;
  125. import java.awt.event.*;
  126.  
  127. public class WClock extends Applet implements  KeyListener, MouseListener, MouseMotionListener, MouseWheelListener{
  128.  
  129.     public Color hour_hand_color,min_hand_color,sec_hand_color,number_color;
  130.     public Color horloge_color,backgroundcolor,ftmin_color,fimin_color,onemin_color;
  131.     int xsize,ysize;
  132.     double center_x,center_y;
  133.     Graphics2D backg;                                                                                                                      
  134.     BufferedImage bg;
  135.     Graphics2D horloge;                                                                                                                      
  136.     BufferedImage ggb;
  137.     double seconds;
  138.     int fifteenminute;
  139.     int fiveminute;
  140.     int oneminute;
  141.     static int diamonds=0;
  142.     static int lines=1;
  143.     static int numbers=2;
  144.     String helptxt;
  145.     int H_in=-1;
  146.     int M_in=-1;
  147.     int S_in=-1;
  148.     int alpha=-1;
  149.     boolean use_seconds;
  150.     boolean user_modify;
  151.     public String[] telwoorden = {"zero","one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","thirteen",
  152.     "fourteen","fifteen","sixteen","seventeen","eightteen","nineteen","twenty","twentyone","twentytwo","twentythree",
  153.     "twentyfour","twentyfive","twentysix","twentyseven","twentyeight","twentynine","thirty","thirtyone","thirtytwo",
  154.     "thirtythree","thirtyfour","thirtyfive","thirtysix","thirtyseven","thirtyeight","thirtynine","fourty","fourtyone",
  155.     "fourtytwo","fourtythree","fourtyfour","fourtyfive","fourtysix","fourtyseven","fourtyeight","fourtynine","fifty"
  156.     };
  157.     public String[] mtext = {"It is exactly speak_hours O'clock","It is a quarter past speak_hours",
  158.     "It is speak_minutes minutes past speak_hours"," It is exactly half past speak_hours",
  159.     "It is speak_minutes minutes before half past speak_hours","It is a quarter to speak_hours",
  160.     "It is speak_minutes minutes over half past speak_hours","It is speak_minutes minutes to speak_hours",
  161.     "and speak_seconds seconds"};
  162.     public String [] single_multi_sec = {"second","seconds"};
  163.     public String[] single_multi_min = {"minute","minutes"};
  164.    
  165.     public void init(){
  166.         helptxt="minuten=F1,M,cursor,muis,spatiebalk  uren=F2,H  seconden=F3,S ";
  167.         String param = getParameter("language");
  168.         if(param != null && param.length() == 2){
  169.             if(param.equalsIgnoreCase("nl")){
  170.                 telwoorden = new String[] {"nul","een","twee","drie","vier","vijf","zes","zeven","acht","negen","tien",
  171.                 "elf","twaalf","dertien","veertien","vijftien","zestien","zeventien","achttien","negentien",
  172.                 "twintig","eenentwintig","tweeentwintig","drieentwintig","vierentwintig","vijfentwintig",
  173.                 "zesentwintig ","zevenentwintig"," achtentwintig"," negenentwintig"," dertig",
  174.                 "eenendertig","tweeendertig","drieendertig","vierendertig","vijfendertig","zesendertig","zevenendertig",
  175.                 "achtendertig","negenendertig","veertig","eennenveertig","tweeenveertig","drieenveertig","vierenveertig",
  176.                 "vijfenveertig","zesenveertig","zevenenveertig","achtenveertig","negenenveertig","vijftig"};
  177.        
  178.                 mtext = new String[] {"Het is precies speak_hours uur","Het is kwart over speak_hours",
  179.                 "Het is speak_minutes minuten over speak_hours","Het is half speak_hours",
  180.                 "Het is speak_minutes minuten voor half speak_hours","Het is kwart voor speak_hours",
  181.                 "Het is speak_minutes minuten over half speak_hours","Het is speak_minutes minuten voor speak_hours",
  182.                 "en speak_seconds seconden"};
  183.                 single_multi_sec = new String[] {"seconde","seconden"};
  184.                 single_multi_min = new String[] {"minuut","minuten"};
  185.             }
  186.             else
  187.             {
  188.                 System.out.println("Sorry, no support for other languages than English and Dutch");
  189.             }
  190.         }
  191.        
  192.         param = getParameter("alpha");
  193.         if(param != null && param.length() !=0){
  194.             try{alpha = Integer.parseInt(param);}catch(Exception e){System.out.println("Can not set alpha color to"+param);}
  195.         }
  196.         param = getParameter("user_modify");
  197.         if(param != null && param.length() !=0){
  198.             if(param.equals("0") || param.equalsIgnoreCase("no")){user_modify = false;}else{user_modify = true;}
  199.         }
  200.         horloge_color = new Color(255,255,255,0); // do not change : needs to be transparent ... image drawn over number&hand image
  201.         hour_hand_color = new Color(255,0,0,120);
  202.         min_hand_color = new Color(0,255,0,120);
  203.         sec_hand_color = new Color(0,0,255,120);
  204.         number_color = new Color(0,50,255,120);
  205.         backgroundcolor = new Color(255,255,255);
  206.         ftmin_color = new Color(0,10,255,160);
  207.         fimin_color = new Color(0,10,255,160);
  208.         onemin_color = new Color(0,10,255,160);
  209.         // reading params, reverting to default if not set.
  210.         backgroundcolor = colorDecodeParam("background_color",backgroundcolor);
  211.         hour_hand_color = colorDecodeParam("hour_hand_color",hour_hand_color);
  212.         min_hand_color = colorDecodeParam("minutes_hand_color",min_hand_color);
  213.         sec_hand_color = colorDecodeParam("seconds_hand_color",sec_hand_color);
  214.         number_color = colorDecodeParam("numbers_color",number_color);
  215.         ftmin_color = colorDecodeParam("15_min_color",ftmin_color);
  216.         fimin_color = colorDecodeParam("5_min_color",fimin_color);
  217.         onemin_color = colorDecodeParam("1_min_color",onemin_color);
  218.         if(alpha>-1){
  219.             hour_hand_color = MakeTransparent(hour_hand_color,alpha);
  220.             min_hand_color = MakeTransparent(min_hand_color,alpha);
  221.             sec_hand_color = MakeTransparent(sec_hand_color,alpha);
  222.         }
  223.         fifteenminute = setHorlogeType("15_min_type",2);
  224.         fiveminute = setHorlogeType("5_min_type",0);
  225.         oneminute = setHorlogeType("1_min_type",1);
  226.         Dimension appletSize = this.getSize();                                                                                            
  227.         ysize = appletSize.height;xsize = appletSize.width;    
  228.         center_x=(double) (xsize/2);center_y=(double) (ysize/2);
  229.         bg = new BufferedImage(xsize,ysize, BufferedImage.TYPE_INT_ARGB);                                                        
  230.         backg = (Graphics2D) bg.getGraphics();
  231.         ggb = new BufferedImage(xsize,ysize, BufferedImage.TYPE_INT_ARGB);                                                        
  232.         horloge = (Graphics2D) ggb.getGraphics();
  233.         if(user_modify){
  234.             addMouseListener(this);
  235.             addMouseMotionListener(this);
  236.             addMouseWheelListener(this);
  237.             addKeyListener(this);
  238.         }
  239.         prepaint();
  240.         getTime();
  241.         setTime(0);
  242.         //requestFocus();
  243.     }
  244.        
  245.      
  246.    public String speakTime(){
  247.         int H = (int) ((seconds/3600) % 12);
  248.         int M = (int) ((seconds/60) % 60);
  249.         int S = (int) ((seconds) % 60);
  250.         //System.out.println("H="+H+" M="+M+" S="+S);
  251.  
  252.         String text_m="";
  253.         String enzoveelseconden="";
  254.         String speak_hours="";
  255.         String speak_minutes="";
  256.         if( M > 15 ){ H++;}
  257.         if( H == 0 || H > 12){ H = 12;}
  258.         speak_hours=telwoorden[H];
  259.        
  260.         if( M <= 15 ){
  261.             if(M ==  0){
  262.                 text_m=mtext[0].replace("speak_hours",speak_hours);
  263.             }
  264.             else
  265.             {
  266.                 if(M == 15){
  267.                     text_m=mtext[1].replace("speak_hours",speak_hours);
  268.                 }
  269.                 else
  270.                 {      
  271.                     speak_minutes=telwoorden[M];
  272.                     text_m=mtext[2].replace("speak_minutes",speak_minutes);
  273.                     text_m=text_m.replace("speak_hours",speak_hours);
  274.                 }
  275.             }
  276.         }
  277.         else
  278.         {
  279.             if(M <= 30){
  280.                 if( M == 30){
  281.                     text_m=mtext[3].replace("speak_hours",speak_hours);
  282.                 }
  283.                 else
  284.                 {
  285.                     speak_minutes=telwoorden[30 - M];
  286.                     text_m=mtext[4].replace("speak_minutes",speak_minutes);
  287.                     text_m=text_m.replace("speak_hours",speak_hours);
  288.                 }
  289.             }
  290.             else
  291.             {
  292.                 if( M <= 45 ){
  293.                     if(M == 45){
  294.                         text_m=mtext[5].replace("speak_hours",speak_hours);
  295.                     }
  296.                     else
  297.                     {
  298.                         speak_minutes=telwoorden[M-30];
  299.                         text_m=mtext[6].replace("speak_minutes",speak_minutes);
  300.                         text_m=text_m.replace("speak_hours",speak_hours);
  301.                     }
  302.                 }
  303.                 else
  304.                 {
  305.                     if( M <= 60 ){
  306.                         speak_minutes=telwoorden[60-M];
  307.                         text_m=mtext[7].replace("speak_minutes",speak_minutes);
  308.                         text_m=text_m.replace("speak_hours",speak_hours);
  309.                     }
  310.                 }
  311.             }
  312.         }
  313.         if( M == 1 || M == 29 || M == 31 || M == 59  ){text_m = text_m.replace(single_multi_min[1],single_multi_min[0]);}
  314.         if( S != 0 && use_seconds){
  315.             enzoveelseconden=mtext[8].replace("speak_seconds",""+S+"");
  316.             if( S == 1 ){
  317.                 enzoveelseconden=enzoveelseconden.replace(single_multi_sec[1],single_multi_sec[0]);
  318.             }
  319.         }
  320.         return text_m+"..."+enzoveelseconden;
  321.     }
  322.    
  323.  
  324.    public void setApplet(String type , int incr){
  325.         if(type.equals("H")){setTime((double)(incr*3600));}
  326.         else
  327.         if(type.equals("M")){setTime((double)(incr*60));}
  328.         else
  329.         if(type.equals("S") && use_seconds ){setTime((double)(incr*1));}
  330.     }
  331.    
  332.     public int setHorlogeType(String param, int d){
  333.         String c = getParameter(param);
  334.         if(c != null && c.length() !=0){
  335.             try{
  336.                 if(c.equalsIgnoreCase("diamonds") || c.equals("0") ){return diamonds;}
  337.                 else
  338.                 if(c.equalsIgnoreCase("lines") || c.equals("1") ){return lines;}
  339.                 else
  340.                 if(c.equalsIgnoreCase("numbers") || c.equals("2") ){return numbers;}
  341.             }catch(Exception e){System.out.println("Can\'t handle "+param+" = "+c);}
  342.         }
  343.         return d;
  344.     }
  345.    
  346.     public Color MakeTransparent(Color c, int a){
  347.         return new Color(c.getRed(),c.getGreen(),c.getBlue(),a);
  348.     }
  349.  
  350.     public Color colorDecodeParam(String param, Color c0){
  351.         String c = getParameter(param);
  352.         if( c != null && c.length() !=0){
  353.             try{ c0 = Color.decode(c);}catch(Exception e){System.out.println("don\'t know color "+c+" ... setting to default");}
  354.         }    
  355.         return c0;
  356.     }
  357.    
  358.     public void getTime(){
  359.         String param;
  360.         param = getParameter("use_seconds");
  361.         if(param != null && param.length() !=0){
  362.             if(param.equals("1") || param.equalsIgnoreCase("yes")){use_seconds = true;}else{use_seconds = false;}
  363.         }
  364.  
  365.         param = getParameter("use_system_time");
  366.         if(param != null && param.length() !=0){
  367.             if(param.equals("1") || param.equalsIgnoreCase("yes")){
  368.                 Date date = new Date();
  369.                 if(use_seconds){ S_in = date.getSeconds(); }else{ S_in = 0; }
  370.                 M_in = date.getMinutes();
  371.                 H_in   = date.getHours();
  372.                 seconds  = (double) (3600*H_in + 60*M_in + S_in);
  373.                 return;
  374.             }
  375.         }
  376.         param = getParameter("hours");
  377.         if(param != null && param.length() !=0){
  378.             H_in = Integer.parseInt(param);
  379.         }else{H_in =(int) (Math.round(12*(Math.random())));}
  380.            
  381.         param = getParameter("minutes");
  382.         if(param != null && param.length() !=0){
  383.             M_in = Integer.parseInt(param);
  384.         }else{M_in =(int) (Math.round(60*(Math.random())));}
  385.         if(use_seconds){
  386.             param = getParameter("seconds");
  387.             if(param != null && param.length() !=0){ S_in = Integer.parseInt(param); }else{ S_in = (int) (Math.round(60*(Math.random())));}
  388.         }else{ S_in = 0;}
  389.         seconds  = (double) (3600*H_in + 60*M_in + S_in);
  390.     }
  391.  
  392.     public String readApplet(){
  393.         int H = (int) ((seconds/3600) % 12);
  394.         int M = (int) ((seconds/60) % 60);
  395.         int S = (int) ((seconds) % 60);
  396.         // user set time , initial time
  397.         return H+":"+M+":"+S+","+H_in+":"+M_in+":"+S_in;
  398.     }
  399.        
  400.     Polygon getDiamond(int seconds,double angle,double forwards,double backwards,double sideways){
  401.         Polygon polygon=new Polygon();
  402.         double leftsin=Math.sin((seconds-angle)*Math.PI/30);
  403.         double leftcos=Math.cos((seconds-angle)*Math.PI/30);
  404.         double middlesin=Math.sin(seconds*Math.PI/30);
  405.         double middlecos=Math.cos(seconds*Math.PI/30);
  406.         double rightsin=Math.sin((seconds+angle)*Math.PI/30);
  407.         double rightcos=Math.cos((seconds+angle)*Math.PI/30);
  408.         polygon.addPoint((int) (center_x + center_x*forwards*middlesin)  , (int) (center_y - center_y*forwards*middlecos));
  409.         polygon.addPoint((int) (center_x + center_x*sideways*leftsin)    , (int) (center_y - center_y*sideways*leftcos));
  410.         polygon.addPoint((int) (center_x + center_x*backwards*middlesin) , (int) (center_y - center_y*backwards*middlecos));
  411.         polygon.addPoint((int) (center_x + center_x*sideways*rightsin)   , (int) (center_y - center_y*sideways*rightcos));
  412.         return polygon;
  413.     }
  414.  
  415.     void drawNumber(Graphics g,int seconds,int number,double size,double radius){
  416.         Font font=new Font("TimesRoman",Font.PLAIN,(int)(Math.min(center_x,center_y)*size));
  417.         FontMetrics fontmetrics=getFontMetrics(font);
  418.         String string=(new Integer(number)).toString();
  419.         int x=(int) (center_x + center_x*radius*Math.sin(seconds*Math.PI/30));
  420.         int y=(int) (center_y - center_y*radius*Math.cos(seconds*Math.PI/30));
  421.         x-=fontmetrics.stringWidth(string)/2;
  422.         y+=fontmetrics.getAscent()/2;
  423.         g.setColor(number_color);
  424.         g.setFont(font);
  425.         g.drawString(string,x,y);
  426.     }
  427.        
  428.     public void prepaint(){
  429.         backg.setColor(horloge_color);
  430.         backg.fillOval(0,0,xsize,ysize);
  431.         for(int n=0;n<60;n++){
  432.             if(n%15==0&&fifteenminute==diamonds){
  433.                 backg.setColor(ftmin_color);
  434.                 backg.fillPolygon(getDiamond(n,.4,1,.8,.9));
  435.             }
  436.             else if(n%15==0&&fifteenminute==numbers){
  437.                 backg.setColor(ftmin_color);
  438.                 drawNumber(backg,n,n==0?12:n/5,.17,.9);
  439.             }
  440.             else if(n%15==0&&fifteenminute==lines){
  441.                 backg.setColor(ftmin_color);
  442.                 drawNumber(backg,n,n==0?12:n/5,.17,.9);
  443.             }
  444.             else if(n%5==0&&fiveminute==diamonds){
  445.                 backg.setColor(fimin_color);
  446.                 backg.fillPolygon(getDiamond(n,.2,.95,.85,.9));
  447.             }
  448.             else if(n%5==0&&fiveminute==numbers){
  449.                 backg.setColor(fimin_color);
  450.                 drawNumber(backg,n,n==0?12:n/5,.1,.9);
  451.             }
  452.             else if(n%5==0&&fiveminute==lines){
  453.                 backg.setColor(fimin_color);
  454.                 drawNumber(backg,n,n==0?12:n/5,.1,.9);
  455.             }
  456.             else if(oneminute==lines){
  457.                 double sin=Math.sin(n*Math.PI/30);
  458.                 double cos=Math.cos(n*Math.PI/30);
  459.                 backg.setColor(onemin_color);
  460.                 backg.drawLine((int) (center_x + center_x*.88*sin) ,(int) (center_y - center_y*.88*cos) ,(int) (center_x + center_x*.92*sin),(int) (center_y - center_y*.92*cos));
  461.             }
  462.             else if(oneminute==numbers){
  463.                 backg.setColor(onemin_color);
  464.                 drawNumber(backg,n,n,.05,.9);
  465.             }
  466.         }
  467.     }
  468.  
  469.     public void prepainthorloge(){
  470.         horloge.setColor(backgroundcolor);
  471.         horloge.fillRect(0,0,xsize,ysize);
  472.         if(use_seconds){
  473.             Polygon S = getWijzer((seconds)%60,0.9,0.02,0.02,30);
  474.             drawWijzer(sec_hand_color,horloge,S);
  475.         }
  476.         Polygon M = getWijzer((seconds/60)%60,0.9,0.04,0.04,30);
  477.         Polygon H = getWijzer(5*((seconds/3600)%12),0.6,0.05,0.05,30);
  478.         drawWijzer(min_hand_color,horloge,M);
  479.         drawWijzer(hour_hand_color,horloge,H);
  480.         drawCenter(Color.black,horloge,(int)(0.05*xsize));
  481.     }
  482.  
  483.     public void paintComponent(Graphics g){
  484.         Graphics2D g2 = (Graphics2D) g;
  485.         g2.drawImage(ggb,0,0,this);
  486.         g2.drawImage(bg,0,0,this);
  487.     }
  488.        
  489.     public void paint(Graphics g){
  490.         update(g);
  491.     }
  492.  
  493.     public void update(Graphics g){
  494.         prepainthorloge();                                                                                                        
  495.         paintComponent(g);                                                                                                                
  496.     }
  497.  
  498.     Polygon getWijzer(double time,double forwards,double backwards,double sideways,int div){
  499.         Polygon polygon=new Polygon();
  500.         double sin = Math.sin(time*Math.PI/div);
  501.         double cos = Math.cos(time*Math.PI/div);
  502.         polygon.addPoint((int) (center_x + center_x*forwards*sin)  ,(int) (center_y - center_y*forwards*cos));
  503.         polygon.addPoint((int) (center_x + center_x*sideways*cos)  ,(int) (center_y + center_y*sideways*sin));
  504.         polygon.addPoint((int) (center_x - center_x*backwards*sin) ,(int) (center_y + center_y*backwards*cos));
  505.         polygon.addPoint((int) (center_x - center_x*sideways*cos)  ,(int) (center_y - center_y*sideways*sin));
  506.         return polygon;
  507.     }
  508.        
  509.     void drawCenter(Color c,Graphics g,int w){
  510.             g.setColor(c);
  511.             g.fillOval((int) (center_x-w/2),(int) (center_y-w/2),w,w);
  512.     }
  513.  
  514.     void drawWijzer(Color c,Graphics g,Polygon polygon){
  515.         g.setColor(c);
  516.         g.fillPolygon(polygon);
  517.         g.drawLine(polygon.xpoints[0],polygon.ypoints[0],polygon.xpoints[2],polygon.ypoints[2]);
  518.         g.drawLine(polygon.xpoints[1],polygon.ypoints[1],polygon.xpoints[2],polygon.ypoints[2]);
  519.         g.drawLine(polygon.xpoints[3],polygon.ypoints[3],polygon.xpoints[2],polygon.ypoints[2]);
  520.         g.drawLine(polygon.xpoints[0],polygon.ypoints[0],polygon.xpoints[1],polygon.ypoints[1]);
  521.         g.drawLine(polygon.xpoints[0],polygon.ypoints[0],polygon.xpoints[3],polygon.ypoints[3]);
  522.     }
  523.  
  524.  
  525.     public void run(){}
  526.     public void start(){}
  527.     public void stop(){}
  528.     public void restart(){getTime();repaint();}
  529.  
  530.     public void mouseDragged(MouseEvent evt){setTime(60);}
  531.     public void mouseMoved(MouseEvent evt){}
  532.     public void mousePressed(MouseEvent evt){}
  533.     public void mouseReleased(MouseEvent evt){}
  534.     public void mouseEntered(MouseEvent evt){}
  535.     public void mouseExited(MouseEvent evt){}
  536.     public void mouseClicked(MouseEvent evt){if(evt.getButton() == MouseEvent.BUTTON1){setTime(60);}else{setTime(-60);}}
  537.     public void mouseWheelMoved(MouseWheelEvent evt){setTime(-60*(evt.getWheelRotation()));}
  538.     public void keyPressed(java.awt.event.KeyEvent evt){
  539.         int key=evt.getKeyCode();
  540.         if(key == 37 || key == 8 ){setTime(59*60);}// left arrow
  541.         else
  542.         if(key == 39 || key ==32 ){setTime(60);}// right arrow
  543.         else
  544.         if(key == 33){setTime(3*900);}//page down
  545.         else
  546.         if(key == 34){setTime(900);}//page up
  547.         else
  548.         if(key > 48 && key < 58){setTime(3600*(key-48));}//1,2,3,4,5,6,7,8,9   
  549.         else
  550.         if(use_seconds && (key == 83 || key == 114) ){setTime(1);}// s , F3
  551.         else
  552.         if(use_seconds && (key == 82 || key == 115) ){setTime(59);}// r , F4
  553.         else
  554.         if(key == 77 || key == 112 ){setTime(60);}// m , F1
  555.         else
  556.         if(key == 85 || key == 113 || key == 72){setTime(3600);}// u , h , F2
  557.         else
  558.         if(key == 116  || key == 127){setTime(11*3600);}// F5 ,del
  559.         //System.out.println(key);
  560.     }
  561.     public void keyTyped(KeyEvent evt){}                                                                                                                                                                                                                                              
  562.     public void keyReleased(KeyEvent evt){}
  563.  
  564.     public void setTime(double incr){
  565.         seconds = seconds + incr;
  566.         repaint();
  567.     }
  568.  
  569. }
  570.  
  571.  
  572.  
  573.