Results 1 to 2 of 2
  1. #1
    susan is offline Member
    Join Date
    Jul 2007
    Rep Power

    Default Help with pictures en Java

    Recently, I found that initialzing a new ImageIcon in the paint function is a terrible thing to do, as it will always look for the image which will slow the game down and/or flicker.
    So the solution to this problem is to define the ImageIcon in the class, and call the picture in public void init or something.

    However, would I have to do this process for 100++ pictures? I tried to use and array to load all my pictures, but then I had a problem finding the one I needed. Is there another solution to stop the game from being so slow/flickering?
    Or just a better way to do this in general?

  2. #2
    cachi is offline Member
    Join Date
    Jul 2007
    Rep Power


    Can you associate the pictures with some type of string?
    Such as the filename or something of that sort?
    That way you can look it up in a hashmap which will give you as close as O(1) time as you're going to get.
    There is also included a way to get the entrySet from the hashmap if you need to go through each of them.
    This is included in the API:

    Basically I think you need to look into ways to optimizing the whole thing. It may be worth wild to do a search on Google about optimizing java code. Besides that without looking at the code I can't tell you much else about it.


Similar Threads

  1. Replies: 22
    Last Post: 07-25-2012, 09:51 PM
  2. Help Loading Up Pictures
    By marco in forum Java Applets
    Replies: 3
    Last Post: 08-14-2007, 10:32 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts