Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Unable to view image in applet

 
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);
}

}
 
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 .
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • 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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic