wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes enum, random card, setIcon problems Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "enum, random card, setIcon problems" Watch "enum, random card, setIcon problems" New topic
Author

enum, random card, setIcon problems

Alex Munteanu
Greenhorn

Joined: Jan 31, 2011
Posts: 5
Hello.


I have a project that im working on for a couple of days. I wanna make a card game (about texas holdem) that shows you 3 cards (the flop) and you need to tell if that flop is good or not for a bet. So, i made a class Fereastra.java (Window.Java in my native language), a class Face.java, Suit.java that generates a random face and suit from an enum and returns it as a string. I also made a Card.java class. Now i have to make a Flop.java class that shows the images (3) representation of the each card randomly chosen. I made an Flop.properties file in wich i put FAd = Ad.png ( face ace of diamonds) and so on for each card. My Flop.properties is in the practice.resources.carti package. carti means cards. I have to somehow tell Flop.java or Card.java to look in the Flop.properties for the image name that is chosen. To explain better i post the code below. Btw, im working in NetBeans.


Face.java



Suit.java


h, s, d, c means heart, spade, diamond, club

Card.java


I guess is also something wrong in the Card constructor.



If, in the main class Fereastra.java or in the Flop.java class, i do this:



I get errors.
To summarize i want, when i call Flop() to be displayed 3 cards randomly chosen on my JLabel.

Any help would be very appreciated. Also some feedback about my english is appreciated.

PS: If its something that i posted other than in english (and i didnt explained it) or you dont understand something please tell me.
Thanks for reading this.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11161
    
  16

"I get errors" doesn't really help us much. Errors when you compile? run? save? Telling the details is critical. What are you doing that generates the errors, and what is the exact text of those errors?


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Alex Munteanu
Greenhorn

Joined: Jan 31, 2011
Posts: 5
Thanks for your reply Fred.

well i writed in Fereastra.java this:



And i get
cannot find symbol
regarding ImageIcon
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19654
    
  18

Welcome to the Ranch, Alex.

Have you tried importing javax.swing.ImageIcon?

Also, I really suggest you rename your enum constants. If you have to explain to us what h, s, d and c mean that should already signal that they are improperly named. So use proper names:
I'd rather read Suit.Hearts and Face.Four than Suit.V_h and Face.V_4.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Alex Munteanu
Greenhorn

Joined: Jan 31, 2011
Posts: 5
Hi Rob, thanks for the reply. Yes i imported ImageIcon, and thanks again for feedback i will replace them. About the problem, i think its because i put that card inside ImageIcon(). So i without card inside it works fine. Im thinking of something like:



or something like that
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19654
    
  18

Something like that. The parameter to getResource needs to be a String, indicating the relative location to the image file.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38033
    
  22
. . . and welcome to the Ranch
Alex Munteanu
Greenhorn

Joined: Jan 31, 2011
Posts: 5
Nice to meet you too Ritchie

Well i know it must be a String but the Card class has to make it a String. The way i see it, in the Card class constructor it gets a random face (for example: A) and a random suit (for examaple d) and it adds them together:



I tried also with:



But doesnt seem to work either. So after doing that Card = Ad (in this example) and that need to be replaced with "Ad.png" from my Flop.properties.

Alex Munteanu
Greenhorn

Joined: Jan 31, 2011
Posts: 5
I modified the Card.java class:



And i made the Flop.java like this:



And in the the Fereastra.java class (that makes the window) at the actionListener of a button i putted:



And i get some strange errors:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at practice.Flop.<init>(Flop.java:16)
at practice.Fereastra$1.actionPerformed(Ferestra.java:48)


Anyone know wtf?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: enum, random card, setIcon problems
 
Similar Threads
Enum
doubts in enum and generalized code
Constructor problem.
can't split card shuffle method into a separate class
Need help with constructor and fields