applet loops
i got the following code:
import java.awt.*;
import javax.swing.*;
publicclass Shapesextends JApplet
{
privateint shapeSelect;
privateint cont;
publicvoid init()
{
shapeSelect = Integer.parseInt(JOptionPane.showInputDialog(" Enter 1 to draw lines "
+" \n Enter 2 to draw rectangles "
+" \n Enter 3 to draw ovals "
+" \n Enter 4 to draw triangles"));
}
publicvoid paint(Graphics shape)
{
int x1 = 0;
int y1 = 0;
int x2 = 10;
int y2 = 10;
int x3 = 40;
int y3 = 10;
int[] xCoordinates ={0, 175, 175};
int[] yCoordinates ={20, 0, 20};
for(int index = 0; index <= 100; index++)
{
switch(shapeSelect)
{
case 1:
shape.drawLine(x1,y1,x2,y2);
x1 = x1 + 5;
y1 = y1 + 10;
x2 = x2 + 15;
y2 = y2 + 20;
break;
case 2:
shape.drawRect(x1,y1,x3,y3);
x1 = x1 + 5;
y1 = y1 + 5;
x3 = x3 + 10;
y3 = y3 + 10;
break;
case 3:
shape.drawOval(x1,y1,x3,y3);
x1 = x1 + 5;
y1 = y1 + 5;
x3 = x3 + 10;
y3 = y3 + 10;
break;
case 4:
shape.drawPolygon (xCoordinates,yCoordinates,xCoordinates.length);
break;
default:
Font errorMessage =new Font("SansSerif",Font.BOLD + Font.ITALIC,38);
shape.setFont(errorMessage);
shape.setColor(Color.blue);
shape.drawString("ERROR: Incorrect Entry!",38,200);
}
}
}
}
Now you see in case 4, am drawing a triangle how do i loop its like the other so it produces multiple triangles in different locations?
Message was edited by:
The_One

