Results 1 to 8 of 8
  1. #1
    Atynine is offline Member
    Join Date
    Jan 2012
    Posts
    13
    Rep Power
    0

    Default Grabbing Images from Arraylists

    I want to grab this image from the ArrayList, but don't know how to. Any help?

    Java Code:
    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.image.BufferedImage;
    import java.io.IOException;
    import java.util.ArrayList;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    
    
    public class Terrain{
    	BufferedImage Allow;
    	int x, y;
    	
    	public Terrain(){
    	loadSprites();	
    	}
        public void loadSprites(){
            BufferedImageLoader loader = new BufferedImageLoader();
            BufferedImage spriteSheet = null;
            try {
                Allow = loader.loadImage("terrain.png");
    
            } catch (IOException ex) {
                Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
            }
            SpriteSheet Terr = new SpriteSheet(Allow);
            ArrayList<BufferedImage> walk = new ArrayList<BufferedImage>();
                walk.add(Terr.grabSprite(0, 0, 16, 16));
        }
    }
    Just to clarify, I want to load "walk.add(Terr.grabSprite(0, 0, 16, 16));" and display it on the screen.
    Code might be a little messy, haven't gotten around to cleaning it up, and I'm new to this:D

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,691
    Rep Power
    8

    Default Re: Grabbing Images from Arraylists

    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    19

    Default Re: Grabbing Images from Arraylists

    You need to inform your GUI that there's a new image in the List (call a method on the GUI).
    This can be done either by holding a reference to the GUI (or relevant bit of the GUI) in your Terrain object, or to have the Terrain object hold a list of listeners that are informed when the List of images has changed.

  4. #4
    Atynine is offline Member
    Join Date
    Jan 2012
    Posts
    13
    Rep Power
    0

    Default Re: Grabbing Images from Arraylists

    What would I need to add in paintComponent to display the image after that?

  5. #5
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,691
    Rep Power
    8

    Default Re: Grabbing Images from Arraylists

    Quote Originally Posted by Atynine View Post
    What would I need to add in paintComponent to display the image after that?
    What have you tried? Have you checked out the API yet?

    Java Platform SE 6
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  6. #6
    Atynine is offline Member
    Join Date
    Jan 2012
    Posts
    13
    Rep Power
    0

    Default Re: Grabbing Images from Arraylists

    Quote Originally Posted by KevinWorkman View Post
    What have you tried? Have you checked out the API yet?

    Java Platform SE 6
    Just did, but don't know where to look

  7. #7
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,691
    Rep Power
    8

    Default Re: Grabbing Images from Arraylists

    Quote Originally Posted by Atynine View Post
    Just did, but don't know where to look
    Then I suggest you hit the basic tutorials, which I linked above.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  8. #8
    Atynine is offline Member
    Join Date
    Jan 2012
    Posts
    13
    Rep Power
    0

    Default Re: Grabbing Images from Arraylists

    Quote Originally Posted by KevinWorkman View Post
    Then I suggest you hit the basic tutorials, which I linked above.
    Already been through that, I meant I wouldn't know where to look because theres no ArrayList that I saw.

    Edit: Found it, looking now.
    Edit2: Cant pull anything that would help me from that:l
    Last edited by Atynine; 01-19-2012 at 03:39 PM.

Similar Threads

  1. Grabbing a php variable?
    By JeffXtensor in forum New To Java
    Replies: 3
    Last Post: 01-14-2011, 03:18 PM
  2. Replies: 4
    Last Post: 12-16-2010, 04:32 PM
  3. Grabbing info from Java game
    By n0bekre in forum Advanced Java
    Replies: 3
    Last Post: 06-24-2010, 01:17 PM
  4. grabbing text from JTextField and replace it.
    By jimmy-lin in forum New To Java
    Replies: 1
    Last Post: 11-16-2009, 09:09 AM
  5. grabbing an item from an arraylist.
    By newtojava7 in forum New To Java
    Replies: 1
    Last Post: 03-17-2008, 08:25 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
  •