Java Programming: Advanced Topics 1 JavaBeans Chapter 8.

Slides:



Advertisements
Similar presentations
3 Copyright © 2005, Oracle. All rights reserved. Basic Java Syntax and Coding Conventions.
Advertisements

Copyright © 2001 Qusay H. Mahmoud JavaBeans An introduction to component-based development in general Introduction to JavaBeans – Java components – client-side.
JavaBeans: Introspection and Customization Umer Farooq CS6704: Design Patterns & Component FrameworksJanuary 30, 2002.
Mari Göransson - KaU - Datavetenskap - DAVD11 1 Java Beans - Events and Properties -
1 Chapter 7 Graphics and Event Handling. 2 Overview The java.awt and javax.swing packages and their subpackages support graphics and event handling. Many.
Java Beans & Serialization CS-328 Dick Steflik. Java Beans Java based component technology –originally developed to provide java with a component technology.
Java Programming, 3e Concepts and Techniques Chapter 5 Arrays, Loops, and Layout Managers Using External Classes.
JavaBeans introduction Klaus-Peter Heidrich for the University of Karlstad Inst. for Information Technology Dept. of Computer Science.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 15 Advanced Features of Java.
By Dr. Jiang B. Liu 12. The Java Beans. Java Beans n JavaBeans is a portable, platform-independent software component model written in Java. It enables.
JAVA BEANS By Madhuri Kakumanu. What is a Java Bean? “ A Java Bean is a reusable software component that can be visually manipulated in builder tools.”
Chapter 12: Advanced Topics: Exception Handling Visual Basic.NET Programming: From Problem Analysis to Program Design.
Attributes Basic Attributes are great tool for describing your services to clients and users. Attributes give you powerful ways to search for particular.
JAVA BEANS (Unit-V) K.Phani Sirisha.
Introducing JavaBeans Lesson 2A / Slide 1 of 30 JDBC and JavaBeans Pre-assessment Questions 1.Which of the given symbols is used as a placeholder for PreparedStatement.
Introducing JavaBeans Identify the features of a JavaBean Create and add a bean to an application Manipulate bean properties using accessor and mutator.
Java Beans.  Java offers software component development through java Beans  Java Beans are based on a software component model for java.  The model.
Java Beans Component Technology Integrated, Visual Development Environments Reusable Platform-Independent Modular.
Component-Based Software Engineering Introduction to Java Beans Paul Krause and Sotiris Moschoyiannis.
Java Beans.
Chapter 10 Introduction to Components. Process Phases Discussed in This Chapter Requirements Analysis Design Implementation ArchitectureFramework Detailed.
Java Programming, 3e Concepts and Techniques Chapter 3 Section 65 – Manipulating Data Using Methods – Java Applet.
SWE 316: Software Design and Architecture Objectives Lecture # 19 Java Beans SWE 316: Software Design and Architecture  Understand  what JavaBeans (“Beans”)
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.
3461A Readings from the Swing Tutorial. 3461A Overview  The follow is the Table of Contents from the trail “Creating a GUI with JFC/Swing” in the “The.
Java Programming: Advanced Topics 1 Common Elements of Graphical User Interfaces Chapter 6.
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.
Dale Roberts GUI Programming using Java - Introduction Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer.
Ch 3-4: GUI Basics Java Software Solutions Foundations of Program Design Sixth Edition by Lewis & Loftus Coming up: GUI Components.
Graphic User Interface. Graphic User Interface (GUI) Most of us interact with computers using GUIs. GUIs are visual representations of the actions you.
SWE 316: Software Design and Architecture Objectives Lecture # 18 Introduction to Components SWE 316: Software Design and Architecture To learn:  benefits.
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.”
1 Chapter 21 JavaBeans, Bean Events, and MVC Architecture.
Introduction to Java Beans CIS 421 Web-based Java Programming.
Introduction to Java 120 February 2004Sifei HE © 2004 Introduction to Java for CS381, EE4.Web By Sifei HE Department of Computing.
First Bean Compose SimpleBean Demo Simple Bean Discuss Manifest and Jar Add Properties to SimpleBean.
First Bean Compose SimpleBean Demo Simple Bean Discuss Manifest and Jar Add Properties to SimpleBean.
Intro to Applets. Applet Applets run within the Web browser environment Applets bring dynamic interaction and live animation to an otherwise static HTML.
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.
Java Programming: From Problem Analysis to Program Design, 3e Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
Advanced Java Session 4 New York University School of Continuing and Professional Studies.
Chapter 7: Class Inheritance F Superclasses and Subclasses F Keywords: super and this F Overriding methods F The Object Class F Modifiers: protected, final.
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.
Introduction to Software Components: the JavaBeans specs Babak Esfandiari.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 32 JavaBeans and Bean.
Java Programming: Advanced Topics 1 Enterprise JavaBeans Chapter 14.
Java Beans THETOPPERSWAY.COM. Contents What is a Java Bean? Advantages Properties Bean Developers Kit (BDK) What makes Bean possible? Support for Java.
Java Beans - Basics CIS 421 Web-based Java Programming.
1 Sections 5.1 – 5.2 Digital Image Processing Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
CIS 270—Application Development II Chapter 11—GUI Components: Part I.
Chapter 32 JavaBeans and Bean Events
Chapter 36 JavaBeans and Bean Events
JavaBeans* ICS 123 Richard N. Taylor & Eric M. Dashofy UC Irvine
Java Beans Sagun Dhakhwa.
JavaBeans and JSP CS-422.
Persistence & Bean Properties
Event Driven Systems and Modeling
Pre-assessment Questions
Knowledge Byte In this section, you will learn about:
Component-Based Software Engineering
11.1 Applets & graphics.
Java Programming: Advanced Topics
Presentation transcript:

