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
-
nf
- This avoids fetching NumberFormat information every second.
-
side
- Side of the player.
-
th
- Thread controling the clock.
-
timeBase
- Starting time of the timers.
-
timeDelta
- The counters are added this value every second.
-
timeElapsed
- Signaling interface towards Observer.
-
timeLabel
- The time shown on the panel.
-
timeSec
- Integer representation of the time.
-
ChessTimer()
- This is useless constructor for programmer but Externalizable-interface
uses this (public no-arg constructor).
-
ChessTimer(String, int, int, Observer)
- Creates a new chess timer for specific player.
-
adjustTimeDelta()
- Sets the timeDelta-attribute to correct direction.
-
getTime()
- Returns elapsed time in seconds.
-
isCurrentThread()
- Checks if we are testing from current thread.
-
newTimeSlize()
- Gives a new timeslize for this timer.
-
readExternal(ObjectInput)
- Used for reading saved ChessTimer.
-
reset()
- Resets the timer to stop at timeBase
-
resume()
- Resumes the time counting.
-
run()
- This controls the timers.
-
setTimeBase(int)
- Sets new time base.
-
stop()
- Stops the counter permanently.
-
suspend()
- Suspends the counter for now.
-
toString()
- Time formater for Label.
-
writeExternal(ObjectOutput)
- Used for saving this object.
side
private Label side
- Side of the player. White or Black.
timeLabel
private Label timeLabel
- The time shown on the panel.
timeSec
private int timeSec
- Integer representation of the time.
timeBase
private int timeBase
- Starting time of the timers. If this is >0, the timers
run downwards, else upwards.
timeDelta
private int timeDelta
- The counters are added this value every second.
th
private Thread th
- Thread controling the clock.
timeElapsed
private ClockListen timeElapsed
- Signaling interface towards Observer.
nf
private final NumberFormat nf
- This avoids fetching NumberFormat information every second.
ChessTimer
public ChessTimer()
- This is useless constructor for programmer but Externalizable-interface
uses this (public no-arg constructor).
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.
setTimeBase
private void setTimeBase(int base)
- Sets new time base.
- Parameters:
- base - New time base.
newTimeSlize
public void newTimeSlize()
- Gives a new timeslize for this timer.
adjustTimeDelta
private void adjustTimeDelta()
- Sets the timeDelta-attribute to correct direction.
reset
public void reset()
- Resets the timer to stop at timeBase
run
public void run()
- This controls the timers.
toString
public synchronized String toString()
- Time formater for Label. Synchronized because of nf-instance.
- Overrides:
- toString in class Component
resume
public synchronized void resume()
- Resumes the time counting.
suspend
public synchronized void suspend()
- Suspends the counter for now.
isCurrentThread
public boolean isCurrentThread()
- Checks if we are testing from current thread. (Needed for the alarm.)
stop
public synchronized void stop()
- Stops the counter permanently.
getTime
public int getTime()
- Returns elapsed time in seconds.
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.
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