I have an assignment to create Random Shapes by creating a method randomShape that randomly generates objects implementing the Shape interface. This is what I have so far and don't know where to go from here.
import javax.swing.JFrame;
public class RandomShapeViewer
{
public static void main(String[] args)
{
JFrame frame = new JFrame();
final int FRAME_WIDTH = 300;
final int FRAME_HEIGHT = 400;
frame.setSize(FRAME_WIDTH, FRAME_HEIGHT);
frame.setTitle("RandomShapeViewer");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
RandomShapesComponent component = new RandomShapesCOmponent();
frame.add(component);
frame.setVisible(true);
}
}
import javax.swing.JComponent;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Shape;
public class RandomShapesCOmponent extends JComponent
{
public void paintComponent(Graphics g)
{
Graphics2D g2 = (Graphics2D) g;
RandomShapeGenerator r =
new RandomShapeGenerator(getWidth(), getHeight());
for(int i = 1; i <= 10; i++)
g2.draw(r.randomShape());
}
class randomShape implements Shape
{
}
}