0

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
	{
		
	}
}
2
Contributors
1
Reply
3
Views
5 Years
Discussion Span
Last Post by JamesCherrill
0

Maybe this could be as simple as working with a few known classes that implement Shape (Rectangle, RoundRectangle2D, Ellipse2D, Polygon...), then randomly picking one of those shapes and randomly setting its parameters?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.