C
CelticFC
The following is code for a grid within an Applet.
public void drawBox(Graphics g){
for(int i=10;i<=350;i+=40){
g.drawLine(i,10,i,330);
g.drawLine(10,i,330,i);
}
What I would like to do is to be able to load an image within a square
on the grid, so that the image is locked within the square on the grid
and no other image would be able to share the same square.
At the moment I can load an image in the grid, but without locking it
to any square within the grid.
the following is how the image is loaded.
for(int i = 0; i < point.size(); i++){
icon = (Point)point.get(i);
g.drawImage(pawn, icon.x, icon.y, 25, 25, this);
}
And this is the method used.
public void mousePressed(MouseEvent mouseevent){
setBackground(new Color(210,255,210)); //Light Green Background
x = mouseevent.getX(); //returns value of x coordinate
y = mouseevent.getY(); //returns value of y coordinate
if(x > 19 && x < 312 && y > 19 && y < 312){ //boundary of
grid(board)
pawncount = pawncount + 1; //ensures other conditions can
be met within the game
point.add(mouseevent.getPoint()); //adds the value to the
Arraylist
}
Hope this makes sense to somebody.
thanks in advance for any help.
public void drawBox(Graphics g){
for(int i=10;i<=350;i+=40){
g.drawLine(i,10,i,330);
g.drawLine(10,i,330,i);
}
What I would like to do is to be able to load an image within a square
on the grid, so that the image is locked within the square on the grid
and no other image would be able to share the same square.
At the moment I can load an image in the grid, but without locking it
to any square within the grid.
the following is how the image is loaded.
for(int i = 0; i < point.size(); i++){
icon = (Point)point.get(i);
g.drawImage(pawn, icon.x, icon.y, 25, 25, this);
}
And this is the method used.
public void mousePressed(MouseEvent mouseevent){
setBackground(new Color(210,255,210)); //Light Green Background
x = mouseevent.getX(); //returns value of x coordinate
y = mouseevent.getY(); //returns value of y coordinate
if(x > 19 && x < 312 && y > 19 && y < 312){ //boundary of
grid(board)
pawncount = pawncount + 1; //ensures other conditions can
be met within the game
point.add(mouseevent.getPoint()); //adds the value to the
Arraylist
}
Hope this makes sense to somebody.
thanks in advance for any help.