maybe simple problem (translate)

hello,

i tried to translate this way:

public void paint(graphics g){
g.translate(-x,-y)
// paint something
g.translate(x,y)
}

the first translate seems to work perfect but later the origin of the graphics is somewhere in the middle.

By the Way:
I’m changing x,y with a MouseListener and i’m using a thread for calling paint().

but why is the origin wrong? i’m translating and translating back so how can the origin change?

Greetz

maybe x,y changes (-> the mouse is moved) during the execution of paint()?

you doing any other transforms (scale/rotate) in the:
// paint somthing
area?

no, i’m only painting in the //painting area.
but in the future i want to scale the graphics
in the same way like translate. scaling only
works perfect but without the translate it
is senseless (i want to implement a mouse-zoom)

valodim was right. :slight_smile:
x,y changed during execution of paint().
i have fix it with storing x,y in temporary
variables at the beginning of paint() and
using the temporary variables for the painting.

now it looks like this:
public void paint(Graphics g){
int tempX=TranslationX;
int tempY=TranslationY;

g2d.translate(-tempX,-tempY);
// paint something
g.translate(tempX,tempY);
}

Thanks