Here is some code that illustrates the problem. I hope some-one can help.
Thanks,
Ryan.
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.font.GlyphVector;
import java.awt.geom.Rectangle2D;
import javax.swing.JFrame;
public class AnimationTest extends JFrame implements Runnable {
/**
*
*/
private static final long serialVersionUID = 1L;
private double theRotate=0;
private double theTranslate=0;
private double theRotateRate=.1;
private double theTranslateRate=.1;
private double theMaxRotate=45;
private double theMaxTranslate=80;
/**
* @param args
*/
public static void main(String[] args) {
AnimationTest anim = new AnimationTest();
anim.start();
}
public AnimationTest() {
this.setSize(600, 600);
this.setVisible(true);
this.setBackground(Color.BLUE);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void start() {
Thread myThread = new Thread(this);
myThread.start();
}
public void paint(Graphics g) {
super.paint(g);
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g2.setStroke(new BasicStroke((float) 2));
g2.setColor(Color.BLACK);
g2.rotate(Math.toRadians(theRotate), 300, 300);
g2.translate(0, theTranslate);
Font defaultFont = g2.getFont();
Font myFont = defaultFont.deriveFont((float)20);
g2.setFont(myFont);
GlyphVector myGlyph =
myFont.createGlyphVector(g2.getFontRenderContext(), "Test
String 123");
Rectangle2D glyphRect = myGlyph.getVisualBounds();
g2.drawGlyphVector(myGlyph,
(float)(300-glyphRect.getCenterX()),(float)(300-glyphRect.getCenterY()));
g2.drawLine(280, 320, 320, 320);
}
public void run() {
long lastTime = System.currentTimeMillis();
long rotateSign=1;
long translateSign=1;
while (true) {
long currentTime = System.currentTimeMillis();
double deltaTimeSec = ((double)(currentTime -
lastTime))/1000;
if (Math.abs(theRotate) >= theMaxRotate) {
rotateSign = rotateSign *-1;
}
if (Math.abs(theTranslate) >= theMaxTranslate) {
translateSign = translateSign *-1;
}
theRotate = theRotate +
(deltaTimeSec*theRotateRate*rotateSign);
theTranslate = theTranslate +
(deltaTimeSec*theTranslateRate*translateSign);
repaint();
try {
Thread.sleep(80);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
[Message sent by forum member 'rpfitz' (rpfitz)]
http://forums.java.net/jive/thread.jspa?messageID=339057
===========================================================================
To unsubscribe, send email to [email protected] and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
[email protected] and include in the body of the message "help".