MULTIMEDIA: IMAGES, ANIMATION, AUDIO, AND VIDEO


 Timer 
 Image Maps 
 Links 

The "sizzle" of Java is multimedia, the use of sound, images, graphics, and video to make applications "come alive."  Applet method getImage loads an Image  (package jawa.awt).  For example:   logo1 = getImage( getDocumentBase(), "logo.gif" ); It takes two arguments, a location where the image is stored, and the file name of the image..  Applet method getDocumentBase returns the location of the applet's HTML file on the internet as an object of class URL (package java.net).  Java supports several image formats, such as Graphics Interchange Format (GIF) ( .gif ), Joint Photographic Experts Group (JPEG) (.jpg or .jpeg), and Portable Network Graphics (PNG) (.png).  Class ImageIcon (package javax.swing) provides constructors that allow an ImageIcon object to be initialized with an image from the local computer or with an image stored on a web server on the Internet.  ImageIcon method paintIcon displays the ImageIcon's image.  It requires four arguments, a reference to the component on which the image will be displayed, a reference to the Graphics object used to render the image, and the x- and y- coordinates of the upper-left corner of the image.  For example:    logo2.paintIcon( this, g, 180, 0 );  Class ImageIcon's paintIcon method does not allow scaling of an image.  The class provides method getImage, which returns an Image reference that can be used with Graphics method drawImage to display a scaled version of an image.

Graphics method drawImage receives four arguments, a reference to the Image object in which the image is stored, the x- and y- coordinates where the image should be displayed and a reference to an ImageObserver object.  For example: g.drawImage( logo1, 0 0, this) will draw an image.    To output a scaled image, use six arguments, the fourth and fifth arguments specify the width an height of the image.  For example:  g.drawImage( logo1, 0, 120, getwidth(), getheight - 120, this ); will draw image scaled to fit width of applet and height of applet minus 120 pixels.  Interface ImageObserver is implemented by class component (an indirect superclass of Applet), which are notified to update na image that was displayed as the rest of the image is loaded.

Timer objects generate ActionEvents at fixed intervals of milliseconds and notify their registered ActionListeners that the event occurred.   The Timer constructor receives two arguments, the delay in milliseconds and the ActionListener. For example animation delay = 50;    animationTimer = new Timer( animationDelay, this);   Timer method start indicates that the timer should start generating events.  For example animationTimer.start();   Timer method stop indicates that the timer should stop generating events.  For example animationTimer.stop();   Timer method restart indicates that the timer should start generating events again.  For example animationTimer.restart();  

Applets can be customized via parameters ( the <param> tag) that are supplied from the HTML file that invokes the applet.  The <param> tag lines must appear between the starting applet tag and the ending applet tag.  Each parameter has a name and a value.  For example:
                <html>
                <applet code = "LogoApplet.class" width = 400, height = 400>
                <param name = "totalImages" value = "30">
                <param name = "imageName" value = "leMoyne">
                <param name = "animationDelay" value = "200">
                </applet>
                <html>
Applet method getParameter gets the value associated with a specific parameter and returns the value as a String.  The argument passed to getParameter is a String containing the name of the parameter in the param tag.  For example:    parameter = getParameter( "animationdelay" );    gets the value 200 associated with parameter animationdelay.   If there is no param tag containing the specified parameter, getParameter returns null.

Image maps are a common technique used to create interactive Web pages.  An image map is an image that has hot areas that the user can click to accomplish a task, such as loading a different Web page into a browser.  When the user positions the mouse pointer over a hot area, a descriptive message appears.  The code to invoke it is:
                public class ImageMap extends JApplet    {
                        private ImageIcon mapImage;

Applet method play has two forms:
                public void play( URL location, String soundFileName );    loads the audio clip stored in file soundFileName from location and plays the sound.  The first argument is a call to the applet's getDocumentBase which indicates the location of the HTML file that loaded the applet  or getCodeBase which indicates the location of the applet's .class file, and
                public void play( URL soundURL );    takes a URL that contains the location and the file name of the audio clip.  The statement play( getDocumentBase(), "hi.au" );  loads the audio clip in file hi.au and plays it once.
The sound engine that plays the audio clips support several audio file formats.  Sun Audio (.au), Windows Wave (.wav), Macintosh AIFF (.aif or .aiff), and Musical Instrument Digital Interface (MIDI) (.mid or .rmi).  The Java Media Framework (JMF) supports other additional formats.

Applet method getAudioClip has two forms that take the same arguments as the play method.  Method getAudioClip returns a reference to an AudioClip.  AudioClips have three methods, namely play plays the audio once, loop continuously loops the audio clip, and stop terminates the audio clip that is currently playing.

Links:

 NASA Multimedia gallery contains a wide variety of images, audio and video clips that can be downloaded and used to test Java multimedia programs.

 Sunsite Japan Multimedia Collection also provides a wide variety of images, audio and video clips that can be downloaded for educational purposes.

 Australian Notional Botanic Gardens provides links to sounds of many animals,  Common Birds

 Freesite.com has links to free sounds and clip art

 Sound Central provides audio clips in WAV. AU, AIFF, and MIDI formats.

 Animation Factory provides thousands of free GIF animations for personal use.

 Clip Art.com contains links to web sites that provide free art

 PNGART.com provides over 50,000 free images in PNG format to help this newer image format gain popularity

 Java Look-and-feel Graphics Repository provides standard images for use in a swing GUI