File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Performance and the fly likes How can be better? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Java » Performance
Bookmark "How can be better?" Watch "How can be better?" New topic

How can be better?

Pan Niko
Ranch Hand

Joined: Mar 19, 2011
Posts: 86


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

Joined: Nov 03, 2000
Posts: 331
Use a HashMap and assign the key, value pairs by HashMap<Character, Image>
Pan Niko
Ranch Hand

Joined: Mar 19, 2011
Posts: 86

Never used HashMap before, checked its API but did not understant how will be usefull in my programm. Any similar example please??
I agree. Here's the link:
subject: How can be better?
It's not a secret anymore!