Index Topic Contents | |||
Previous Topic: How to Build a DirectAnimation Java Applet or Application Next Topic: How to Build the DirectAnimation C++ Samples that Render to DirectDraw Surfaces |
How to Write a DirectAnimation Java Applet
See the BasicApplet.java file in Samples\DA\Java\Templates\BasicApplet.
Every DirectAnimation applet has two main pieces: the DXMApplet class and the Model class. The following steps show how to construct and initialize a simple DirectAnimation applet.
- Import the media libraries.
import com.ms.dxmedia.*;If you import multimedia files using URLs, you must also import the Java libraries with:
import java.net.*;- Define the applet class. This class extends the DXMApplet class. Then, set the model in the init method. Always call the superclass's init first to ensure that the applet's base URL (the directory in which the applet is located) is set. The model you set with the setModel method is the model that is displayed.
// // Class: MyApplet // class MyApplet extends DXMApplet { public void init() { super.init() ; // Now set the model. setModel(new MyModel()); } }- Define the model class. This class extends the Model class. You construct your animation with the createModel method. The following code example constructs a solid blue image.
// // Class: MyModel // class MyModel extends Model { public void createModel(BvrsToRun blist){ // Set the image that actually gets displayed setImage(solidColorImage(blue)); } }- Compile the code with the Jvc compiler.
- Insert the applet in an HTML page.
<title> My Applet </title> <hr> <applet code=MyApplet.class width=200 height=200> </applet> <hr>© 1998 Microsoft Corporation. All rights reserved. Terms of Use.