Multimedia

Date: 5/6/2002

Animation

Applets

In the paint method for Applet:

img = getImage(RL for server/path, strFileName);
g.drawImage(img, y-pos, x-pos, null);

Applications

In the constructor for the Application:

Make sure that the component is visible first. Meaning, if it's a frame show it, if its a panel add it to a visible frame.

Create a URL object for the file.

URL url = new URL(strURLFileName)

Get the Toolkit for the component:

Toolkit tk = frame.getToolkit();

Use the createImage() method of the Toolkit object:

Image img = tk.createImage(url);

Use a MediaTracker to make sure it is fully loaded before displaying it:

MediaTracker mt = new MediaTracker(this);
mt.addImage(img, 0);
mt.waitForAll();

Get the Graphics for the object, and draw the image:

Graphics g = getGraphics();
g.drawImage(img,4,23,this);

Sound

Applets

song = getAudioClip(URL object for server/path, strFileName);
Two arguments for Applet method

Applications

song = Applet.newAudioClip(URL object for server/path/filename);
One argument for Applet method