Sign in to follow this  
luckylavs

Java Question: How to refer to an Icon using concatenated Strings?

Recommended Posts

Here is my problem. I have created many different icon objects, each named with this general format:

<name><direction><number>icon

For example, billdown5icon, steveright2icon, etc.

I want to repeatedly change a JLabel's icon to accomplish a simple animation

So I am trying:

myLabel.setIcon
(name+direction+number+"icon");

But Java is expecting an Icon as the argument, and here I'm giving it a string. I don't want to give it a String, I want to say "use the icon which has this particular name"

Is there an easy way to do this?

Thanks in advance.

Share this post


Link to post
Share on other sites
Shouldn't one of the ImageIcon constructors like [url="http://download.oracle.com/javase/1.4.2/docs/api/javax/swing/ImageIcon.html#ImageIcon(java.lang.String)"]this one[/url] do the job?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this