Squid.java import java.awt.Graphics2D;
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
public class Squid
{
/**
Constructs a Squid (square inside diamond).
@param aCenter the center point
@param aRadius, the distance from the center to the corner points
of the diamond
*/
public Squid(Point2D.Double aCenter, double aRadius)
{
center = aCenter;
radius = aRadius;
}
public void draw(Graphics2D g2)
{
// your work here
}
private Point2D.Double center;
private double radius;
}
Use the following files:
SquidComponent.java
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.Point2D;
import javax.swing.JComponent;
public class SquidComponent extends JComponent
{
public void paintComponent(Graphics g)
{
Graphics2D g2 = (Graphics2D) g;
Squid s = new Squid(new Point2D.Double(200, 200), 200);
s.draw(g2);
}
}
SquidViewer.java
import javax.swing.*;
public class SquidViewer
{
public static void main(String[] args)
{
JFrame frame = new JFrame();
frame.setSize(450, 450);
frame.setTitle("A recursive squid");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
SquidComponent component = new SquidComponent();
frame.add(component);
frame.setVisible(true);
}
}