Do something similar like I did with the for loops.
Also you've made some errors like
QUOTE
if (choice == 1);
QUOTE
for(choice=100; choice<100; choice++);
p
QUOTE
ublic void paint(Graphics g)
should be outside of
init().
Here is what I did:
CODE
import javax.swing.JOptionPane;
import java.awt.*;
import javax.swing.*;
import java.applet.*;
/**
* create a shape then have it repeat 100x.
*
* @author (Simon Orazi)
* @version (26/05/07)
*/
public class Shapes extends JApplet
{
String input;
int choice;
public void 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);
//paint(Graphics g);
repaint();
}while (choice > 4);
}
public void paint(Graphics g)
{
switch (choice)
{
case 1:
if (choice == 1)
{g.drawLine(20,20,20,20);
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: break;
} g.drawString("Please enter 1, 2, 3 or 4", 20, 20);
}
public void drawLine(Graphics g)
{
g.drawLine(20, 20, 20, 80);
for(choice=100; choice<100; choice++){}
}
public void drawRectangle(Graphics g)
{
for(choice=0; choice<100; choice++){g.drawRect(20+choice*2, 20+choice, 80+choice, 80);repaint();}
}
public void drawOval(Graphics g)
{
g.drawOval(20, 20, 12, 75);
for(choice=100; choice<100; choice++){}
}
public void drawPolygon(Graphics g)
{
for(choice=0; choice<100; choice++)
{
int[] xCoords = {60+2*choice, 100+2*choice, 140+2*choice, 140+2*choice,
100+2*choice, 60+2*choice, 20+2*choice, 20+2*choice};
int[] yCoords = {20+2*choice, 20+2*choice, 60+2*choice, 100+2*choice,
140+2*choice, 140+2*choice, 100+2*choice, 60+2*choice};
g.drawPolygon(xCoords, yCoords, 8);
repaint();
}
}
}