You are here:   HomeJava ProgrammingAWT and AppletsShapeChooser in Java Example
by Dinesh Thakur Category: AWT and Applets

 

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





Subscribe To Free Daily Newsletter!

Get Free News Updates Delivered Directly To Your Inbox
About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular Computer Notes blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to contact us.



What's New and Popular





Popular Article