How to display images in the Applet

Source: Internet
Author: User

How to display images in the Applet
**************************************** *********************
****
** Author: one small step of one day's improvement by Liu Yu **
** Date: 2000-12-19 ==================== **
** Jeru@163.net enriches my every day **
****
**************************************** *********************
I. To display an image in an Applet, You need to introduce the following package and call the ImageObserver interface .:
Import java. awt. image .*;
Import java. awt. image. ImageObserver;
Import java.net. URL;
Public class MyApplet extends Applet implements ImageObserver {...
II. Define image path
URL imgURL = getDocumentBase ();
Set the path to the same as your html file.
URL imgUrl = getClassBase ();
Set the path to the same as your html file.
3. Get Image
Img = getImage (imgURL, imgName );
Of course, if you want to put your image files in a directory, you can do this.
Img = getImage (imgURL, "img" + imgName );
4. Show Image
The most basic method is to call drawImage (). This method is defined in the Graphics class. The simplest method is as follows:
G. drawImage (image, xPosition, yPosition, this );
The last parameter calls ImageObserver.
5. Final supplement
The above is the most basic. Of course, sometimes you even want to compress your image file into a jar package.
The getResourceAsStream () method is used.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.