JavaBeans program development from introductory to proficient

Source: Internet
Author: User
Tags numeric value

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];
 }
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.