KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * AnimatedTank.java
3  *
4  * Created on 23 May 2005, 13:46
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. It renders a simple military tank
20  * that drives in a circle around the view area while its turret moves back and
21  * forth.
22  *
23  * @author Brandon Franklin
24  * @version $Date: 2006/11/25 09:31:50 $
25  */

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

34     public AnimatedTank() {
35         vvDisplay = new VVDisplay(new VVPanel());
36     }
37
38     /**
39      * Starts the example.
40      */

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

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