Created
September 16, 2011 10:03
-
-
Save cth/1221725 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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