• Post Reply Bookmark Topic Watch Topic
  • New Topic

getCodeBase problem  RSS feed

 
Steve Schowiak
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please help a Greenhorn.
I am writing a simple Blackjack applet (ya, it's been done a million times before, but I'm new to Swing/AWT and trying to test my OO skillz)
I alway get a compile error on the line with '>>>>>' :

Error is:
[BOLD]cannot resolve symbol: method getCodeBase ()in class BlackjackApplet.DeckofCards at line 20 (20:30)[/BOLD]
The thing is I found some code on the web that uses a similar line and it works.
Any help out there?
Thanks!
Steve
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
getCodeBase() is a method in java.applet.Applet, but DeckOfCards does not extend Applet, so the only way to call getCodeBase() would be if DeckOfCards had a reference to an Applet object. You might, for instance, pass the Applet as a constructor argument to DeckOfCards.
 
Steve Schowiak
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you are saying that I can pass the applet itself from the already running applet?
Like:
DeckofCards deck = new DeckofCard(this);
If so, how do I define the data type of the parameter in the constructor of DeckofCards? And once I have the applet in there, then I can reference all the methods of Applet?
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is your class the Applet, or is it a supporting class? If it's the Applet, then you need to make it one:



If it's a class that your applet uses then you could pass the reference into it through the constructor, or get a reference to the data in some other way.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!