First, a JavaBean must implement a sequentially-served interface, which supports the objects of this interface to store and rebuild their status. As follows:
Public Class SimpleBean Extends Canvas IMPLEments Serializable
Then we can define attributes and events for this JavaBean so that this JavaBean can have a certain function. As follows:
PRIVATE color beancolor = color.blue;
Then define the following two Accessor methods, these two methods need to be defined as public types:
Public color color getcolor () {
Return beancolor;
}
Public void setcolor (color newcolor) {
Beancolor = newcolor;
Repaint ();
}
At the same time, in order to link the beancolor attribute to the performance of JavaBean, you need to overrunate the Paint () method of the Canvas:
Public void paint (graphics g) {
G.SetColor (beancolor);
g.fillRect (0, 0, Width, Height);
}