With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

No credit card required

Indefinite Progress Indicator #47
Chapter 6, Transparent and Animated Windows
|
253
HACK
Build the Circular Shape
Everything begins when the start( ) method is invoked:
public void start( )
{
setVisible(true);
ticker = buildTicker( );
animation.start( );
}
Before running the animation, this method takes care of adding a mouse lis-
tener that is responsible for catching all the mouse events and preventing
them from being forwarded to the underlying user interface. Thus, the user
will not be able to perform any action. The second step is to set the glass
pane to be visible. Finally, the
ticker, the circular shape, is built and the ani-
mation is started. Building the shape is done with two methods:
private Area buildPrimitive( )
{
Rectangle2D.Double body = new Rectangle2D.Double(6, 0, 30, 12);
Ellipse2D.Double head = new Ellipse2D.Double(0, 0, 12, 12);
Ellipse2D.Double tail = new Ellipse2D.Double(30, 0, 12, 12);
Area tick = new Area(body);
return tick;
}
private Area[] buildTicker( )
{
Area[] ticker = new Area[barsCount];
Point2D.Double center = new Point2D.Double((double) getWidth( ) / 2,
(double) getHeight( ) / 2);
double fixedAngle = 2.0 * Math.PI / ((double) barsCount);
for (double i = 0.0; i < (double) barsCount; i++)
{
Area primitive = buildPrimitive( );
AffineTransform toCenter = AffineTransform.getTranslateInstance(
center.getX(), center.getY( ));
AffineTransform toBorder =
AffineTransform.getTranslateInstance(45.0, -6.0);
AffineTransform toCircle =
AffineTransform.getRotateInstance(-i * fixedAngle,
center.getX(), center.getY( ));

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

No credit card required