Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How can be better?

 
Pan Niko
Ranch Hand
Posts: 86
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I have some txt files with characters. In my java programm im reading these files and depending what character is in each place, show an image in JPanel. Im checking the characters simply by if, if else, else statments. My question is if there is a better way to do it, because are aprox 10-11 different images.

Thank you
 
john mattucci
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use a HashMap and assign the key, value pairs by HashMap<Character, Image>
 
Pan Niko
Ranch Hand
Posts: 86
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Never used HashMap before, checked its API but did not understant how will be usefull in my programm. Any similar example please??
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic