KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > thoughtriver > open > vectorvisuals > example > animation > AnimatedTankCanvas


1 /*
2  * AnimatedTankCanvas.java
3  *
4  * Created on 11 October 2005, 16:53
5  */

6
7 package com.thoughtriver.open.vectorvisuals.example.animation;
8
9 import java.awt.*;
10 import java.awt.geom.*;
11
12 import javax.swing.*;
13
14 import com.thoughtriver.open.vectorvisuals.*;
15 import com.thoughtriver.open.vectorvisuals.task.*;
16
17 /**
18  * This example illustrates the use of <CODE>AnimationTask</CODE> that is
19  * included with the Vector Visuals framework, as well as the use of the <CODE>VVCanvas</CODE>
20  * as an alternative to the <CODE>VVPanel</CODE>. It renders a simple
21  * military tank that drives in a circle around the view area while its turret
22  * moves back and forth.
23  *
24  * @author Brandon Franklin
25  * @version $Date: 2006/11/25 09:31:50 $
26  */

27 public class AnimatedTankCanvas implements Runnable JavaDoc {
28
29     /** The <CODE>VVDisplay</CODE> used to display the test */
30     private VVDisplay vvDisplay = null;
31
32     /**
33      * Creates a new instance of <CODE>AnimatedTankCanvas</CODE>.
34      */

35     public AnimatedTankCanvas() {
36         vvDisplay = new VVDisplay(new VVCanvas());
37     }
38
39     /**
40      * Starts the example.
41      */

42     public void run() {
43         JFrame frame = new JFrame("Vector Visuals Animated Tank Canvas Example");
44         frame.setSize(640, 480);
45         frame.getContentPane().setLayout(new BorderLayout());
46         frame.getContentPane().add(vvDisplay.getViewPane(), BorderLayout.CENTER);
47         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
48
49         frame.setVisible(true);
50
51         // Set up the panel itself
52
vvDisplay.getViewPane().setBackground(Color.DARK_GRAY);
53         vvDisplay.setWorldViewTranslation(320, 240);
54         vvDisplay.setWorldViewScale(1);
55
56         ArmyTank tank = new ArmyTank();
57
58         // Center the tank
59
AffineTransform transform = AffineTransform.getTranslateInstance(125, 0);
60         tank.setTransform(transform);
61         vvDisplay.addObject(tank);
62
63         // Animate the turret of the tank
64
IndefiniteOscillationTask task = new IndefiniteOscillationTask(tank.getTurret(), 1);
65         task.setRate(1);
66         vvDisplay.getTaskManager().addTask(task);
67
68         // Animate the root container with an endless rotation
69
IndefiniteRotationTask task2 = new IndefiniteRotationTask(vvDisplay.getRootObject());
70         task2.setRate(-0.5);
71         vvDisplay.getTaskManager().addTask(task2);
72     }
73
74     /**
75      * Instantiates a <CODE>AnimatedTankCanvas</CODE> and executes it.
76      *
77      * @param args the command line arguments, ignored here
78      */

79     public static void main(final String JavaDoc[] args) {
80         Runnable JavaDoc example = new AnimatedTankCanvas();
81         example.run();
82     }
83
84 }
85
Popular Tags