Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Image Class is a Abstract Class ? ?

Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 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.

Posts: 21999
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
If you open the box, you will find Heisenberg strangling Shrodenger's cat. And waving this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic