Java Reference
In-Depth Information
Figure 21-3. LabelText bean
The code for LabelText is shown in Example 21-2 . Notice that it is serializable and uses the
set/get paradigm for most of its public methods. Most of the public set/get methods simply
delegate to the corresponding methods in the label or the text field. There isn't really a lot to
this bean, but it's a good example of aggregation, in addition to being a good example of a
bean.
Example 21-2. LabelText.java
// package com.darwinsys.swingui;
public
public class
class LabelText
LabelText extends
extends JPanel implements
implements java . io . Serializable {
private
private static
long serialVersionUID = - 8343040707105763298L ;
/** The label component */
protected
static final
final long
protected JLabel theLabel ;
/** The text field component */
protected
protected JTextField theTextField ;
/** The font to use */
protected
protected Font myFont ;
/** Construct the object with no initial values.
* To be usable as a JavaBean there must be a no-argument constructor.
*/
public
public LabelText () {
this
this ( "(LabelText)" , 12 );
}
/** Construct the object with the label and a default textfield size */
public
public LabelText ( String label ) {
this
this ( label , 12 );
}
/** Construct the object with given label and textfield size */
public
public LabelText ( String label , int
int numChars ) {
this
this ( label , numChars , null
null );
}
Search WWH ::




Custom Search