The Artima Developer Community
Sponsored Link

Java Answers Forum
tranlations problem

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
niall o' gribin

Posts: 1
Nickname: nastynige
Registered: Mar, 2003

tranlations problem Posted: Mar 5, 2003 1:52 AM
Reply to this message Reply
Advertisement
Hi Folks!

I have a little problem where on a panel, i am trying to flip an image.. but it seems to flip all images on the screen. I can't seem to get it working.. anybody able to spot the problem?

It loops thru all images, and only if 'rotated' it should rotate image, draw them all to buffered image and draw it to screen

<code follows.. >


public void update(Graphics g){
Graphics2D g2 = (Graphics2D)g;


if(firstTime){
Dimension dim = this.getSize();


Random randomvalue = new Random();

int w = dim.width*2;
int h = dim.height;

setSize(w,h);
area = new Rectangle(dim);
bi = (BufferedImage)createImage(w, h);
big = bi.createGraphics();


firstTime = false;

}


int thecenterx,thecentery;
int thex, they;

big.clearRect(0, 0, area.width*2, area.height);
Dimension d = getSize();


AffineTransform oldat = big.getTransform();//get the at to restore later.



String theanswer =Quiz.getanswerstring(Quiz.getcurrentQuestionNumber());



for (int i=0; i<theanswer.length(); i++)
{

currentimage=currentanswer;

if (flippedarray[currentimage])
{
// System.out.println("Flipping..");
thecenterx=rectarray[currentimage].x+(imagearray[currentimage].getWidth(this)/ 2);
thecentery=rectarray[currentimage].y+(imagearray[currentimage].getHeight(this) /2);//Centre co-ords of rectangle needed


AffineTransform fliptransform = AffineTransform.getTranslateInstance(thecenterx,thecentery);//The last transform is translation from origin back to original location

fliptransform.scale(-(1+stretcharray[currentimage]), 1.0);

fliptransform.translate(-thecenterx, -thecentery);//The first transform is from original location back to origin


at.concatenate(fliptransform);

big.setTransform(fliptransform);
shape=at.createTransformedShape(rectarray[currentimage]);//Returns a new Shape object defined by the geometry of
//the specified Shape after it has been transformed by this transform

arectarray=shape.getBounds2D();

flippedarray[currentimage]=!flippedarray[currentim
age];

}

big.setTransform(at);

big.drawImage(imagearray[currentimage], rectarray[currentimage].x,rectarray[currentimage].y,this);


}//end for loop


//System.out.println(rectarray[currentimage].x);
big.setTransform(oldat);//restore default transformation mode.
g2.drawImage(bi, 0, 0, this);




}





<code ends..>

any help appreciated !

Topic: java Previous Topic   Next Topic Topic: reg:java/j2ee

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use