• 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

Imageicon and getImage() not working with JLabels

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a friends code using the same images with the same paths working. We simply do not understand what is wrong. Thanks for any help.




 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Scrolling through your code I couldn't see any paths or any images. But then there were several hundred lines of code so probably I couldn't pick those trees out of the forest. If you have a question about JLabel and images, could you possibly just post that code and not several hundred lines of unrelated code?
 
Paul Clapham
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
However I do have a comment about this code:



You really shouldn't use the == operator to compare the contents of two String objects for equality. You should use String's equals() method if you want to do that. But in this particular case you shouldn't be comparing any Strings anyway. Here's what that code should look like instead:


 
Paul Clapham
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And sorry, should have said this before, welcome to the Ranch!
 
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome again

Paul Clapham wrote:However I do have a comment about this code:

. . .

Me too.
Whenever I see lots of if‑elses like that, I start to think that is really non‑object‑oriented code. Why are you not using a Card object? In which case your deuce can have a value of 0 and the trey a value of 1.
Actually, I have a vague memory that the cards are all worth their number value, except for the court cards: J=11, Q=12, K=13 and A=14. There would be no card with a value of 1.
You also have the problem that if you put anything which is not found or matched by the selection blocks, it will return 12 as if for an ace.
 
reply
    Bookmark Topic Watch Topic
  • New Topic