You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
931 B
Java

Drawing Shapes
import java.awt.Graphics;
import javax.swing.*;
public class SwitchTest extends JApplet
{
int choice;
public void init()
{
String input;
input = JOptionPane.showInputDialog(
"Enter 1 to draw lines\n" +
"Enter 2 to draw rectangles\n" +
"Enter 3 to draw ovals\n" );
choice = Integer.parseInt( input );
}
public void paint( Graphics g )
{
for ( int i = 0; i < 10; i++ )
{
switch( choice )
{
case 1:
g.drawLine( 10, 10, 250, 10 + i * 10 );
break;
case 2:
g.drawRect( 10 + i * 10, 10 + i * 10, 50 + i * 10, 50 + i * 10 );
break;
case 3:
g.drawOval( 10 + i * 10, 10 + i * 10, 50 + i * 10, 50 + i * 10 );
break;
default:
JOptionPane.showMessageDialog( null, "Invalid value entered" );
} // end switch
} // end for
} // end paint()
} // end class SwitchTest