Hi there..i am working on a program where i am adding few widgets(components) on the panel.
Now i could add a button to the frame, and also add a panel carrying a circle widget. but when i try to add a image on the panel and in turn on a frame, i get the error as : java.awt.Image is an abstract class. Now i know since the abstract classes cannot be instantiated.
then how could i add my image on the panel?
Now , the following is the code where i am trying to add a button, a oval widget and also a image(as represented by the above program).
but now when i am compiling this program the following error is what i get:
C:\JPM\gui>javac SimpleGui3C.java SimpleGui3C.java:34: java.awt.Image is abstract; cannot be instantiated MyImage image=new Image(); ^ 1 error
I would like to ask the members to give hints and allow me to work out this program so that i shall learn the basics.
Thank you...kindly co-operate if anything wrong in representing.
Don't you mean "new MyImage"? Because that's the name of your class, not image.
There is a problem with your approach. You create a new JPanel subclass for the image (which could work), but you haven't provided its size. Therefore, it will have a preferred size of 0 by 0 pixels, and probably not display at all.
If you just want to display an image, JLabel is a better solution:
[ September 27, 2008: Message edited by: Rob Prime ]