Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

enum, random card, setIcon problems

 
Alex Munteanu
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 12098
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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?
 
Alex Munteanu
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply Fred.

well i writed in Fereastra.java this:



And i get
cannot find symbol
regarding ImageIcon
 
Rob Spoor
Sheriff
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Alex Munteanu
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Something like that. The parameter to getResource needs to be a String, indicating the relative location to the image file.
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
. . . and welcome to the Ranch
 
Alex Munteanu
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic