• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

enum, random card, setIcon problems

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
. . . and welcome to the Ranch
 
Alex Munteanu
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
It's hard to fight evil. The little things, like a nice sandwich, really helps. Right tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic