Grabbing Images from Arraylists
I want to grab this image from the ArrayList, but don't know how to. Any help?
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
Re: Grabbing Images from Arraylists
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.
Re: Grabbing Images from Arraylists
What would I need to add in paintComponent to display the image after that?
Re: Grabbing Images from Arraylists
Quote:
Originally Posted by
Atynine
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
Re: Grabbing Images from Arraylists
Quote:
Originally Posted by
KevinWorkman
Just did, but don't know where to look
Re: Grabbing Images from Arraylists
Quote:
Originally Posted by
Atynine
Just did, but don't know where to look
Then I suggest you hit the basic tutorials, which I linked above.
Re: Grabbing Images from Arraylists
Quote:
Originally Posted by
KevinWorkman
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