developing graphical objects
I am trying to create an applet that displays a Dialog box giving the user a choice of shapes to draw and in the applets paint() method i need to have a for loop that loops at least 100 times. Inside the loop i need a switch statement that draws the line rectangle oval or polygon depending on the users choice. With each repeat of the loop, the shape drawn should be positioned in a slightly different place to create an interesting pattern. If an invalid number is entered, the default case should use the drawString() method to write an error message.
i do not understand how to repeat the object 100x to create the pattern, below is how far i have made it so far.
import javax.swing.JOptionPane;
import java.awt.*;
import javax.swing.*;
/**
* create a shape then have it repeat 100x.
*
* @author (Simon Orazi)
* @version (26/05/07)
*/
publicclass Shapesextends JApplet
{
String input;
int choice;
publicvoid init()
{
do
{
input = JOptionPane.showInputDialog("Enter 1 to draw lines\n" +"Enter 2 to draw rectangles\n" +
"Enter 3 to draw ovals\n" +"Enter 4 to draw polygons");
choice = Integer.parseInt(input);
publicvoid paint(Graphics g)
{
switch (choice)
{
case 1:
if (choice == 1);
drawLine(g);
break;
case 2:
if (choice == 2);
drawRectangle(g);
break;
case 3:
if (choice == 3);
drawOval(g);
break;
case 4:
if (choice == 4);
drawPolygon(g);
break;
default:
}g.drawString("Please enter 1, 2, 3 or 4", 20, 20);
}while (choice > 4);
}
publicvoid drawLine(Graphics g)
{
g.drawLine(20, 20, 20, 80);
for(choice=100; choice<100; choice++);
}
publicvoid drawRectangle(Graphics g)
{
g.drawRect(20, 20, 80, 80);
for(choice=100; choice<100; choice++);
}
publicvoid drawOval(Graphics g)
{
g.drawOval(20, 20, 12, 75);
for(choice=100; choice<100; choice++);
}
publicvoid drawPolygon(Graphics g)
{
int[] xCoords ={60, 100, 140, 140,
100, 60, 20, 20};
int[] yCoords ={20, 20, 60, 100,
140, 140, 100, 60};
g.drawPolygon(xCoords, yCoords, 8);
for(choice=100; choice<100; choice++);
}
}

