• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Unable to view image in applet

 
Mona Bajaj
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

Unable to view image in applet.
I have saved the image where the .class file is saved, but when running the program(Eclipse), only blank applet viewer screen is displayed.
Please let me know in which folder, the image should be saved.

Please refer the below code

package practice_2;

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

public class ImageDemo extends Applet {
private static final long serialVersionUID = 1L;

private Image img;

public void init() {
img = getImage(getDocumentBase(), getParameter("img"));

}
public void paint(Graphics g) {
g.drawImage(img, 10,0, this);
}

}
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try it like this

 
Mona Bajaj
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
tried that way then also facing the problem.

Same problem i am facing when m trying to add image to icon in basic swing program.

Please tell me the exact location where the image file should be saved .
 
Darryl Burke
Bartender
Posts: 5148
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This tutorial should help: http://docs.oracle.com/javase/tutorial/uiswing/components/icon.html#getresource
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic