Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Paint help

I've got issues with accessing my paint method in a class. I have a paint method in a class called Canvas - basically this paint method will draw me a grid and colour each cell the colour black when the mouse is clicked a cell. Lets say i've clicked a few cells and they're black. That code is here as follows:

public void paint (Graphics g)
{
super.paint(g);

int width = getWidth();
int height = getHeight();
int x2 = width;
int y2 = height;
int xcoord = gridcoord;
int ycoord = gridcoord;
squareX = width/ grid;
squareY = height/grid;


for (int j=-10; j<=grid; j++) // the number of squares on the y axis
{
g.drawLine (xcoord,ycoord, x2,ycoord);
ycoord += squareY ;
}


ycoord = gridcoord;


for (int i=-12; i<=grid; i++) // the number of squares on the x axis
{
g.setColor(Color.black);
g.drawLine (xcoord,ycoord, xcoord,y2);
xcoord = xcoord + squareX;
}
g.setColor(Color.black); // colour each square to this colour
for(int row = 0; row < gridcell.length; row++)
{
for(int col = 0; col < gridcell[row].length; col++)
{
if(gridcell[row][col] == colour)
{
xcoord = gridcoord + col * squareX + 1;
ycoord = gridcoord + row * squareY + 1;
g.fillRect(xcoord, ycoord, squareX - 1, squareY - 1);
}
}

}
}

Ok, so this alll works fine. But on my actual GUI, i have a button called "Clear". This clear button is in class Frame, and this clear button should repaint the whole grid (with no cells in black). Now, i'm trying to call the paint method when the Clear button is pressed, just not sure of how to do that. I tried calling the paint component directly, that didn't help. Any ideas from you guys?
[2211 byte] By [coolio2006] at [2007-11-11 8:50:02]
# 1 Re: Paint help
call repaint()
Phaelax at 2007-11-11 22:34:14 >