01: import java.awt.Graphics;
02: import java.awt.Graphics2D;
03: import java.awt.Rectangle;
04: import javax.swing.JPanel;
05: import javax.swing.JComponent;
06: 
07: /**
08:    A component that draws two rectangles.
09: */
10: public class RectangleComponent extends JComponent
11: {  
12:    public void paintComponent(Graphics g)
13:    {  
14:       // Recover Graphics2D
15:       Graphics2D g2 = (Graphics2D) g;
16: 
17:       // Construct a rectangle and draw it
18:       Rectangle box = new Rectangle(5, 10, 20, 30);
19:       g2.draw(box);
20: 
21:       // Move rectangle 15 units to the right and 25 units down
22:       box.translate(15, 25);
23: 
24:       // Draw moved rectangle
25:       g2.draw(box);
26:    }
27: }