Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Emo.fm
Jan 2, 2007
I'm writing a program (yes, homework for intro CS) that plays a quick card game between two computer players and then returns who won (player 1 or 2, it's a random game of luck so theoretically I should be able to run it 1000000 times and see 50/50 winning percentages). I believe my code is correct, and I can run it as many times as I want with no exceptions if I actually run it repeatedly by hand -- but if I insert a for loop to get it to run multiple trials, I invariably end up with an array index out of bounds exception. I'm really confused by this because all of the variables (arrays of cards, stuff like that) are declared either in the for loop or the method called from within the for loop. What kinds of things should I be looking for? What could cause the program to screw up when run multiple times within itself, when I can run it so many times from outside with no incidents, so to speak?

Adbot
ADBOT LOVES YOU

Emo.fm
Jan 2, 2007
What's the deal with loading images from the web to display in applets? I'm following the directions from this site, but whenever I try to compile, I'm told that the method "getImage()" doesn't exist.

I'm doing this within a file that is a smaller class used in the Applet, not the Applet class itself, so could that be the problem? Pretty much the entire program is finished except for this (I was previously working offline as an application, and therefore just using a toolKit) so I'm not willing to move the loading of graphics into the Applet class, unless that's the only way. Ideas?

(Just for clarification, here is exactly how I'm trying to implement this:
code:
 Image myImage = getImage("http://www.website.com/image.gif"); 

Emo.fm
Jan 2, 2007

ynef posted:

You answered your own question, there. Your code attempts to call a method called getImage() in your small class that is used in the Applet class. If you haven't written a method like that, then it is not going to work. Call the Applet class' getImage() method instead.

Sorry, I'm still a little confused. Let's say I have two files, MyApplet.java and SmallClass.java. If I want to load an image in SmallClass.java, how do I do it? Moving all of the image related operations that occur in SmallClass to MyApplet is not an option for me right now. There must be some way to load an image in a class that isn't an applet, right?

PS - If what you meant was to call Image myImage = MyApplet.getImage("url"); that doesn't seem to work either.

Emo.fm
Jan 2, 2007

Strong Sauce posted:

Eh? My problem was with generics. But anyways I figured out that you can't define a constant for the generic type.

You want AspectJ. Except no one really wants AspectJ, as far as I can tell.

My question, which is less Java related and more "data structures oh god why did I take this class this semester": implementing a splay tree. How strictly is one supposed to follow the rules of splaying every time you access a node? For example, I'm writing a method to return an array representation of the node-keys from an inorder traversal of the tree. Am I supposed to splay after visiting each node :gonk:? Or do I only splay after searching expressly for a specific key?

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply