Properties of JavaBeans
The attribute of JavaBeans is a concept in the attribute of a general Java program, or the attribute of an object in all object-oriented programming languages, which is embodied in a program as a variable in a class. In JavaBeans design, according to the different functions of the attributes are subdivided into four categories: simple, Index, bound and constrained properties.
1. Simple Properties
A simple property represents a variable that accompanies a pair of get/set methods (the C language procedure or function is called a "method" in a Java program). The property name corresponds to the Get/set method name associated with the property. For example, if there is a setx and getx method, it implies a property named "X". If there is a method named ISX, it usually implies that "X" is a Boolean property (that is, the value of x is True or false). For example, in the following program:
public class alden1 extends Canvas {
string ourString= "Hello"; //属性名为ourString,类型为字符串
public alden1(){ //alden1()是alden1的构造函数,
与C++中构造函数的意义相同
setBackground(Color.red);
setForeground(Color.blue);
}
/* "set"属性*/
public void setString(String newString) {
ourString=newString;
}
/* "get"属性 */
public String getString() {
return ourString;
}
}
2. Indexed Properties
A indexed property represents an array value. Use the Set/get method that corresponds to this property to get the numeric value in the array. The property can also set or get the value of the entire array at one time. Cases:
public class alden2 extends Canvas {
int[] dataSet={1,2,3,4,5,6}; // dataSet是一个indexed属性
public alden2() {
setBackground(Color.red);
setForeground(Color.blue);
}
/* 设置整个数组 */
public void setDataSet(int[] x){
dataSet=x;
}
/* 设置数组中的单个元素值 */
public void setDataSet(int index, int x){
dataSet[index]=x;
}
/* 取得整个数组值 */
public int[] getDataSet(){
return dataSet;
}
/* 取得数组中的指定元素值 */
public int getDataSet(int x){
return dataSet[x];
}
}