001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
039
040
041
042
043
044
045
046
047
048
049
050
051
052
053
054
055
056
057
058
059
060
061
062
063
064
065
066
067
068
069
070
071
072
073
074
075
076
077
078
079
080
081
082
083
084
085
086
087
088
089
090
091
092
093
094
095
096
097
098
099
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
/**********************************************************************************
 *                                                                                *
 *                         Digital clock Applet(Ver2)                             *
 *                            ( DigitalClock.java )                               *
 *                                                         Author : Seiichi Inoue *
 **********************************************************************************/

/********************** << Imported package class definition >> *******************/
import java.applet.Applet;      /* Applet packages                                */
import java.awt.*;              /* All of the Abstract Windowing Toolkit packages */
import java.util.Date;          /* Date packages                                  */

/************************** <<Oneself of class definition>> ***********************/
//    Class name      : DigitalClock1
//    Access control  : public( Access possibility even from which class )
//    Extends class   : Applet
//    Implements class: Runnable( Use of Thread is enabled )
public  class  DigitalClock1  extends Applet implements Runnable {

/************************* << Class attribute of definition >> ********************/
    Dimension    d;                           /* Display range                    */
    Thread       kicker=null;                 /* Thread(Initial value:suspension) */
    Image        offs;                        /* Off screen                       */
    Graphics     grf;                         /* Drawing range                    */
    Image        img;                         /* Background image                 */
    MediaTracker mt;                          /* MediaTracker                     */
    int          imgsw;                       /* Background image presence info   */
    String       param;                       /* Parameter reading                */
    Font         font;                        /* Clock letter font                */
    Color        color;                       /* Clock letter color               */
    int          ap_fontsize;                 /* AM/PM disply font information    */
    int          amx,amy,pmx,pmy;             /* AM/PM disply position information*/
    int          h;                           /* Hour information                 */
    String       sh,h10,h01;                  /* Hour display letter information  */
    int          h_fontsize;                  /* Hour display font information    */
    int          h10x,h10y,h01x,h01y;         /* Hour display position information*/
    int          m;                           /* Minute information               */
    String       sm,m10,m01;                  /* Minute display letter information*/
    int          m_fontsize;                  /* Minute display font information  */
    int          m10x,m10y,m01x,m01y;         /* Minute display position info     */
    int          s;                           /* Second information               */
    String       ss,s10,s01;                  /* Second display letter information*/
    int          s_fontsize;                  /* Second display font information  */
    int          s10x,s10y,s01x,s01y;         /* Second display position info     */
    int          am_pm;                       /* Morning/Afternoon information    */
    int          dot_fontsize;                /* Dot disply font information      */
    int          dotux,dotuy,dotdx,dotdy;     /* Dot disply position information  */

/***************** << Class of method (implementation procedure) >> ***************/
//
/******** Initialization (init) method *********/
    public void init() {
        d = size();                             /* Set display screen size        */
        offs = createImage(d.width,d.height);   /* Off scr area preparation       */
        grf  = offs.getGraphics();              /* Graphics object extraction     */

        param = getParameter("image");          /* Background image input reading */
        if ( param != null ) {                  /* Input parameter existence?     */
            mt = new MediaTracker(this);        /* MediaTracker instance          */
            img = getImage(getCodeBase(),param);/* Background image reading       */
            mt.addImage(img,0);                 /* Image load surveillance reg    */
            imgsw = 1;                          /* Background image existence info*/
        }
        else                                    /* No : no designated input       */
            imgsw = 0;                          /* No background image info       */

        param = getParameter("ap_fontsize");    /* AM/PM disply font size reading */
        ap_fontsize = (param != null)?          /* Input determination            */
            Integer.parseInt(param): 10;
        param = getParameter("h_fontsize");     /* Hour display font size reading */
        h_fontsize = (param != null)?           /* Input determination            */
            Integer.parseInt(param): 20;
        param = getParameter("m_fontsize");     /* Minute disp font size reading  */
        m_fontsize = (param != null)?           /* Input determination            */
            Integer.parseInt(param): 20;
        param = getParameter("s_fontsize");     /* Second disp font size reading  */
        s_fontsize = (param != null)?           /* Input determination            */
            Integer.parseInt(param): 20;
        param = getParameter("dot_fontsize");   /* Dot disply font size reading   */
        dot_fontsize = (param != null)?         /* Input determination            */
            Integer.parseInt(param): 40;

        param = getParameter("amx");            /* AM disply position (H)         */
        amx = (param != null)?                  /* Input determination            */
            Integer.parseInt(param): 0;
        param = getParameter("amy");            /* AM disply position (V)         */
        amy = (param != null)?                  /* Input determination            */
            Integer.parseInt(param): 10;
        param = getParameter("pmx");            /* PM disply position (H)         */
        pmx = (param != null)?                  /* Input determination            */
            Integer.parseInt(param): 0;
        param = getParameter("pmy");            /* PM disply position (V)         */
        pmy = (param != null)?                  /* Input determination            */
            Integer.parseInt(param): 20;

        param = getParameter("h10x");           /* Hour 10 places disp position(H)*/
        h10x = (param != null)?                 /* Input determination            */
            Integer.parseInt(param): 0;
        param = getParameter("h10y");           /* Hour 10 places disp position(V)*/
        h10y = (param != null)?                 /* Input determination            */
            Integer.parseInt(param): 20;
        param = getParameter("h01x");           /* Hour 1 place disp position(H)  */
        h01x = (param != null)?                 /* Input determination            */
            Integer.parseInt(param): 10;
        param = getParameter("h01y");           /* Hour 1 place disp position(V)  */
        h01y = (param != null)?                 /* Input determination            */
            Integer.parseInt(param): 20;

        param = getParameter("m10x");           /* Minute 10 places disp posi(H)  */
        m10x = (param != null)?                 /* Input determination            */
            Integer.parseInt(param): 30;
        param = getParameter("m10y");           /* Minute 10 places disp posi(V)  */
        m10y = (param != null)?                 /* Input determination            */
            Integer.parseInt(param): 20;
        param = getParameter("m01x");           /* Minute 1 place disp position(H)*/
        m01x = (param != null)?                 /* Input determination            */
            Integer.parseInt(param): 40;
        param = getParameter("m01y");           /* Minute 1 place disp position(V)*/
        m01y = (param != null)?                 /* Input determination            */
            Integer.parseInt(param): 20;

        param = getParameter("s10x");           /* Second 10 places disp posi(H)  */
        s10x = (param != null)?                 /* Input determination            */
            Integer.parseInt(param): 60;
        param = getParameter("s10y");           /* Second 10 places disp posi(V)  */
        s10y = (param != null)?                 /* Input determination            */
            Integer.parseInt(param): 20;
        param = getParameter("s01x");           /* Second 1 place disp position(H)*/
        s01x = (param != null)?                 /* Input determination            */
            Integer.parseInt(param): 70;
        param = getParameter("s01y");           /* Second 1 place disp position(V)*/
        s01y = (param != null)?                 /* Input determination            */
            Integer.parseInt(param): 20;

        param = getParameter("dotux");          /* Upper dot disply position(H)   */
        dotux = (param != null)?                /* Input determination            */
            Integer.parseInt(param): 40;
        param = getParameter("dotuy");          /* Upper dot disply position(V)   */
        dotuy = (param != null)?                /* Input determination            */
            Integer.parseInt(param): 5;
        param = getParameter("dotdx");          /* Lower dot disply position(H)   */
        dotdx = (param != null)?                /* Input determination            */
            Integer.parseInt(param): 40;
        param = getParameter("dotdy");          /* Lower dot disply position(V)   */
        dotdy = (param != null)?                /* Input determination            */
            Integer.parseInt(param): 15;


    }                                           /* End of initial method          */

/************ Start (start) method *************/
    public void start() {
        if ( kicker == null ) {                 /* Kicker is null? ( Suspension? )*/
            kicker = new Thread(this);          /* YES: kicker setting            */
            kicker.start();                     /* Setting of start               */
        }
        repaint();
    }                                           /* End of start method            */

/*********** Repeatedly (run) method ***********/
    public void run() {
        Thread.currentThread().setPriority(Thread.NORM_PRIORITY-3);
        if ( imgsw != 0 ) {                     /* It is designated an image?     */
            try {                               /* Interruption confirmation      */
                mt.waitForID(0);                /* Image load waiting             */
            } catch( InterruptedException e ) { /* Interruption processing        */
                System.out.println("Wait Error");
                return;
            }
        }

        while( kicker != null) {              /* Repeat until kicker becomes null */
            repaint();                          /* Drawing triggering             */
            try {                               /* Interruption confirmation      */
                kicker.sleep(100);              /* Wait 100 milli seconds set     */
            } catch (InterruptedException e) {} /* Interruption processing        */
        }
        kicker = null;                          /* Repeate process completion set */
    }                                           /* End of run method              */


/*********** Renewal (update) method ***********/
    public void update(Graphics g) {            /* Lost of screen flickering      */
        paint(g);                               /* Drawing                        */
    }                                           /* End of update method           */


/*********** Drawing (paint) method ************/
    public void paint(Graphics g) {
        if ( imgsw != 0 ) {                  /* Background image infor existence? */
            if ( mt.isErrorID(0)) {             /* Load error?                    */
                g.drawString("Image Load Error....",50,20); /* Error display      */
                return;
            }
            if( ! mt.checkID(0)) {              /* Loading ?                      */
                g.drawString("Loading....",d.width/2-30,20); /* Loading display   */
                return;
            }
            grf.drawImage(img,0,0,this);        /* Image information setting      */
        }
        else {                                  /* NO :                           */
            grf.setColor(Color.black);          /* Set backcolor ( black )        */
            grf.fillRect(0,0,d.width,d.height); /* Paint backcolor                */
        }

        Date d = new Date();                    /* Read clock information         */

        h = d.getHours();                       /* Hour information reading       */
        if ( h < 12 )                           /* Morning?                       */
            am_pm = 0;                          /* YES:Morning information setting*/
        else {                                  /* NO : PM                        */
            am_pm = 1;                          /*      Set PM                    */
            if ( h > 12 ) 
                h -= 12;                        /*      Hour - 12                 */
            else;
        }
        grf.setColor(Color.red);                /* Set letter color(red)          */
        if ( am_pm == 0 ) {                     /* AM ?                           */
            grf.setFont(new Font("Dialog",Font.BOLD,ap_fontsize)); /* Set font inf*/
            grf.drawString( "AM", amx, amy );   /* Set AM disply position         */
        }
        else {
            grf.setFont(new Font("Dialog",Font.BOLD,ap_fontsize)); /* Set font inf*/
            grf.drawString( "PM", pmx, pmy );   /* Set PM disply position         */
        }
        if ( h < 10 )                           /* One digit ( 0 - 9 )?           */
            sh = " " + h + " ";                 /* Two digits (  0 -  9 ) + Blank */
        else
            sh = h + " ";                       /* Figure + Blank(for extraction) */
        h10 = sh.substring(0,1);                /* Hour 10 places figure extracte */
        h01 = sh.substring(1,2);                /* Hour 1 place figure extracte   */
        grf.setFont(new Font("Dialog",Font.BOLD,h_fontsize)); /* Set font info    */
        grf.drawString( h10, h10x, h10y );      /* Set hour 10 places display     */
        grf.drawString( h01, h01x, h01y );      /* Set hour 1 place display       */

        m = d.getMinutes();                     /* Minute information reading     */
        if ( m < 10 )                           /* One column ( 0 - 9 )?          */
            sm = "0" + m + " ";                 /* Two column ( 00 - 09 ) + Blank */
        else
            sm = m + " ";                       /* Figure + Blank(for extraction) */
        m10 = sm.substring(0,1);                /* Minute 10 places fig extracte  */
        m01 = sm.substring(1,2);                /* Minute 1 place fig extracte    */
        grf.setFont(new Font("Dialog",Font.BOLD,m_fontsize)); /* Set font info    */
        grf.drawString( m10, m10x, m10y );      /* Set minute 10 places display   */
        grf.drawString( m01, m01x, m01y );      /* Set minute 1 place display     */

        s = d.getSeconds();                     /* Second information reading     */
        if ( s < 10 )                           /* One column ( 0 - 9 )?          */
            ss = "0" + s + " ";                 /* Two column ( 00 - 09 ) + Blank */
        else
            ss = s + " ";                       /* Figure + Blank(for extraction) */
        s10 = ss.substring(0,1);                /* Second 10 places fig extracte  */
        s01 = ss.substring(1,2);                /* Second 1 place fig extracte    */
        grf.setFont(new Font("Dialog",Font.BOLD,s_fontsize)); /* Set font info    */
        grf.drawString( s10, s10x, s10y );      /* Set second 10 places display   */
        grf.drawString( s01, s01x, s01y );      /* Set second 1 place display     */

        grf.setFont(new Font("Dialog",Font.BOLD,dot_fontsize)); /* Set font info  */
        grf.drawString( ".", dotux, dotuy );    /* Set upper dot disply position  */
        grf.drawString( ".", dotdx, dotdy );    /* Set lower dot disply position  */

        g.drawImage(offs,0,0,this);             /* Drawing setting                */

    }                                           /* End of paint method            */


/************ Stop (stop) method ***************/
    public void stop() {
        if( kicker != null ) {                  /* Kicker is not null?( action? ) */
            kicker.stop();                      /* Set kicker to suspension       */
            kicker = null;                      /* Set kicker suspension condition*/
        }
    }                                           /* End of stop method             */

}                                               /* End of class setting           */

/**********************************************************************************
 *                       End of Digital clock Applet(Ver2)                        *
 **********************************************************************************/