KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > thoughtriver > open > vectorvisuals > example > fundamental > Subclassing


1 /*
2  * Subclassing.java
3  *
4  * Created on 2 August 2004, 01:41
5  */

6
7 package com.thoughtriver.open.vectorvisuals.example.fundamental;
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.example.animation.*;
16
17 /**
18  * This small application illustrates the use of a subclassed <CODE>VisualObject</CODE>
19  * in a <CODE>VVDisplay</CODE>.
20  *
21  * @author Brandon Franklin
22  * @version $Date: 2006/11/25 09:35:06 $
23  */

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

32     public Subclassing() {
33         vvDisplay = new VVDisplay(new VVPanel());
34     }
35
36     /**
37      * Starts the example.
38      */

39     public void run() {
40         JFrame frame = new JFrame("Vector Visuals Subclassing Example");
41         frame.setSize(640, 480);
42         frame.getContentPane().setLayout(new BorderLayout());
43         frame.getContentPane().add(vvDisplay.getViewPane(), BorderLayout.CENTER);
44         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
45
46         frame.setVisible(true);
47
48         // Set up the panel itself
49
vvDisplay.getViewPane().setBackground(Color.DARK_GRAY);
50         vvDisplay.setWorldViewScale(1);
51
52         // Instantiate an ArmyTank, which is a subclass of VisualObject
53
ArmyTank tank = new ArmyTank();
54
55         // Set the location and size of the tank
56
AffineTransform transform = tank.getTransform();
57         transform.scale(3.0, 3.0);
58         transform.translate(100, 80);
59         tank.setTransform(transform);
60
61         // The subclass offers us unique API that we can use
62
tank.rotateTurret(0.5);
63
64         // Display the object on the VVPanel
65
vvDisplay.addObject(tank);
66     }
67
68     /**
69      * Instantiates a <CODE>Subclassing</CODE> and executes it.
70      *
71      * @param args the command line arguments, ignored here
72      */

73     public static void main(final String JavaDoc[] args) {
74         Runnable JavaDoc example = new Subclassing();
75         example.run();
76     }
77
78 }
79
Popular Tags