rohith yenumula wrote:Thanks for the example.
I have a doubt regarding the ImageIcon constructor. I tried passing the relative and absolute address of a image but there was no image displayed.
your problem is setting the relative path
1) save your image next to your your file (then the path i gave you is the correct)
2) save your image inside a folder called img and put this folder next to your file (then the path is: img/"myImage")
so, JPEG is diferent from jpeg, i guess
also, you have to give the extension and also all that should be inside quotes ("myImage.png")
as a side note, you should always pay atention to the compiler error messages - the compiler is your friend
try this and let me know if it works:
rohith yenumula wrote:Hi Miguel. I have tried doing it as you told but it didn't work.
There are no compile-time or run-time errors but two .class files(DisplayImage and DisplayImage$1) were created when I ran the program. Do you have any idea why is it so?
post all the code you have so far, so that we give it a look
DisplayImage.class is the class file for the DisplayImage class. DisplayImage$1 is the class file for the first anonymous inner class encountered inside the DisplayImage class. If you have taken Miguel's example code then that is the Runnable created in the main method.
Try to add the following instead:
This way you can see which file is being loaded (or at least tried), and if that file exists.