Friday, October 14, 2016

a program to demonstrate the Bound properties of a bean .

Aim: write a program to demonstrate the Bound properties of a bean .

Program:

import java.awt.*;
import java.awt.event.*;
public class Colors extends Canvas
{
            transient private Color color;
            private boolean rectangular;
            public Colors()
            {
                        addMouseListener(new MouseAdapter()
                        {
                                    public void mousePressed(MouseEvent me)
                                    {
                                                change();
                                    }
                        });
                        setSize(200,100);
                        rectangular=false;
                        change();
            }
            public boolean getRectangular()
            {
                        return rectangular;
            }
            public void setRectangular(boolean flag)
            {
                        this.rectangular=flag;
                        repaint();
            }
            public void change()
            {
                        color=randomColor();
                        repaint();
            }
            public Color randomColor()
            {
                        int r=(int)(255*Math.random());
                        int g=(int)(255*Math.random());
                        int b=(int)(255*Math.random());
                        return(new Color(r,g,b));
            }
            public void paint(Graphics g)
            {
                        Dimension d=getSize();
                        int w=d.width;
                        int h=d.height;
                        g.setColor(color);
                        if(rectangular)
                        g.fillRect(0,0,w-1,h-1);
                        else
                        g.fillOval(0,0,w-1,h-1);
            }
}


For the above program you will get colors bean.
follow the following steps

1. start the BDK and create an instance of the Colors Bean in the BeanBox window.
2. Create an instance of the TickTock Bean. The Properties window should show one
property for this component. It is “Interval” and its initial value is 5. This represents
the number of seconds that elapse between property change events generated by the
TickTock Bean. Change the value to 1.






Now you need to map events generated by the TickTock Bean into method calls on
the Colors Bean. Follow these steps:

1. Go to the menu bar of the BeanBox and select Edit | Events | propertyChange | propertyChange. You should now see a line extending from the button to
the cursor.
2. Move the cursor so that it is inside the Colors Bean display area, and click the left mouse button. You should see the Event Target Dialog dialog box.
3. The dialog box allows you to choose a method that should be invoked when this event occurs. Select the entry labeled “change” and click the OK button.
You should see a message box appear very briefly, stating that the tool is “Generating and compiling adaptor class.”
You should now see the color of your component change every second.



Labels:

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home