GT Computing Home Page

GT Computing Home Page

The DigitModifer class

Here's a listing of this class:

//  DigitModifier.java

import linguist.quickshow.*;

public class DigitModifier extends Thread
{
	Actor actor;
	
	public DigitModifier(Actor a)
	{
		actor=a;
		start();
	}
	
	public void run()
	{
		int actorLeft=actor.getLeft();
		int actorTop=actor.getTop();
		int actorHeight=actor.getHeight();
		while (true)
		{
			actor.pause((int)(Math.random()*10000));
			int height;
			for (height=actorHeight; height>actorHeight/4; height-=4)
			{
				actor.setScaledHeight(height);
				actor.moveAllTo(actorLeft,actorTop+actorHeight-height);
				actor.redraw();
				actor.pause(50);
			}
			for (; height<=actorHeight; height+=4)
			{
				actor.setScaledHeight(height);
				actor.moveAllTo(actorLeft,actorTop+actorHeight-height);
				actor.redraw();
				actor.pause(50);
			}
		}
	}
}

This class is not derived from Actor as it doesn't need to be known to the Stage. But it does subclass Thread so it can run concurrently. It serves here as an example of how to use utility classes to manage the behaviour of Actors, without the need to incorporate all the rules in the Actor itself. This is good Java practice and not something specific to QuickShow. There are (as ever) several ways of doing much the same thing; here I've chosen to have the Modifier control the Actor, but you could put the timing loop in the Digit class and merely use static functions in the Modifier to do the digit alterations. I wouldn't say one way is better than the other.