import java.applet.Applet; import java.awt.Label; import java.awt.Font; public class tid_c extends Applet implements Runnable { public void init() { super.setLayout( null ); this.time_lbl = new Label(); this.time_lbl.setFont( new Font( "Helvetica", Font.ITALIC, 15 ) ); super.add( this.time_lbl ); this.time_lbl.setBounds( 10, 5, 400, 50 ); this.base_msg = super.getParameter( "base_msg" ) + " "; this.one_hour = super.getParameter( "one_hour" ); this.sev_hours = super.getParameter( "sev_hours" ); this.one_minute = super.getParameter( "one_minute" ); this.sev_minutes = super.getParameter( "sev_minutes" ); this.one_second = super.getParameter( "one_second" ); this.sev_seconds = super.getParameter( "sev_seconds" ); } // init public void start() { this.set_time_label(); this.run_thread = new Thread( this ); this.keep_running = true; this.run_thread.start(); } // start public void stop() { this.keep_running = false; this.run_thread = null; } // stop public void run() { while ( this.keep_running ) { try { Thread.sleep( 1000 ); } catch ( InterruptedException exc ) { } tid_c.seconds = ( tid_c.seconds + 1 ) % 60; if ( tid_c.seconds == 0 ) { tid_c.minutes = ( tid_c.minutes + 1 ) % 60; if ( tid_c.minutes == 0 ) { tid_c.hours++; } // if } // if this.set_time_label(); } // while } // run private void set_time_label() { StringBuffer msg = new StringBuffer( this.base_msg ); tid_c.add_time( msg, // msg tid_c.hours, // siffra this.one_hour, // label_1 this.sev_hours, // label_not_1 false ); // add_when_0 tid_c.add_time( msg, // msg tid_c.minutes, // siffra this.one_minute, // label_1 this.sev_minutes, // label_not_1 tid_c.hours > 0 ); // add_when_0 tid_c.add_time( msg, // msg tid_c.seconds, // siffra this.one_second, // label_1 this.sev_seconds, // label_not_1 true ); // add_when_0 this.time_lbl.setText( msg.toString() ); } // set_time_label private static void add_time( StringBuffer msg, int siffra, String label_1, String label_not_1, boolean add_when_0 ) { if ( ( siffra == 0 ) && ( !add_when_0 ) ) { return; ////////// } // if msg.append( siffra ); if ( siffra == 1 ) { msg.append( label_1 ); } else { msg.append( label_not_1 ); } // if } // add_time private Thread run_thread; private Label time_lbl; private Label init_lbl; private boolean keep_running; private String base_msg; private String one_hour, sev_hours; private String one_minute, sev_minutes; private String one_second, sev_seconds; private static int hours, minutes, seconds; private static int init_number = 0; } // tid_c