Home | Java Menu | Java Applets | Java Tips | E-mail Us
View Java Applet


/* MultimediaImage.java
  *
  * A Java Applet demonstrating multimedia image.
  *
  * Authored by Khim Theng
  * khim_theng@completeesolutions.com
  *
  * Last modified on 05/11/2000
  */

import java.applet.*;
import java.awt.*;

public class MultimediaImage extends Applet
{
    private String imageName;  //String variable for image
    private Image picture = null;  //Set picture to null 
    private int pictureWidth, pictureHeight;

    public void init ()
    {
        setBackground(Color.white);  //Set the background color to white

        imageName = getParameter("IMAGE");  //Get image file from the <PARAM> tag in the HTML file

        if (imageName != null)  //If imageName is not empty
        {
            picture = getImage(getCodeBase(), imageName);  //Find the image file in the same directory as the .class file
            showStatus("Loading Image File...");  //Display message in the window status bar (not shown in Netscape)
            MediaTracker imageMt =  new MediaTracker(this);  //Create new MediaTracker object
            imageMt.addImage(picture, 0);
            try
            {
                imageMt.waitForAll();  //Load full image before displaying
            }
            catch(InterruptedException ie)
            { }

            if (imageMt.isErrorAny())
                picture = null;

            pictureWidth = picture.getWidth(this);  //Get the width of the picture
            pictureHeight = picture.getHeight(this);  //Get the height of the picture
        }
    }  //End of init

    public void paint (Graphics g)
    {
        if (picture == null)
            g.drawString("Error loading image!", 5, 5);  //Display message if picture is empty
        else
        {
            g.drawImage(picture, 5, 5, this);  //Display image at x position 5 and y position 5
        }
    }  //End of paint

}  //End of MultimediaImage
                
View Java Applet

Home | Java Menu | Java Applets | Java Tips | Legal
© 1999-2003 Complete e Solutions, Inc.