Java Programming: Advanced Topics 1 JavaBeans Chapter 8

Java Programming: Advanced Topics 2 Objectives Learn what the JavaBeans component model is Understand Bean Development environments Use the Sun BeanBox Create a JavaBean class

Java Programming: Advanced Topics 3 Objectives (Cont.) Explore JavaBean property types Add custom event types to your beans Create a JavaBean class with events Supply additional information and support classes for a JavaBean

Java Programming: Advanced Topics 4 JavaBeans Component Model The JavaBeans component model is a framework for creating reusable Java classes Classes that conform to the JavaBeans specification can be loaded into development tools called beanboxes, with which developers can create applications by constructing them from parts JavaBeans are packaged in.jar files that include a manifest file

Java Programming: Advanced Topics 5 What Makes a Class a Bean There is no common superclass that all JavaBean classes extend. To define a JavaBean follow the programming conventions All beans should have a constructor that takes no arguments because the Sun BeanBox call this constructor A JavaBean class must implement the marker interface Serializable, because beanboxes use serialization to save the state of beans

Java Programming: Advanced Topics 6 Elements of a JavaBean Interface

Java Programming: Advanced Topics 7 Bean Development Environments Sun created a demonstration development environment called the BeanBox The Bean Builder is a program that demonstrates new and emerging technologies within the Java platform that allow the construction of applications using component assembly mechanisms

Java Programming: Advanced Topics 8 Using the Sun BeanBox When a bean is instantiated in a beanbox, the bean’s methods are called in the following order: –The constructor with no arguments is called to set up the bean –The preferredSize method returns the display dimensions of the bean –The paint method draws the bean on the BeanBox window

Java Programming: Advanced Topics 9 The BDK BeanBox Properties Window

Java Programming: Advanced Topics 10 Creating a JavaBean Class Create a JavaBean class Package your JavaBean classes into a.jar file Load your.jar file into the BeanBox to connect with other JavaBean components

Java Programming: Advanced Topics 11 Exploring JavaBean Property Types Properties are the attributes of a bean, commonly implemented as the fields of a Java class There are four types of JavaBean Property Types: –Simple –Indexed –Bound –Constrained

Java Programming: Advanced Topics 12 Indexed Properties Properties can be indexed under a single name with an integer index value Indexed properties are arrays of values The mutator and accessor methods for an indexed property must have the arguments, names, and return types

Java Programming: Advanced Topics 13 Indexed Properties (Cont.)

Java Programming: Advanced Topics 14 Bound Properties Bound properties provide notification when they change so that other JavaBeans can listen for these changes and act accordingly The package java.beans includes a class for use with bound properties, PropertyChangeSupport

Java Programming: Advanced Topics 15 Bound Properties (Cont.)

