-
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?
-
Similar Threads
-
Replies: 1
Last Post: 02-12-2006, 10:32 AM
-
By javatrainee in forum Java
Replies: 5
Last Post: 11-06-2005, 02:52 PM
-
Replies: 2
Last Post: 03-08-2005, 03:19 AM
-
Replies: 1
Last Post: 03-12-2002, 09:21 PM
-
Replies: 1
Last Post: 10-19-2000, 05:00 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks