Escolar Documentos
Profissional Documentos
Cultura Documentos
Search Documents
/ 127
Download this Document for Free represented by a nonpublic instance variable. It can be read-write, read-only, or write-only. There are four different types of properties: Simple As the name implies, simple properties
represent the simplest of thefour. To create a property, define a pair of set/get routines. Whatever name usedin the pair of routines, becomes the property name Indexed An indexed property is for when a single property can hold an array of values. The design pattern for
these properties is: public void setPropertyName (PropertyType[] list) public void setPropertyName (PropertyType element, int position) public PropertyType[] getPropertyName () public PropertyType getPropertyName (int position) Bound
A bean that has the bound property generates an event when the property is changed. The event is of type propertyChangeEvent and is sent toobjects that previously registered an interest in receiveing such notifications. Inorder for the notific ation to happen, you
need to maintain a w atch list for PropertyChangeEvent s via the PropertyChangeSuppor t class. First,you have to create a list of listeners to maintain: private PropertyChangeSuppor t changes =new PropertyChangeSuppor t (this);And then, you have to maintain the list: public void
addPropertyChangeList ener (PropertyChangeListen er p) {changes.addProperty ChangeListener (p);} public void removePropertyChange Listener (PropertyChangeListen er p) {changes.removePrope rtyChangeListener (p);} Constrained -
Constrained properties are similar to bound properties. In additionto maintaining a list of PropertyChangeList eners, the Bean maintains a list of Prasad V. Potluri Siddhartha Institute of Technology36 VetoableChangeListene r
s. Then, prior to the Bean changing a propertyvalue, it asks the VetoableChangeLi steners if its okay. If i t isn't, the listener thr ows a PropertyVetoException , which you declare the set routine tothrow. Methods Bean methods are av ailable for anyone to
call by just making e ach public.However, you can restrict which methods are visible to the Bean builder/integration tool by providing a getMethodDescriptor s method along with your Bean's BeanInfo. EveryBean can provide a supporting BeanInfo class to customize a
Bean's appearance to anintegration tool. Procedural Steps to create a Java-Bean: 1)Creating a directory- Create a new directory in C:\b eans\demo\sunw\dem o witha new folder name colors2)Create a java source file3)Compile the java source file4)Create a manifest file colors.mft in the
directory called as C:\beans\demo5)Creat e a jar file- to create a jar file type the following command in the command prompt jar cfm ..\jars\colors.jar colors.mft sunw\demo\ colors\*.class6 ) S t a r t t h e B D K 7)Check whether the colors bean is placed in toolbox or not.
PROGRAM: package sunw.demo.colors;impo rt java.awt.*;import java.awt.event.*;public class Colors extends Canvas{transient private Color color;private boolean rectangular;public Colors() Prasad V. Potluri Siddhartha Institute of Technology37
{addMouseListener(ne w MouseAdapter() {public void mousePressed(MouseE vent me) {change(); }});rectang ular=false;setSize(100, 100);change();}public boolean getRectangular() {return rectangular;}public void setRectangular(boolean
flag) {this.rectangular=flag; repaint();}public void change() {color=randomColor();r epaint();}private Color randomColor(){int r=(i nt) (255*Math.random());in t g=(int) (255*Math.random());in t b=(int) (255*Math.random());r eturn new
Color(r,g,b);}public void paint(Graphics g) Prasad V. Potluri Siddhartha Institute of Technology38 {Dimension d=getSize();int h=d.height;int w=d.width;g.setColor(c olor);if(rectangular) {g.fillRect(0,0,w-1,h1);}else{g.fillOval(0,0, w-1,h-1);}}} OUTPUT:
RESULT: Thus the colors bean is created successfully. Program 2:Visual Beans (program
2)Convert.javapackag e sunw.demo.convert;i mport java.awt.*;import java.awt.event.*;publ ic class convert extends Canvas{private double dollars=0.0;private double rupees=0.0;private double dollarvalue=0.0;publi
c convert() {setSize(100,1000);} public double getDollars() Prasad V. Potluri Siddhartha Institute of Technology40
{return dollars;}public void setDollars(double value) {this.dollars=value;} public void setRupees(double value) {this.rupees=value;} public double getRupees(){return rupees;}public void change() {dollarvalue= value();repaint();}pri
vate double value() {return rupees*dollars;}publi c void paint(Graphics g) {g.setColor(Color.red );g.drawString(String .valueOf(dollarvalue), 10,10);}}Convert.mf Name: sunw/demo/convert/c onvert.classJavaBean: True ( press Enter)(Carriage return compulsory)
Prasad V. Potluri Siddhartha Institute of Technology41 JNTU WT RECORD LAB MANUAL Download this Document for FreePrintMobileCollections Report Document Info and Rating WT Follow syam_5491983
p.
p.
2. p.
p.
p. 3. p.
p.
p. 4. p.
p.
p.
5. p.
p.
p. 6. p.
p.
p. 7. p.
p.
p.
8. p.
p.
36 p.
22 p. 2. 3 p.
28 p.
Add a Comment
Upload a Document Search Documents Follow Us! scribd.com/scribd twitter.com/scribd facebook.com/scribd About Press Blog
Partners Scribd 101 Web Stuff Support FAQ Developers / API Jobs Terms Copyright Privacy Copyright 2011 Scribd Inc. Language:
English