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



AIM:
     To create a java Bean to draw graphical shapes and display it using BDK       

PROCDURE:
Ø      Start the program.
Ø      Create a java file for drawing rectangle.
Ø      Create a manifeast.
Ø      Create jar file and load it in to the bean window.
Ø      Display the shape.
Ø      Terminate the program.

PROGRAM:

SimpleBean.java

// Comment
import java.awt.*;
import java.io.*;
public class SimpleBean extends Canvas implements Serializable
{
private Color myColor;
public SimpleBean()
{
myColor=Color.white;
setBackground (myColor);
}
public Color getmyColor() {return myColor;}
public void setmyColor(Color c){myColor=c;}
public void paint(Graphics g)
{
g.setColor(myColor);
g.fillRect(0,0,getSize().width,getSize().height);
}         
public Dimension getPreferredSize()
{
return new Dimension(50,50);}
public Dimension getMinimumSize()
{
return getPreferredSize();
}
}

BeanTest.java
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.beans.*;
public class BeanTest extends Applet
{
SimpleBean bean;
public static void main(String args[])
{
Frame f=new Frame("BeanTest-SimpleBean");
BeanTest me=new BeanTest();
f.add(me,"Center");
me.init();
me.start();
f.pack ();
f.addWindowListener (new WindowAdapter ()
{
public void windowClosing(WindowEvent we)
{
System.exit(0);
}
}
);
f.setVisible (true);
}
public void init ()
{
SetBackground (Color.lightGray);
add (new Label("BeanTest-SimpleBean"));
try
{
bean= (SimpleBean)Beans. instantiate (null,"SimpleBean");
add(bean);
}
catch(Exception e)
{
add(new Label("cannot instantiate the Bean!"));
e.printStackTrace();
}
}
} 
SimpleBean.mf Name: SimpleBean.class Java-Bean: True

Screen Shot
raja P Web Developer

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...