Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9245509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:16:57+00:00 2026-06-18T09:16:57+00:00

I am currently working on a small Java game in eclipse, and am knee

  • 0

I am currently working on a small Java game in eclipse, and am knee deep in a few thousand lines of code. Right now, I am specifically attempting to use a String’s contents to paint an image, and am wondering if it is possible. If it is it would save me at least a few hundred lines of individual variables for each image.

Pasting the whole program would more than likely prove counter productive due to the length, so I will merely demonstrate what I am attemtping.

What I am attempting to do:

ImageIcon ladder = new ImageIcon (getClass ().getResource ("ladder.png"));
floorContents [currentX] [currentY] = "ladder";

public void paint (Graphics g)
{
     if (floorContents [currentX] [currentY] != "none") // painting item where standing
     {
         floorContents[currentX][currentY].paintIcon (this, g, 0, 0);
     }
}

Essentially I am attempting to get the program to see
this line:

floorContents[currentX][currentY].paintIcon (this, g, 0, 0);

as this:

ladder.paintIcon (this, g, 0, 0);

If at all possible. This would save me from having to write in each image item seperately.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T09:16:58+00:00Added an answer on June 18, 2026 at 9:16 am

    Put each image in a Map keyed by the string

    imageMap.put("ladder", new ImageIcon (getClass ().getResource ("ladder.png")));
    
    //...
    
    imageMap.get(floorContents [currentX] [currentY]).paintIcon (this, g, 0, 0);
    

    Of course, you should key to see if the map contains the key first, or if the value returned is null…

    if (imageMap.containsKey(floorContents [currentX] [currentY]) {
        //....
    }
    

    of

    ImageIcon image = imageMap.get(floorContents [currentX] [currentY]);
    if (image != null) {
        //...
    }
    

    But that’s up to you

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently working on a small 2D game-engine in C++, but I am now
I'm currently working on a small game that consisted of a few targets that
I'm am currently working on a program in java which requires adding a small
I am currently working on a small personal multiplayer game project. I am using
I'm currently working on a small project in java where I need to process
I'm currently working on a small iPhone game, and am porting the 3d engine
I'm working on building a chess game in Java, and I'm currently having a
I am currently working on a small project using RESTlet on Google App Engine/Java.
I'm working on a small java game which is a sort of clone of
I am currently working on a small desktop Java application which will track various

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.