Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials:
 

Software Solutions and Services
 

 
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments
 
Display image in the applet 
 

This program illustrates you to display image in an applet which has been done in this example.

 

Display image in the applet

                         

Introduction

This program illustrates you to display image in an applet which has been done in this example. In this program you will see that how many methods, classes, packages and it's properties have been used to display the image in an applet.

In this program only one function paint(Graphics g) has used. Function paint(Graphics g) is also a part of the life cycle of an applet in which anything you can draw in your applet to appear on the browser. In this function MediaTracker class of the java.awt.*; package, has been used. MediaTracker is a utility class that tracks the status of a number of media objects. And this type of object can include images and audio clips. In this program only the explanation about the adding images has been given. MediaTracker class is used after creating the instance for that and calling the addImage() of the MediaTracker class which is used in this program as you can see. In this program method getImage() is used to return the image for the object ( img ) of the Image class taking two arguments, first is getCodeBase() and another is image name. Then the addImage() method of the MediaTracker has been used. Syntax of the addImage() function is MediaTracker.addImage(img, x, y, x1, y1). Arguments of addImage() function is explained below : 

img - image name type of Image.
x     - lower X - Coordinate type of int.
y     - lower Y - Coordinate type of int.
x1   - upper X - Coordinate type of int.
y1   - upper Y - Coordinate type of int.

Here is the code of the program : 

import java.applet.*; 
import java.awt.*; 
             
public class appletImage extends Applet{
  Image img;
  MediaTracker tr;
  public void paint(Graphics g) {
    tr = new MediaTracker(this);
    img = getImage(getCodeBase()"freelinuxcds.gif");
    tr.addImage(img,0);
    g.drawImage(img, 00this);
  
}

Try online this example.

Download this example.

                         

» View all related tutorials
Related Tags: html c com orm air tags sed char tag rounding ai element tar character elements characters like start call cte

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

4 comments so far (
post your own) View All Comments Latest 10 Comments:

Hi,

I tried this program using Netbeans IDE 6.1 but the applet cannot display as sample in online.
Error display "Applet not initialized".
Please help me. Thank You

Posted by AZAH on Tuesday, 09.16.08 @ 06:50am | #79747

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

public class appletImage extends Applet{
Image img;
MediaTracker tr;
public void paint(Graphics g) {
tr = new MediaTracker(this);
img = getImage(getCodeBase(), "freelinuxcds.gif");
tr.addImage(img,0);
g.drawImage(img, 0, 0, this);
}
}

i had tried this program but it did not display the image. so can tell me what was the reason?

Posted by antriksh on Monday, 09.8.08 @ 14:31pm | #77986

Hi,
I need to know the method to import images in applet.
Can u give me suggestions reguarding how to create a slideshow in java and displaying the data retrieved from any database along with images.

Posted by Sangram on Monday, 02.4.08 @ 10:45am | #47165

please send me tutorials related how to create java applets displaying different scrolling images and each image ishaving different hyperlinks

Posted by smitha on Monday, 05.14.07 @ 11:10am | #15824

Training Courses
Tell A Friend
Your Friend Name
Website Designing Services
 
Web Designing Packages From $150!
 
Website Designing Company Web Hosting
 
Website Designing Quotation
 
Search Tutorials:

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.