Hi,
This application does everything but show the circles and rectangles even though visible is set to true.
package Shapes;
import java.awt.*;
import javax.swing.*;
public class ShapesTest {
public static void main (String []args){
String input = JOptionPane.showInputDialog
("Enter 1 to draw rectangles\n" +
"Enter 2 to draw ovals" );
int choice = Integer.parseInt( input );
Shapes panel = new Shapes( choice );
JFrame application = new JFrame();
application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE );
application.add( panel );
application.setSize( 500, 500 );
application.setVisible( true );
}
}
package Shapes;
import java.awt.*;
import javax.swing.*;
public class Shapes extends JPanel {
private int choice;
public Shapes(int UserChoice)
{
}
public void paintComponent( Graphics g){
super.paintComponent(g);
for (int i = 0; i < 10; i++)
{switch(choice)
{
case 1:g.drawRect(10 + i * 10 , 10 + i * 10,50 + i * 10,50 + i * 10);
break;
case 2:g.drawOval(10 + i * 10 , 10 + i * 10, 50 +i * 10,50 + i * 10);
} break;
}
}
}