• Time

    Inside Jplay's package there's a time counter using the following format:

    formatoTempo

    1 - Time class constructor:

    public Time(int x, int y, boolean crescentTime);

    In this Constructor you must pass the positions (x,y) where the time will be draw on the screen and if Time is going to be used as a reverse or progressive stopwatch.

    To work as a reverse stopwatch, pass a false value to the option boolean crescentTime. Otherwise, to work as a progressive stopwatch, pass a true value.

    Example:

    					Time tempo = new Time(100,100, true);
    					X = 100, Y = 100, Progressive Stopwatch.
    					Time tempo = new Time(100,100, false);
    					X = 100, Y = 100, Reverse Stopwatch.
    				


    On the constructor method down below we must pass the hour, minute and second value that will be used, and the position as well.

    public Time( int hour, int minute, int second, int x, int y );

    Example:

    					//Time equal to 5 seconds
    					//hora = 0, minuto = 5, segundo = 0, x = 456, y = 329, reverse stopwatch.
    					Time tempo = new Time(0,5,0, 456, 329, false);
    				


    On the construtor method bellow you can choose the font and the text color to display the time.

    public Time(int hour, int minute, int second, int x, int y, Font font, Color color, boolean crescentTime);

    Example:

    					//public Time( int hour, int minute, int second, int x, int y, Font font, Color color, boolean crescentTime )
    					Font fonte = new Font("Comic Sans MS", Font. TRUETYPE_FONT, 40);
    					Time tempo = new Time( 1, 23, 34, 100, 100, fonte , Color.Yellow, false);
    				

    Obs.: On the other constructors the default font and text colors are: Font("Arial",Font.TRUETYPE_FONT, 20) e Color.YELLOW.

    2 - Time class methods

    					//Returns a string with the time value on the format 00:00:00
    					public String toString(); 
    					
    					//Shows an user's choice message and then draws the time value
    					public void draw(String message);
    					
    					//Draw the value on the screen
    					public void draw();
    	
    					//Set a color to the time value
    					public void setColor(Color color);
    					
    					//Set a font
    					public void setFont(Font font);
    					
    					//If you choose a reverse stopwatch, This method returns true if the time had ended
    					public boolean  timeEnded();
    					
    					//Set the hour
    					public void setHour(int  hour);
    					
    					//Set the minutes
    					public void setMinute(int  minute);
    					
    					//Set the seconds
    					public void setSecond(int  second);
    					
    					//Returns the hour
    					public long  getHour();
    					
    					//Returns the minute
    					public long  getMinute();
    					
    					//Returns the second
    					public long  getSecond();
    					
    					//Get the amount of time in seconds
    					public long  getTotalSecond();
    					
    					//Set the time value
    					public void setTime(int hour, int minute, int seconds);
    				


    Example: Show on the screen two stopwatches, a reverse and a progressive one.

    					package Time001;
    
    					import jplay.GameImage;
    					import jplay.Keyboard;
    					import jplay.Time;
    					import jplay.Window;
    					import java.awt.Color;
    
    					/**
    					 * @author Gefersom Cardoso Lima
    					 * Federal Fluminense University
    					 * Computer Science
    					 */
    
    					public class Time001
    					{
    						//Show on the screen a regressive and a rising time.
    						public static void main(String[] args)
    						{
    								Window janela = new Window(800,600);
    								Keyboard keyboard = janela.getKeyboard();
    								GameImage backGround = new GameImage("fundo.png");
    
    								Time tempo1 = new Time(100, 100,true);
    								tempo1.setColor(Color.yellow);
    
    								Time tempo2 = new Time(1, 39, 56, 100, 200,false);
    								tempo2.setColor(Color.cyan);
    
    								boolean executando = true;
    
    								while(executando)
    								{
    										backGround.draw();
    										tempo1.draw("Progressivo: ");
    										tempo2.draw("Regressivo:  ");
    										janela.update();
    
    										if ( keyboard.keyDown(Keyboard.ESCAPE_KEY) == true )
    											executando = false;
    								}
    								janela.exit();
    						}
    					}
    
    				

    UFF - Universidade Federal Fluminense - Institudo de Computação - Ciência da Computação