Java Programming: Advanced Topics 16 Constrained Properties Constrained properties: bound properties with the additional characteristics that other listeners can prevent a change in value from occurring To implement a constrained property, a JavaBean class should use an object of the VetoableChangeSupport class Each listener can veto a change and stop it from happening

Java Programming: Advanced Topics 17 Constrained Properties (Cont.)

Java Programming: Advanced Topics 18 Adding Custom Event Types To create and use a custom event: –Define the event class X that extends java.util.EventObject or one of its subclasses –Define the interface, XListener, that the event listeners must implement –Define the methods addXListener and removeXListener for the JavaBean class that can fire the event –The JavaBean class should define a fireX method

Java Programming: Advanced Topics 19 Creating a JavaBean with Events Event handling follows the same model as event handling for components in the Swing and AWT APIs If a bean can generate an event Y, the class for the event is YEvent A listener class YListener should handle YEvent objects Changes to properties trigger events of PropertyChangeEvent objects

Java Programming: Advanced Topics 20 Custom Event Class

Java Programming: Advanced Topics 21 Custom Event Class (Cont.)

Java Programming: Advanced Topics 22 Using the BeanInfo Classes Beanboxes use the Reflection API to determine what they need to know about a JavaBean BeanInfo classes are used only when beans are being connected in a beanbox The BeanInfo classes implement the java.beans.BeanInfo interface If the Reflection API cannot provide all the information that a beanbox needs about a bean, you can supply an additional information class that implements the interface BeanInfo

Java Programming: Advanced Topics 23 JavaBean Information Classes

Java Programming: Advanced Topics 24 Using the BeanInfo Classes (Cont.) Methods of the interface java.beans.BeanInfo: –BeanInfo[ ] getAdditionalBeanInfo() –BeanDescriptor getBeanDescriptor() –int getDefaultEventIndex() –int getDefaultPropertyIndex() –EventSetDescriptor[ ] getEventSetDescriptors() –Image getIcon( int iconKind ) –MethodDescriptor[ ] getMethodDescriptors() –PropertyDescriptor[ ] getPropertyDescriptors()

Java Programming: Advanced Topics 25 Providing a Custom Property Editor Beanboxes typically provide property editors for properties of types String, Font, and Color You can provide customized editors for other kinds of properties by defining a class that extends PropertyEditorSupport or implements the PropertyEditor interface If the property editor dialog box of the beanbox is not adequate, you can supply a customizer class for the bean

Java Programming: Advanced Topics 26 A Customizer Class The customizer class must be a component that can be embedded in a dialog box The class must have a constructor that has no arguments When you create a customizer class, you must provide the method getBeanDescriptor in the BeanInfo class associated with the JavaBean

Java Programming: Advanced Topics 27 JavaBean Class

Java Programming: Advanced Topics 28 JavaBean Class (Cont.)

Java Programming: Advanced Topics 29 JavaBean Class (Cont.)

Java Programming: Advanced Topics 30 JavaBean Class (Cont.)

Java Programming: Advanced Topics 31 JavaBean Class (Cont.)

Java Programming: Advanced Topics 32 JavaBean Class (Cont.)

Java Programming: Advanced Topics 33 JavaBean Class (Cont.)

Java Programming: Advanced Topics 34 JavaBean Class (Cont.)

Java Programming: Advanced Topics 35 JavaBean Class (Cont.)

Java Programming: Advanced Topics 36 JavaBean Class (Cont.)

Java Programming: Advanced Topics 37 JavaBean Class (Cont.)

Java Programming: Advanced Topics 38 Summary The JavaBeans component model is a framework for creating reusable Java classes Classes that conform to the JavaBeans specification can be loaded into development tools called beanboxes A bean must implement the interface java.io.Serializable, and must have a constructor that has no arguments Properties are the attributes of a bean, and can be single entities, indexed, bound or constrained

Java Programming: Advanced Topics 39 Summary (Cont.) JavaBean objects use event-handling mechanism to notify other JavaBean objects that some event has occurred Changes to properties trigger events of PropertyChangeEvent objects Additional information classes, BeanInfo classes, can accompany a JavaBean class You can provide customized editors by defining a class that extends PropertyEditorSupport or implements the PropertyEditor interface