Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to extend ImageIcon class effectively  RSS feed

 
Sir Java
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to write a prog initially for a pack of playing cards.

The SingleCard class extends ImageIcon, so that is also holds info on the suit and value of the card.




In a DeckofCards class, an array holds 52 objects of type SingleCard

eg,

URL someGif = getClass().getResource("cards/aceofhearts.gif");
SingleCard card1 = new SingleCard(someGif,0,0);

Problem: If I try to add a SingleCard to a frame, it doesn't compile, saying that 'add method cannot be applied to SingleCard'.

What is going wrong?




 
Joe Ess
Bartender
Posts: 9406
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the JavaRanch, Sir Java. Please change your displayed name to conform to our
naming policy. In short, your name must be a first name and last name, separated by a space and not obviously fake.
Have a look at the javadoc for ImageIcon. Then look at the javadoc for JFrame. Notice anything about the add() method in JFrame (actually in Container, JFrame's superclass)? add() takes a Component. ImageIcon is not a Component.
There's a chapter on How to Use Icons in the Java Tutorial that you may find helpful.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!