// A custom panel for displaying dragon curves.
// CS 310, Spring 2008
import javax.swing.JPanel;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.Point2D;
import java.awt.geom.Line2D;
class DragonPanel
extends JPanel {
public
DragonPanel(DragonCurve dc) {
// Create a new panel that displays the given dragon curve.
super();
dragonCurve = dc;
}
public void
paintComponent(Graphics g) {
// Draw using the given graphics context the dragon curve associated with
// this panel.
super.paintComponent(g);
final Graphics2D g2 = (Graphics2D) g;
final Point2D points [] = dragonCurve.points();
for (int i = 0; i < points.length - 1; i++)
g2.draw(new Line2D.Float(points[i], points[i + 1]));
}
private final DragonCurve dragonCurve;
}
syntax highlighted by Code2HTML, v. 0.9.1