Skip to content

Instantly share code, notes, and snippets.

@cth
Created September 16, 2011 10:03
Show Gist options
  • Save cth/1221725 to your computer and use it in GitHub Desktop.
Save cth/1221725 to your computer and use it in GitHub Desktop.
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import javax.swing.JComponent;
public class RectangleComponent extends JComponent {
public void paintComponent(Graphics g) {
// Recover Graphics2D
Graphics2D g2 = (Graphics2D)g;
// Construct rectangle and draw
Rectangle box = new Rectangle(5,10,20,30);
g2.draw(box);
// Move 15 units to the right and 25 units down
box.translate(15,25);
// Draw moved rectangle
g2.draw(box);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment