For example, the method invocation coded below reads the fourth element (or index value 3): aVarOfSupportedType = getAnArrayOfThisType( 3 ) ; The set method that writes an indexed property requires two arguments: the array position and the data to be written to the property. Here s the method header for a set method for the indexed property declared in the previous code listing: public void setAnArrayOfThisType( int arrIndex, SupportedType aVar ) For example, the method invocation in the following writes some data into the fourth array element: setAnArrayOfThisType( 3, aVarOfSupportedType ) ; Now that you ve seen the basic elements that comprise a bean, let s take a look at a simple bean. Creating a Simple Bean The code in Listing 6-1 shows a simple bean. Later in the chapter, this bean will be used in a JSP. Listing 6-1: The CalcBean class 1 package cbean ; //1 2 public class CalcBean { 3 /** 4 Calculator bean for Chapter 6 5 */ 6 private int operand1 = 0 ; //2 7 private int operand2 = 0 ; 8 private double result = 0 ; 9 private String operation = “” ; 10 11 //No-arg constructor for bean…. 12 public CalcBean() { } //3 13 14 //Get/Set methods follow 15 public void setOperand1( int op1 ) { //4 16 operand1 = op1 ; 17 } 18 public void setOperand2( int op2 ) { 19 operand2 = op2 ; 20 } 21 public void setOperation( String oper ) { 22 operation = oper ; 23 } 24 public void setResult( double aResult) { 25 result = aResult ; 26 } 27 public int getOperand1() { //5 28 return operand1 ; 29 } 30 public int getOperand2() { 31 return operand2 ; 32 } 33 public String getOperation() { 34 return operation; 35 } 36
Adult web hosting has rich experience in providing unique solutions for the customer’s needs, just check frontpage web hosting services.

Leave a Reply