Timeout2 (other files are same as before)

MyCanvas.java  [download]

import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import javax.swing.*;

public class MyCanvas extends JPanel {
    /**
     * Our basic shape, in canonical orientation, centered at 0, 0
     */
    private Rectangle2D rect = new Rectangle2D.Double (-25, -25, 50, 50); //*2 Save canonical rectangle

    private Main parent;

    public MyCanvas (Main parent) {
	this.parent = parent;
    }

    public void paintComponent (Graphics g) {
	super.paintComponent(g);
	Graphics2D g2 = (Graphics2D) g;

	int nboxes = parent.getFrame(); //*1 Redraw all boxes

	for (int ibox=0; ibox<nboxes; ibox++) { //*1
	    // First rotate about its center
	    AffineTransform trans = new AffineTransform (); //*3 Rotate first
	    trans.setToRotation (ibox/10.); //*3
	    Shape s = trans.createTransformedShape (rect); //*3

	    // Then move it somewhere
	    trans = new AffineTransform (); //*4 Then translate
	    trans.setToTranslation (100+2*ibox, 100+2*ibox); //*4
	    s = trans.createTransformedShape (s); //*4

	    g2.draw (s); //*5 Then draw result
	}
    }
}