import javax.swing.*;
import java.awt.*;




public class Time{
	
	int hr, mt, sc;
	
	public Time(){
		hr = 0;
		this.mt = 0;
		
	}
	
	public Time(int jhr, int jmt, int jsc){
		this.setHour(jhr);
		setMinute(jmt);
		this.setSecond(jsc);
		
	}
	
	public void setHour(int xhr){
		if(xhr < 24) hr = xhr;
		else hr = 0;
	}
	
	public void setMinute(int xmt){
		if(xmt < 60) mt = xmt;
		else mt = 0;
	}
	
	public void setSecond(int xsc){
		if(xsc < 60) sc = xsc;
		else sc = 0;
	}
	
	public String toStandard(){
		String t = "", tcd;
		
		
		if(hr > 12) tcd = " P.M";
		
		else tcd = " A.M";
		
		if(hr % 12 < 10) t = t + "0" + hr % 12;
		else t = t + hr;
		t = t + ":";
		
		if(mt < 10) t = t + "0" + mt;
		else t = t + mt;
		t = t + ":";
		
		if(sc < 10) t = t + "0" + sc;
		else t = t + sc;
		
		t = t + tcd;
		
		return t;
			
	}
	
	
	public String toString(){
		String t = "";
		
		if(hr < 10) t = t + "0" + hr;
		else t = t + hr;
		t = t + ":";
		
		if(mt < 10) t = t + "0" + mt;
		else t = t + mt;
		t = t + ":";
		
		if(sc < 10) t = t + "0" + sc;
		else t = t + sc;
		
		return t;
	}
	
	
	public void tick(){
		// insert code to advance time by one second...
		
		sc++;
		if(sc==60){
			mt++;
			sc=0;
		}
		if(mt==60){
			hr++;
			mt=0;
		}
		if(hr==24){
			hr=0;
		}
		
	}
	
	
	public static void main(String argv[]){
		
		Time t1, t2;
		t1 = new Time();
		t2 = new Time(17, 45, 55);
		
		System.out.println("hello world  " + t1);
		System.out.println(t2.toStandard());
		//----------------------------------------------------------------
		
		JFrame f = new JFrame("My Test Frame");
        f.getContentPane().setLayout(new FlowLayout());
        JButton button;
        ImageIcon image;
        ImageIcon poster;
        image = new ImageIcon("starz.gif");
        poster = new ImageIcon("impala.jpg");
        JLabel lab1 = new JLabel(poster);
        
        for(int i = 0; i < 3; i++){
           button = new JButton("My Button", image);
           button.setText("Testing 123");
           f.getContentPane().add(button);
        }
        
     
        
        f.getContentPane().add(lab1);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setSize(200, 400);
        f.setVisible(true);
        
        
        for(int i = 0; i < 25; i++){
        	
        	t2.tick();
            lab1.setText(t2.toString());
            try{
        	     Thread.sleep(1000);
             }
            catch(InterruptedException ie){
            	ie.printStackTrace();
            }
            
            System.out.println("Show Print");
        }

	}
	
}

    Source: geocities.com/dvshah