a program in javabean to implement simple properties of a bean using simplebeaninfo class
Aim: write a program in javabean to implement simple properties of a bean using simplebeaninfo.
Program:
Box.java
package sunw.demo.Box;
import java.awt.*;
public class Box extends Canvas
{
private int
depth,height,width;
public Box()
{
setSize(120,30);
height=0;
depth=0;
width=0;
}
public int getDepth()
{
return depth;
}
public void
setDepth(int depth)
{
this.depth=depth;
}
public int
getHeight()
{
return height;
}
public void
setHeight(int height)
{
this.height=height;
}
public int
getWidth()
{
return width;
}
public void
setWidth(int width)
{
this.width=width;
}
public void
paint(Graphics g)
{
double
volume=(height*depth*width);
String
msg="Volume="+volume;
g.drawString(msg,10,10);
}
}
BoxBeanInfo.Java
package sunw.demo.Box;
import java.beans.*;
public class BoxBeanInfo extends SimpleBeanInfo
{
public
PropertyDescriptor[] getPropertyDescriptors()
{
try
{
PropertyDescriptor
height = new PropertyDescriptor("height",Box.class);
PropertyDescriptor width = new
PropertyDescriptor("width",Box.class);
PropertyDescriptor depth = new
PropertyDescriptor("depth",Box.class);
PropertyDescriptor pd[] = {height,width,depth};
return pd;
}
catch(Exception e)
{
}
return null;
}
}
Output:
Labels: Advanced Java Lab
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home