aspose file tools*
The moose likes Beginning Java and the fly likes Image Class is a Abstract Class ? ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Image Class is a Abstract Class ? ? " Watch "Image Class is a Abstract Class ? ? " New topic
Author

Image Class is a Abstract Class ? ?

sameer khazi
Greenhorn

Joined: Sep 05, 2008
Posts: 28
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.
















Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19693
    
  20

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 ]

SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Image Class is a Abstract Class ? ?