Mari Göransson - KaU - Datavetenskap - DAVD11 1 Java Beans - Events and Properties -

Slides:



Advertisements
Similar presentations
1 Event Listeners Some Events and Their Associated Event Listeners Act that Results in the EventListener Type User clicks a button, presses Enter while.
Advertisements

JSF Portlet Backing Beans and UI Components Copyright © Liferay, Inc. All Rights Reserved. No material may be reproduced electronically or in.
Copyright © 2001 Qusay H. Mahmoud JavaBeans An introduction to component-based development in general Introduction to JavaBeans – Java components – client-side.
Mari Göransson - KaU - Datavetenskap - DAVD11 1 Java Event Handling --
Recitation 11 November 11, Today’s Goals:  Automatic refresh  Learn and apply the Observer pattern.
Spring 2010ACS-3913 Ron McFadyen1 Weather Station Page 39+ In this application, weather station devices supply data to a weather data object. As the data.
Java Beans & Serialization CS-328 Dick Steflik. Java Beans Java based component technology –originally developed to provide java with a component technology.
Listener Interfaces  A mechanism for registering handlers that respond to external events  Motivation: Develop a Canvas class that:  supports drawing.
JavaBeans introduction Klaus-Peter Heidrich for the University of Karlstad Inst. for Information Technology Dept. of Computer Science.
1 org.eclipse.ui.texteditor-api l Provides a framework for text editors obeying to the desktop rules. org.eclipse.ui.texteditor.
JAVA BEANS (Unit-V) K.Phani Sirisha.
Java Beans.  Java offers software component development through java Beans  Java Beans are based on a software component model for java.  The model.
CSC 520 – Advanced Object Oriented Programming, Fall, 2010 Thursday, September 2, Week 4 Design by Contract, Java Exceptions, Eventing, Finding the Classes,
Last update October 18, 2004 Advanced Programming 2004 Java Beans.
Introduction to Java Beans by Anders Børjesson. Introduction to JavaBeans2 JavaBeans components JavaBeans are the components in the Java environment Many.
JavaBeans Components. To understand JavaBeans…  Proficient experience with the Java language required  Knowledge of classes and interfaces  Object-Oriented.
TM Introduction to JavaBeans™ Dimitrios Psarros Questra Consulting (716) x225.
Comparing JavaBeans and OSGi Towards an Integration of Two Complementary Component Models HUMBERTO CERVANTES JEAN-MARIE FAVRE 09/02.
CG0165: Advanced Applications Development in Java Michael Brockway Sajjad Shami Week 5: JavaBeans Northumbria University School of Computing, Engineering.
Java Event Handling CSIS 3701: Advanced Object Oriented Programming.
CS 350 – Software Design The Observer Pattern – Chapter 18 Let’s expand the case study to include new features: Sending a welcome letter to new customers.
1 First BlueJ Day, Houston, Texas, 1st March 2006 Writing BlueJ Extensions Ian Utting University of Kent.
Java Programming: Advanced Topics 1 JavaBeans Chapter 8.
Introduction to Component-Based Engineering Howard Abrams
Components Components are specialized self contained Software entities that can be replicated, Customized and inserted into applications. Components come.
Java Bean Definition “A Java Bean is a reusable software component that can be manipulated visually in a builder tool.”
Chapter 12 1 TOPIC 13B l Buttons and Action Listeners Window Interfaces Using Swing Objects.
Copyright © 2002, Systems and Computer Engineering, Carleton University EventModel.ppt * Object-Oriented Software Development Part 17.
Introduction to Java Beans CIS 421 Web-based Java Programming.
First Bean Compose SimpleBean Demo Simple Bean Discuss Manifest and Jar Add Properties to SimpleBean.
Observer design pattern A closer look at INotifyPropertyChanged, INotifyPropertyChanging and ObservableCollection Observer design pattern1.
First Bean Compose SimpleBean Demo Simple Bean Discuss Manifest and Jar Add Properties to SimpleBean.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 27 JavaBeans and.
Java Beans. Definitions A reusable software component that can be manipulated visually in a ‘builder tool’. (from JavaBean Specification) The JavaBeans.
Graphics in Java Dr. Andrew Wallace PhD BEng(hons) EurIng
Advanced Java Session 4 New York University School of Continuing and Professional Studies.
Introduction to Java Beans by Anders Børjesson. Introduction to JavaBeans2 JavaBeans components JavaBeans are the components in the Java environment –COM.
JavaBean Component Java bean is a reusable software component that can be manipulated visually in a builder tool Graphic bean and Non-graphic bean Javabean.
Introduction to Java Beans From Anders Børjesson.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 32 JavaBeans and Bean.
Lorenz: Visitor Beans: An Aspect-Oriented Pattern Aspect-oriented pattern: describes a solution to a tangling problem in a particular context.
1 Java Server Pages A Java Server Page is a file consisting of HTML or XML markup into which special tags and code blocks are inserted When the page is.
Java Beans THETOPPERSWAY.COM. Contents What is a Java Bean? Advantages Properties Bean Developers Kit (BDK) What makes Bean possible? Support for Java.
Java Swing, Events Readings: Just Java 2: Chap 19 & 21, or Eckel’s Thinking in Java: Chap 14 Slide credits to CMPUT 301, Department of Computing Science.
April 20, 1998CS102-02Lecture 4-1 A Method to the Madness CS Lecture 4-1 Java's Work Horses.
Object orientation and Packaging in Java Object Orientation and Packaging Introduction: After completing this chapter, you will be able to identify.
Java Beans - Basics CIS 421 Web-based Java Programming.
Java - hello world example public class HelloWorld { public static void main (String args[]) { System.out.println("Hello World"); }
JavaBeans Profile Domingos Neto Marcos Aurélio
Introduction to Inversion Of Control (IOC). IOC Definition (based on Wikipedia)  Consider the way in which an object obtains references to its dependencies.
Chapter 32 JavaBeans and Bean Events
Events and Event Handling
Chapter 36 JavaBeans and Bean Events
Javabeans for dummies.
JavaBeans* ICS 123 Richard N. Taylor & Eric M. Dashofy UC Irvine
Java Beans Sagun Dhakhwa.
Observer Design Pattern
Java FX.
JavaBeans and JSP CS-422.
Introduction to Java Bean
Miscellaneous Topics #6: Polygons GUI Components and Event Handlers
Introduction to Java Bean
Persistence & Bean Properties
תירגול 9 אובייקטים.
Pre-assessment Questions
Advanced ProgramMING Practices
Properties and Collections
Knowledge Byte In this section, you will learn about:
Advanced ProgramMING Practices
Java Programming: Advanced Topics
Presentation transcript:

Mari Göransson - KaU - Datavetenskap - DAVD11 1 Java Beans - Events and Properties -

Mari Göransson - KaU - Datavetenskap - DAVD11 2 Properties Simple properties Bound properties Constrained properties

Mari Göransson - KaU - Datavetenskap - DAVD11 3 Simple Properties Named attributes that can be read or written by calling appropriate methods on the JavaBean E.g. Getter: String getTextValue() E.g. Setter: setTextValue(String) -> property is textValue

Mari Göransson - KaU - Datavetenskap - DAVD11 4 Bound Properties When changes to the property are of interest to other beans. The component provides a change notification service: public void addPropertyChangeListener(PropertyChangeListener l) public void removePropertyChangeListener(PropertyChangeListener l)

Mari Göransson - KaU - Datavetenskap - DAVD11 5 Bound Properties Mostly, the listeners are handled by the class PropertyChangeSupport. When a change occurs a PropertyChangeEvent is fired containing the old and new value.

Mari Göransson - KaU - Datavetenskap - DAVD11 6 Constrained Properties When a bean (listener) may want to validate a change and reject the change if it is inappropriate.

Mari Göransson - KaU - Datavetenskap - DAVD11 7 Event-mechanism models The basic event-delegation mechanism is a specialized version of the Observer pattern. JavaBeans introduced another version of the observer pattern; the property change listener.

Mari Göransson - KaU - Datavetenskap - DAVD11 8 Java Event Handling and the Observer Pattern The observer pattern is used when an object wants to be informed of a state change in another object. In java, the observer object listens for events to happen.

Mari Göransson - KaU - Datavetenskap - DAVD11 9 Java Event Handling and the Observer Pattern

Mari Göransson - KaU - Datavetenskap - DAVD11 10 Java Event Handling and the Observer Pattern

Mari Göransson - KaU - Datavetenskap - DAVD11 11 JavaBeans and Events

Mari Göransson - KaU - Datavetenskap - DAVD11 12 Property Change Listeners as Observers This is a closer representation of the Observer pattern: each observer listens for changes to an attribute in the subject and is informed when the state changes.

Mari Göransson - KaU - Datavetenskap - DAVD11 13 PropertyChangeListeners The registered set of listeners is managed within the PropertyChangeSupport class. When the watched property changes the support class informs all registered listeners of the old and new value.

Mari Göransson - KaU - Datavetenskap - DAVD11 14 Swing The Swing components have a similar event model where many of their properties are bound.

Mari Göransson - KaU - Datavetenskap - DAVD11 15 Bound Property Structure

Mari Göransson - KaU - Datavetenskap - DAVD11 16 Implementing Bound Property Support Import the java.beans package. This gives you access to the PropertyChangeSupport class.

Mari Göransson - KaU - Datavetenskap - DAVD11 17 Implementing Bound Property Support Instantiate a PropertyChangeSupport object: private PropertyChangeSupport changes = new PropertyChangeSupport(this); This object maintains the property change listener list and fires property change events on your behalf.

Mari Göransson - KaU - Datavetenskap - DAVD11 18 Implementing Bound Property Support Implement methods to maintain the property change listener list. Since PropertyChangeSupport implements these methods, you merely wrap calls to the property-change support object's methods:

Mari Göransson - KaU - Datavetenskap - DAVD11 19 Implementing Bound Property Support public void addPropertyChangeListener( PropertyChangeListener l) { changes.addPropertyChangeListener(l); } public void removePropertyChangeListener( PropertyChangeListener l) { changes.removePropertyChangeListener(l); }

Mari Göransson - KaU - Datavetenskap - DAVD11 20 Implementing Bound Property Support Modify a property's setter method to fire a property change event when the property is changed. Public void setText(String value) { String oldValue = text; text = value; changes.firePropertyChange(”text", oldValue, value); }

Mari Göransson - KaU - Datavetenskap - DAVD11 21 Implementing Bound Property Support The firePropertyChange method bundles its parameters into a PropertyChangeEvent object, and calls propertyChange(PropertyChangeEvent pce) on each registered listener.

Mari Göransson - KaU - Datavetenskap - DAVD11 22 Implementing Bound Property Listeners Implement the PropertyChangeListener interface. public class MyClass implements java.beans.PropertyChangeListener, java.io.Serializable

Mari Göransson - KaU - Datavetenskap - DAVD11 23 Implementing Bound Property Listeners Implement the propertyChange method in the listener. public void propertyChange(PropertyChangeEvent e) Example taken from: