Sunday, November 27, 2011

Display Image in an Applet Example

/*
Display Image in an Applet Example
 This Java example shows how to display an image using drawImage method
 of an Java Graphics class.
 */
 import java.applet.Applet;
 import java.awt.Graphics;
 import java.awt.Image;
 /*
 <applet code = "DisplayImageExample" width = 500 height = 300>
 <param name = "Image1" value = "one.jpg">
 <param name = "Image2" value = "two.jpg">
 </applet>
 */
 public class DisplayImageExample extends Applet
 {
 Image img1, img2;
 public void init(){
 img1 = getImage(getDocumentBase(), getParameter("Image1"));
 img2 = getImage(getDocumentBase(), getParameter("Image2"));
 }
 public void paint(Graphics g){
 //display an image using drwaImage method of Graphics class.
 g.drawImage(img1, 0,0,this);
 g.drawImage(img2, 100,100,this);
 }
 }

No comments:

Post a Comment

How to find the most appropriate Keywords?

  🔍 Step 1: Understand Your Business and Audience Define your products, services, or content . Identify your target audien...