Please, UseCodeTags (this is a link) when posting. I have added them for you this time. Doesn't it look better?
You can try replacingwith
The reason is, the image has not beed loaded when drawImage() is called for the first time. You can verity this by printing the result of this method (it returns false if the image has not been loaded, true otherwise).
Adding the panel as ImageObserver ensures that the image will be drawn when fully loaded.
Also, don't write String args[]. It should be String[] args.
Your code would have looked even better with indentation; we have some suggestions here.
I am 99.9% sure that writing .* after Toolkit in the import declaration was a mistake. What do you actually want to import?
I was trying to put a image on jpanel but i was gettong a zoomed in image.Can someone tell how to get the actual image as background.
screenshot of output is attached.
I think I shall merge your thread with your other one because they are about related subjects.
I am 99% sure that the problem has to do with the size of the image. If you open that image with a photo editor, it will probably say it is 8MB size and 3450×2300px. Now that is larger than most screens. Unlike a photo editor, a Swing component does not zoom automatically. Start by shrinking that image with your photo editor, in which case it will probably occupy little enough space that the whole picture is visible. Not sure what to do to about zooming. You can try adding the panel to a scroll pane. You can try copying the Graphics object with its create() method, casting to Graphics2D and using its scale method. But I am not quite sure how you would code that,