• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Imageicon and getImage() not working with JLabels

 
Jake Freedman
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • 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.




 
Paul Clapham
Sheriff
Pie
Posts: 20171
25
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • 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
Sheriff
Pie
Posts: 20171
25
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • 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
Sheriff
Pie
Posts: 20171
25
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And sorry, should have said this before, welcome to the Ranch!
 
Campbell Ritchie
Sheriff
Pie
Posts: 47229
52
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic