12 ComponentsAndBeans
12 ComponentsAndBeans
ITDC0205
Web-based Java Programming
Components
▪ Components are :
1. self-contained,
2. reusable
software units that can be visually composed into
1. composite components,
2. applets, and
3. applications
using visual application builder tools.
What are Component Models?
▪ A component should:
– be modular
– introspection
– customization
– properties
– persistence
Java Beans contd..
Design Environment
❖ Provides Information used by builder tool to customize
the appearance and behavior of Beans.
Run-time Environment
❖ Provides information for other beans as well as
applications to use it.
▪ JDBC Connectivity
– JDBC provides a means to store Beans in a
database.
Java Features used in Beans contd..
▪ JAR Utility
– Used for packaging beans
▪ Reflection
– Used to know about the beans at run-time.
▪ Security
- Beans follows the same security model of Java.
Design Pattern
Other events:
Property changes in a bean
Any general-purpose notification
Delegation Event Model
eListener
Class fooey implements FooListner {
Void fooBarHappened (FooEvent fe) { }
Interface reference
}
Event Handling in AWT
▪ A listener object is an instance of a class that implements a
special interface called listener interface.
▪ java.util.eventObject
▪ java.awt.event
▪ java.awt.dnd
▪ javax.swing.event
Types of Events
▪ Low-level events:
– Tied to GUI component like focus, click, key-pressed, etc.
▪ Semantic events:
Used in a higher level where the user can customize the way of
representing event.
Low-level Events
EventObject
CompoentEvent
FocusEvent InputEvent
MouseEvent
Semantic Events
ActionEvent ItemEvent
AdjustmentEvent
Event Sources
▪ Sources are the objects which fire events.
▪ Sources maintain a list of listeners.
– keep track of added listeners
▪ Listeners can register and unregister themselves with a
source.
▪ Listener registration methods are prepended by add and
remove.
Event Listeners
▪ waits for events.
▪ Listener names end with Listener
User-defined events?
▪ Custom Events:
– Can create and define events.
User defined event objects extend the EventObject
class.
Event Delivery