Results 1 to 5 of 5

Thread: simple drawing

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2001
    Location
    Ottawa, Canada
    Posts
    181

    simple drawing

    i have an array of 100 buttons, with icons (that show properly, without a prob), layout using GridLayout

    i have a second method that is supposed to change the button's icon. to a differnet icon, (which is in the corrent path and everything is fine, but it doesn't change. when i do

    Code:
    public void flipTilesToBlank() {
    	for (int x = 0; x < 100; x++) {
    		aButton[x].setIcon(new ImageIcon ("blank.jpg"));
    		aButton[x].paint(aButton[x].getGraphics());
    		System.out.println(aButton[x].getGraphics());
    		this.update(aButton[x].getGraphics());
    
    		}		
    	}
    for the System.out.println(aButton[x].getGraphics()); i get 'null'

    what method would i use to redraw after i've set the new image icon, (i'm a bit new to java swing, so not exactly sure, i'm trying the update or i'm trying

    aButton[x].paint(aButton[x].getGraphics());

    nothing works?? WHY

    thanx for your help
    --770

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    paint is not a method that is meant to be called directly. It is there as a callback for the system. An application should call the repaint method.

    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Apr 2001
    Location
    Ottawa, Canada
    Posts
    181
    thank you

    but how exactly do i use it??

    i'm doing this... (aButton[x].repaint(1, 0, 0, 500, 500), but doesn't do anything at all

    //from the java api 1.4 (sun website)

    public void repaint(long tm,
    int x,
    int y,
    int width,
    int height)Adds the specified region to the dirty region list if the component is showing. The component will be repainted after all of the currently pending events have been dispatched.

    Overrides:
    repaint in class Component
    Parameters:
    tm - this parameter is not used
    x - the x value of the dirty region
    y - the y value of the dirty region
    width - the width of the dirty region
    height - the height of the dirty region


    --770

  4. #4
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    The Component class has a repaint method that takes no parameters. You can use that one to repaint the whole component.

    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Apr 2001
    Location
    Ottawa, Canada
    Posts
    181
    i am doing both of those...

    tried both..

    repainting the panel it's on and/or the button itself, but it doesn't seem to update...grrr.....

    thanx though
    --770

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width