Turn Desktop View Off
by Dinesh Thakur

 

import java.awt.*;

import java.awt.event.*;
import java.applet.*;
/* <APPLET CODE ="ShapeChooser.class" WIDTH=300 HEIGHT=200> </APPLET> */
public class ShapeChooser extends Applet implements ItemListener
  {
       Choice l;
       public void init()
            {
                 l=new Choice();
                 l.addItem("Square");
                 l.addItem("Arc");
                 l.addItem("Rectangle");
                 l.addItem("Ellipse");
                 l.addItem("Circle");
                 add(l);
                 l.addItemListener(this);
            }
                 public void itemStateChanged(ItemEvent e)
                   {
                       repaint();
                   }
                        public void paint(Graphics g)
                          {
                              if(l.getSelectedItem()=="Square")
                                {
                                   g.drawRect(100,100,50,50);
                              }
                                   if(l.getSelectedItem()=="Arc")
                                   {
                                      g.drawArc(100,100,70,70,0,90);
                                   }
                                         if(l.getSelectedItem()=="Rectangle")
                                        {
                                           g.drawRect(50,50,150,100);
                                        }
                                           if(l.getSelectedItem()=="Ellipse")
                                             {
                                                g.drawOval(100,100,30,70);
                                             }
                                                if(l.getSelectedItem()=="Circle")
                                                  {
                                                     g.drawOval(100,100,70,70);
                                                  }
                       }
    }                                  
                   

ShapeChooser in Java Example