JavaBeans - PowerPoint PPT Presentation

1 / 8
About This Presentation
Title:

JavaBeans

Description:

Can configure a component visually and discover at 'design ... packaged as a JAR file containing one or more classes. exposes properties and methods that other ... – PowerPoint PPT presentation

Number of Views:58
Avg rating:3.0/5.0
Slides: 9
Provided by: JamesB128
Category:
Tags: javabeans | ajar

less

Transcript and Presenter's Notes

Title: JavaBeans


1
JavaBeans
2
What We Want
  • Reusable components
  • Components don't depend on other components
  • Can configure a component visually and discover
    at "design time" the properites of the component
  • Example clock
  • we want a clock that can be easily added to any
    GUI application
  • want to set things such as font, time, background
    color

3
JavaBeans
  • A JavaBean is
  • a reusable component
  • packaged as a JAR file containing one or more
    classes
  • exposes properties and methods that other
    applications can use
  • has a Facade Class (like a main class) with a
    default, no parameter constructor
  • Facade class obeys the Java convention for
    get/set methods

4
JavaBean Details
  • A JavaBean must...
  • implement java.io.Serializable
  • contain a manifest that includes this value
  • JavaBean true
  • follow Java convention for naming get/set
    methods
  • private String name
  • public String getName() ...
  • public void setName(String name) ...

5
4 Kinds of Properties
  • simple - property has a single value that is
    independent of changes to other properties
  • indexed - (typically an array) a property that
    has many values, indexed by something
  • bound - a property for which other Beans need to
    be notified whenever a change occurs
  • constrained - the value of the property must be
    verified by another bean.

6
Simple Property
  • A title
  • A boolean, read-only property

private String title public String getTitle( )
return title public String setTitle( String
title ) this.title title
private boolean full public boolean isFull( )
return full
7
Indexed Property
  • Indexed properties need 2 get and 2 set methods

/ course grades / private String grade /
get one grade / public String getGrade(int index
) return gradeindex / set one grade
/ public void setGrade( index index, String
value ) gradeindex value / get all
grades / public String getGrade( ) return
grades / set all grades / public void
setGrade(String newgrades) ...
8
Bound Properties
  • These are what make JavaBeans interesting
  • Support "observers" using the PropertyChangeListen
    er interface

PropertyChangeListener propertyChange( e
PropertyChangeEvent )
PropertyChangeSupport - listeners Collection -
properties String many methods
addPropertyChangeListener(this)
YourJavaBean -setProperty( value )
firePropertyChange( "property", old, new )
AnObserverClass propertyChange( ... ) ...
Write a Comment
User Comments (0)
About PowerShow.com