0% found this document useful (0 votes)
5 views3 pages

Dynamic Color Bean Creation Guide

The document describes the creation of a simple visual bean in Java that can display either a square or a circle based on a boolean property. The bean changes color dynamically with each mouse click and can also change color through a property window. It includes the Java code for the bean and the steps to compile and package it into a JAR file for use in a bean development kit.

Uploaded by

a9242592425
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

Dynamic Color Bean Creation Guide

The document describes the creation of a simple visual bean in Java that can display either a square or a circle based on a boolean property. The bean changes color dynamically with each mouse click and can also change color through a property window. It includes the Java code for the bean and the steps to compile and package it into a JAR file for use in a bean development kit.

Uploaded by

a9242592425
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Task 6: Visual Beans

Create a simple visual bean with an area filled with a color.

The shape of the area depends on the property shape. If it is set to true then the shape of the area is
Square and it is Circle, if it is false.

The color of the area should be changed dynamically for every mouse click. The color should also be
changed if we change the color in the “property window “.

[Link]

import [Link].*;
import [Link].*;
import [Link]; // Crucial for JavaBeans

public class Colors extends Canvas implements Serializable


{
transient private Color color;
private boolean rectangular;
public Colors()
{
addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent me)
{
change();
}
});
rectangular = false;
setSize(200, 100);
change();
}
public boolean getRectangular()
{
return rectangular;
}
public void setRectangular(boolean flag)
{
[Link] = flag;
repaint();
}
public void change()
{
color = randomColor();
repaint();
}
private Color randomColor()
{
int r = (int)(255*[Link]());
int g = (int)(255*[Link]());
int b = (int)(255*[Link]());
return new Color(r, g, b);
}
public void paint(Graphics g)
{
Dimension d = getSize();
int h = [Link];
int w = [Link];
[Link](color);
if(rectangular)
{
[Link](0, 0, w-1, h-1);
}
else
{
[Link](0, 0, w-1, h-1);
}
}
}

[Link]

Name: [Link]

Java-Bean: True

Compilation steps:

[Link] [Link] file using notepad and place in one folder

[Link] [Link] file using notepad and place this also in same folder

[Link] java file using javac

4. .class file is created in your folder

5. In order to create jar file open cmd prompt, go to your folder

C:> jar -cfm [Link] [Link] Colors*.class

6. It will create jar file in your folder

[Link] this jar in BDK>beans>jars

[Link] come to BDK >beans >beanbox and click on [Link]


OUTPUT:

You might also like