Docstoc

CREATE A JAVA BEAN TO DRAW VARIOUS GRAPHICAL SHAPES USING BDK OR WITHOUT BDK

Document Sample
CREATE A JAVA BEAN TO DRAW VARIOUS GRAPHICAL SHAPES USING BDK OR WITHOUT BDK Powered By Docstoc
					   CREATE A JAVA BEAN TO DRAW VARIOUS GRAPHICAL
         SHAPES USING BDK OR WITHOUT BDK
AIM:
       To Create a Java Bean to draw various graphical shapes using BDK or without
Using BDK.
DESCRIPTION:
   1. Start the Process.
   2. Set the classpath for java as given below

                  C:\devi\bean>set path=%path%;c:\j2sdk1.4.1\bin;

   3. Write the Source code as given below.
PROGRAM:
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
/*<applet code="shapes" width=400 height=400></applet>*/
public class shapes extends Applet implements ActionListener
{
    List list;
    Label l1;
    Font f;
    public void init()
    {
      Panel p1=new Panel();
      Color c1=new Color(255,100,230);
      setForeground(c1);

     f=new Font("Monospaced",Font.BOLD,20);
     setFont(f);
     l1=new Label("D R A W I N G V A R I O U S G R A P H I C A L S H A P E
S",Label.CENTER);
     p1.add(l1);
     add(p1,"NORTH");

     Panel p2=new Panel();
     list=new List(3,false);
     list.add("Line");
     list.add("Circle");
     list.add("Ellipse");
     list.add("Arc");
     list.add("Polygon");
     list.add("Rectangle");
     list.add("Rounded Rectangle");
     list.add("Filled Circle");
     list.add("Filled Ellipse");
   list.add("Filled Arc");
   list.add("Filled Polygon");
   list.add("Filled Rectangle");
   list.add("Filled Rounded Rectangle");
   p2.add(list);
   add(p2,"CENTER");
   list.addActionListener(this);      }
 public void actionPerformed(ActionEvent ae)        {
 repaint();      }
public void paint(Graphics g) {
  int i;
  Color c1=new Color(255,120,130);
  Color c2=new Color(100,255,100);
  Color c3=new Color(100,100,255);
  Color c4=new Color(255,120,130);
  Color c5=new Color(100,255,100);
  Color c6=new Color(100,100,255);
  if (list.getSelectedIndex()==0)       {
     g.setColor(c1);
     g.drawLine(150,150,200,250);         }
  if (list.getSelectedIndex()==1)       {
     g.setColor(c2);
     g.drawOval(150,150,190,190);         }
  if (list.getSelectedIndex()==2)
  {          g.setColor(c3);       g.drawOval(290,100,190,130);  }
  if (list.getSelectedIndex()==3)       {
     g.setColor(c4);
     g.drawArc(100,140,170,170,0,120);        }
  if (list.getSelectedIndex()==4)       {
    g.setColor(c5);
    int x[]={130,400,130,300,130};
    int y[]={130,130,300,400,130};
     g.drawPolygon(x,y,5);       }
  if (list.getSelectedIndex()==5) {
    g.setColor(Color.cyan);
     g.drawRect(100,100,160,150); }
  if (list.getSelectedIndex()==6) {
    g.setColor(Color.blue) g.drawRoundRect(190,110,160,150,85,85);
   }
  if (list.getSelectedIndex()==7)
  {
     g.setColor(c2);
     g.fillOval(150,150,190,190);
   }
  if (list.getSelectedIndex()==8) {
     g.setColor(c3);
        g.fillOval(290,100,190,130); }
     if (list.getSelectedIndex()==9) {
        g.setColor(c4);
        g.fillArc(100,140,170,170,0,120); }
     if (list.getSelectedIndex()==10) {
       g.setColor(c5);
       int x[]={130,400,130,300,130};
       int y[]={130,130,300,400,130};
        g.fillPolygon(x,y,5);            }
     if (list.getSelectedIndex()==11)
     {
       g.setColor(Color.cyan);
        g.fillRect(100,100,160,150);
      }

     if (list.getSelectedIndex()==12)
     {

       g.setColor(Color.blue);
        g.fillRoundRect(190,110,160,150,85,85);
      }}}

    4. Save the above file as shapes. java
    5. compile the file as
        C:\devi\bean>javac shapes.java
C:\devi\bean>
    6. If BDK is not used then execute the file as
       C:\devi\bean>appletviewer shapes.java
    7. Stop the process

				
DOCUMENT INFO
Shared By:
Categories:
Stats:
views:41
posted:9/1/2012
language:English
pages:3
Description: web designing notes for all BE/B-tech students