I am creating an incredibly primitive blackjack game for my high school programming class using Swing, therefore, all my resource classes extend JPanel. I created the following resource classes:
- DealerBox
- ClubsBox
- SpadesBox
- HeartsBox
My problem is that I want to create a handful of public integers such that I have
public int DealerTotal, ClubsTotal, SpadesTotal, HeartsTotal;
I want to do this so I can track the values of everybody's hands and determine winners and losers. I had a lightbulb go off and thought that making the Dealerbox a superclass to Clubs, Spades, and Hearts was the solution to all my troubles as I could have simple code in the superclass getting values for the above integers and do all the checking I need.
So I wrote this for one of my subclasses:
public class ClubsBox extends JPanel, DealerBox implements Runnable
{
//fun code
}
The problem now is that I keep getting an error. I assumed it had something to do with listing ClubsBox as being the subclass of JPanel AND DealerBox. So I stackoverflowed my problem and found an answer that stated that one cannot have a class that has 2 superclasses. Another answer to a similar question said that one COULD have a class that has two superclasses.
Now we get to the main question: Is it possible to have a class that has two superclasses? If so, how do I code it? If not, is there a way around the restriction?
EDIT: 21 APRIL 2014, 44 MINUTES AFTER ORIGINAL POST
I have a new problem. I used the method that everyone suggested which was to make DealerBox extend JPanel then to have everything else extend DealerBox. My GUI went from this:
To This:
The bottom one is clearly incredibly screwed up. Somehow labels from other areas ended up being copied and stuff got mixed around. If you need the code let me know, but I need serious help fixing this.
Please keep in mind the inheritance tree looks like this: