GIDForums  

Go Back   GIDForums > Computer Programming Forums > Java Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 04-Jun-2006, 06:22
bilbo123 bilbo123 is offline
New Member
 
Join Date: Jun 2006
Posts: 1
bilbo123 is on a distinguished road

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:
JAVA Code:
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?
Edit/Delete Message
Last edited by cable_guy_67 : 04-Jun-2006 at 07:53. Reason: Please enclose java code in [java] ... [/java] tags
  #2  
Old 11-Jun-2006, 19:57
TurboPT's Avatar
TurboPT TurboPT is offline
Regular Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 958
TurboPT is a jewel in the roughTurboPT is a jewel in the roughTurboPT is a jewel in the rough

Re: Paint help


What is the 'type' of your grid?

I helped someone else with another type of grid-coloring, but their 'grid' was a two dimensional array of JButtons, and the paint method was not necessary because of direct button coloring via setBackground() button calls, check it out here:

http://www.gidforums.com/showpost.ph...6&postcount=13

[their 'clear' button resets all the buttons to green -- see function colorButtons()]

If you'd like to keep your code, post more of your code (if you can), and we'll try a solution for the clear.
__________________
Use the force...read the source!!
WYCIWYG -- what you code is what you get!
 
 

Recent GIDBlogToyota - 2008 September Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 21:17.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.