Create a Canvas object, add the canvas to your Frame and override the paint() method of your canvas with the one that draws the image. That's all. The paint() method of the Frame is not suitable for this purpose.
An example ImageCanvas (a bit more complicated because it is part of an image button class, supports double buffer, offset etc):
private Image image;
private int horizontalRepaintOffset;
private int verticalRepaintOffset;
private Color bgColor = SystemColor.control;
private boolean doubleBuffered = true; //true is the default value
private Image offscreenImage;
protected int width;
protected int height;
public final void setBackground(Color bgColor) {
this.bgColor = bgColor;
paint(getGraphics());
}
//during redrawing the the background is filled with white if the color isn't set thru this method. I don't know why. You can set the redrawing background color here
public final void setBaseBackground(Color bgColor) {
super.setBackground(bgColor);
}
public final void setDoubleBuffered(boolean doubleBuffered) {
this.doubleBuffered = doubleBuffered;
}
Don't forget to use MediaTracker for the images. That will wait until the image is loaded properly and ready to use.
So, create the Image and do this:
final MediaTracker tracker = new MediaTracker(this);
tracker.addImage(image, 0);
try {
tracker.waitForAll();
}
catch(java.lang.Exception e) {
e.printStackTrace();
}
After this MediaTracker stuff, create the canvas and pass it the image object.
i have done it already but still nothing, i even tried to put a button above and beneth it to see if everything is fine with positioning and still I get a button a blank area and a button. I even made an experiment copied the code to eclipse 3.0 SE environment and compile it and run it - i get an error during execution under eclipse !!! what is wrong i have no idea i run debugger and the picture data isn't null so what is happening ...
as always the path to png file was incorrect for the eclipse SE project i ve done the changes to PP procect in WSDD and nothing blank on Nokia s80 emulator but when i run the application under simple Run application in WSDD everything is oki ??? any ideas??
Try to use gif or jpg images.
Create an image object (make sure the path is correct in pp environment)
Load the image with MediaTracker.
Create an ImageCanvas, pass the Image object to its constructor
add ImageCanvas to your Frame.
Show Frame. That's all. It must work.
Tried everything You have described, and still no results. Everytime i execute an emulator of S80 i do not get the desired picture on my canvas.
Perhaps it is the fault of the environment so i would like You to execute my simple class in Your IDE. Could You do that ??
Or perhaps You send me some similar example to execute.Very simple ofcourse.
Upper left position should be 0, 0 and not 10, 10 in g.drawImage(). And temporarily change the bg color of you canvas to some vivid color and see if it's shown on your frame (in the appropriate size).