Java Toolkit.getDefaultToolkit().getImage

benoit_28 Posted messages 55 Registration date   Status Member Last intervention   -  

I can no longer display the comments from the "help" on my application (I've already described my problem and I thought I had received a solution from a chat bot, but it still doesn’t work).

What I’m doing now, which is more precise than before:

Image image_screen = createImage(1140,800); System.out.println(" image_screen* " + image_screen);

gScreenBuffer = image_screen.getGraphics();

name = javadir + "appli_puits_puits_de_potentiel.jpg"; //name of the comment and location javadir on my disk, verified N times

image_screen = Toolkit.getDefaultToolkit().getImage(name);

System.out.println(" image_screen *** " + image_screen);
Tracker tracker = new MediaTracker(this); tracker.addImage(image_screen, 0);

try { tracker.waitForID(0); }
catch (InterruptedException e) {
System.out.println(" image2 not arrived?");
}
int imagew = image_screen.getWidth(this);
int imageh = image_screen.getHeight(this);
System.out.println(" ****imagew " + imagew + " imageh " + imageh);

Result: imagew and imageh are -1 both, instead of 1140 and 800

and the address of image_screen is sun.awt.image.ToolkitImage@233c0b17 instead of BufferedImage@2ac1fdc4 before the call to the toolkit.

and obviously I don’t have the desired comment on the gScreenBuffer (coupled with image_screen). In fact, the tracker does not seem to be at fault. What seems to be wrong, is (it seems to me) the difference in address of the image before and after the call to the toolkit. A bit like if I asked for a screwdriver in the toolbox (the toolkit) and was given a hammer.

I’ve spun this problem in every way, but I always end up at the same conclusion.

Thanks in advance.