Hey i am making a little game where the user can place blocks (hehe mc

) so here i am i can create and remove blocks with the mouse but it removes the block that was last placed but i want to remove the block where the mouse is hovering over.
So i was thinking maybe if i made an array of polygons and draw a 1x1 poly at the mouse's position and polygons around the blocks and when the mouse collides with the block i want to remove that certain block but how would i select that certain block in the array ?
here is my source
Code:
import java.awt.Point;
import java.util.ArrayList;
import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.BasicGame;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
public class MainGame extends BasicGame{
ArrayList<Image> stone = new ArrayList<Image>();
ArrayList<Point> posi = new ArrayList<Point>();
Input input = null;
int gx = 50;
int gy = 50;
Image ghost = null;
Image stoneBlock = null;
boolean pick = false;
boolean build = false;
public MainGame()
{
super("Slick2DPath2Glory - SimpleGame");
}
@Override
public void init(GameContainer gc)
throws SlickException {
ghost = new Image("data/stone.png");
stoneBlock = new Image("data/stone.png");
ghost.setAlpha(0.5f);
}
@Override
public void update(GameContainer gc, int delta)
throws SlickException
{
input = gc.getInput();
gx = input.getMouseX()-ghost.getWidth()/2;
gy = input.getMouseY()-ghost.getHeight()/2;
if(input.isKeyDown(Input.KEY_B) && input.isMousePressed(Input.MOUSE_LEFT_BUTTON)) {
posi.add(new Point(gx,gy));
stone.add(stoneBlock);
}
if(input.isKeyDown(Input.KEY_P) && input.isMousePressed(Input.MOUSE_LEFT_BUTTON) && stone.size() > 0) {
stone.remove(stoneBlock);
posi.remove(posi.size()-1);
}
}
public void render(GameContainer gc, Graphics g)
throws SlickException
{
ghost.draw(gx,gy,1);
for(int i = 0; i < stone.size(); i++) {
for(Point pos: posi) {
String a = String.valueOf(pos.getX());
float posx = Float.valueOf(a);
String b = String.valueOf(pos.getY());
float posy = Float.valueOf(b);
stone.get(i).draw(posx,posy,1);
}
}
}
public static void main(String[] args)
throws SlickException
{
AppGameContainer app =
new AppGameContainer(new MainGame());
app.setDisplayMode(800, 600, false);
app.setVSync(true);
app.start();
}
}