All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class kpalin.alabra.ChessTimer

java.lang.Object
   |
   +----java.awt.Component
           |
           +----java.awt.Container
                   |
                   +----java.awt.Panel
                           |
                           +----kpalin.alabra.ChessTimer

public class ChessTimer
extends Panel
implements Runnable, Externalizable
This controls the timers.

Author:
Kimmo Palin

Variable Index

 o nf
This avoids fetching NumberFormat information every second.
 o side
Side of the player.
 o th
Thread controling the clock.
 o timeBase
Starting time of the timers.
 o timeDelta
The counters are added this value every second.
 o timeElapsed
Signaling interface towards Observer.
 o timeLabel
The time shown on the panel.
 o timeSec
Integer representation of the time.

Constructor Index

 o ChessTimer()
This is useless constructor for programmer but Externalizable-interface uses this (public no-arg constructor).
 o ChessTimer(String, int, int, Observer)
Creates a new chess timer for specific player.

Method Index

 o adjustTimeDelta()
Sets the timeDelta-attribute to correct direction.
 o getTime()
Returns elapsed time in seconds.
 o isCurrentThread()
Checks if we are testing from current thread.
 o newTimeSlize()
Gives a new timeslize for this timer.
 o readExternal(ObjectInput)
Used for reading saved ChessTimer.
 o reset()
Resets the timer to stop at timeBase
 o resume()
Resumes the time counting.
 o run()
This controls the timers.
 o setTimeBase(int)
Sets new time base.
 o stop()
Stops the counter permanently.
 o suspend()
Suspends the counter for now.
 o toString()
Time formater for Label.
 o writeExternal(ObjectOutput)
Used for saving this object.

Variables

 o side
 private Label side
Side of the player. White or Black.

 o timeLabel
 private Label timeLabel
The time shown on the panel.

 o timeSec
 private int timeSec
Integer representation of the time.

 o timeBase
 private int timeBase
Starting time of the timers. If this is >0, the timers run downwards, else upwards.

 o timeDelta
 private int timeDelta
The counters are added this value every second.

 o th
 private Thread th
Thread controling the clock.

 o timeElapsed
 private ClockListen timeElapsed
Signaling interface towards Observer.

 o nf
 private final NumberFormat nf
This avoids fetching NumberFormat information every second.

Constructors

 o ChessTimer
 public ChessTimer()
This is useless constructor for programmer but Externalizable-interface uses this (public no-arg constructor).

 o ChessTimer
 ChessTimer(String who,
            int sideCode,
            int timeLimit,
            Observer obs)
Creates a new chess timer for specific player.

Parameters:
who - Name whose timer this is.
sideCode - Number id of the player, for callback.
timeLimit - Size of the timeshare.
obs - Observer for the callback.

Methods

 o setTimeBase
 private void setTimeBase(int base)
Sets new time base.

Parameters:
base - New time base.
 o newTimeSlize
 public void newTimeSlize()
Gives a new timeslize for this timer.

 o adjustTimeDelta
 private void adjustTimeDelta()
Sets the timeDelta-attribute to correct direction.

 o reset
 public void reset()
Resets the timer to stop at timeBase

 o run
 public void run()
This controls the timers.

 o toString
 public synchronized String toString()
Time formater for Label. Synchronized because of nf-instance.

Overrides:
toString in class Component
 o resume
 public synchronized void resume()
Resumes the time counting.

 o suspend
 public synchronized void suspend()
Suspends the counter for now.

 o isCurrentThread
 public boolean isCurrentThread()
Checks if we are testing from current thread. (Needed for the alarm.)

 o stop
 public synchronized void stop()
Stops the counter permanently.

 o getTime
 public int getTime()
Returns elapsed time in seconds.

 o writeExternal
 public void writeExternal(ObjectOutput out) throws IOException
Used for saving this object. This is a must, because it's impossible to save Thread-object.

 o readExternal
 public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
Used for reading saved ChessTimer. Doesn't read Thread because it's not saved.


All Packages  Class Hierarchy  This Package  Previous  Next  Index