DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Paint help

  1. #1
    Join Date
    Jun 2006

    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)

    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.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?

  2. #2
    Join Date
    Mar 2004
    call repaint()

Similar Threads

  1. Paint event does not fired
    By livehed in forum .NET
    Replies: 1
    Last Post: 02-12-2006, 10:32 AM
  2. keeping shapes on a canvas with a paint tool
    By javatrainee in forum Java
    Replies: 5
    Last Post: 11-06-2005, 02:52 PM
  3. Paint method problem
    By AK_47 in forum Java
    Replies: 2
    Last Post: 03-08-2005, 03:19 AM
  4. Problem with paint (Graphics g )
    By Alan in forum Java
    Replies: 1
    Last Post: 03-12-2002, 09:21 PM
  5. 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
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center