SlideShare a Scribd company logo
JavaBeans


            1
Topics
●   JavaBean as a component model
●   Core concepts of JavaBeans
●   Properties
●   Event model
●   Introspection
●   Bean persistence
●   Bean persistence in XML




                                    2
JavaBean as a
Software Component
       Model
                 3
Software Component
●   Software components are self-contained, reusable
    software units
●   Visual software components
    –   Using visual application builder tools, visual software
        components can be composed into applets, applications,
        servlets, and composite components
    –   You perform this composition within a graphical user
        interface, and you can immediately see the results of
        your work.
●   Non-visual software components
    –   Capture business logic or state

                                                                  4
What is a JavaBean?
●   JavaBeans™ is a portable, platform-independent
    component model written in the Java programming
    language
●   With the JavaBeans API you can create reusable,
    platform-independent components
●   Using JavaBeans-compliant application builder
    tools such as NetBeans or Eclipse, you can
    combine these components into applets,
    applications, or composite components.



                                                      5
What is a JavaBean?
●   JavaBean components are known as beans.
●   Beans are dynamic in that they can be changed or
    customized
●   Through the design mode of a builder tool, you use
    the property sheet or bean customizer to customize
    the bean and then save (persist) your customized
    beans.




                                                         6
Core Concepts of
  JavaBeans
                   7
Builder Tools & Introspection
●   Builder tools discover a bean's features (that is, its
    properties, methods, and events) by a process
    known as introspection.
●   Beans support introspection in two ways:
    –   By adhering to specific rules, known as design patterns,
        when naming bean features
    –   By explicitly providing property, method, and event
        information with a related bean information class.




                                                                   8
Properties
●   Properties are the appearance and behavior
    characteristics of a bean that can be changed at
    design time
●   Beans expose properties so they can be
    customized at design time
●   Builder tools introspect on a bean to discover its
    properties and expose those properties for
    manipulation
●   Customization is supported in two ways:
    –   by using property editors
    –   by using more sophisticated bean customizers
                                                         9
Events
●   Beans use events to communicate with other beans
●   A bean that is to receive events (a listener bean)
    registers with the bean that fires the event (a
    source bean)
●   Builder tools can examine a bean and determine
    which events that bean can fire (send) and which it
    can handle (receive)




                                                      10
Persistence
●   Persistence enables beans to save and restore
    their state
●   After changing a bean's properties, you can save
    the state of the bean and restore that bean at a
    later time with the property changes intact
●   The JavaBeans architecture uses Java Object
    Serialization to support persistence.




                                                       11
JavaBean Method
●   A bean's methods are no different from Java
    methods, and can be called from other beans or a
    scripting environment
●   By default all public methods are exported




                                                       12
Examples of Beans
●   GUI (graphical user interface) component
●   Non-visual beans, such as a spelling checker
●   Animation applet
●   Spreadsheet application




                                                   13
Examples of GUI Beans
●   Button Beans




●   Slider Bean




                                14
Properties

             15
Properties
●   A bean property is a named attribute of a bean
    that can affect its behavior or appearance
●   Examples of bean properties include color, label,
    font, font size, and display size.




                                                        16
Types of Properties
●   Simple – A bean property with a single value whose
    changes are independent of changes in any other
    property.
●   Indexed – A bean property that supports a range of
    values instead of a single value.
●   Bound – A bean property for which a change to the
    property results in a notification being sent to some
    other bean.
●   Constrained – A bean property for which a change to
    the property results in validation by another bean. The
    other bean may reject the change if it is not
    appropriate.                                          17
Event Model

              18
JavaBeans Event Model
●   Based the Java 1.1 event model
●   An object interested in receiving events is an event
    listener – sometimes called event receiver
●   An object that generates (fire) events is called an
    event source – sometimes called event sender
●   Event listeners register their interest of receiving
    events to the event source
    –   Event source provides the methods for event listeners to
        call for registration
●   The event source maintains a list of listeners and
    invoke them when an event occurs
                                                                   19
Registration of Event Listeners
●   Event listeners are registered to the event source
    through the methods provided by the event source
    –   addXXXListener
    –   removeXXXListener




                                                         20
Steps of Writing Event Handling
1.Write Event class
  –   Create your own custom event class, named XXXEvent or
      use an existing event class
  –   There are existing event class (i.e. ActionEvent)
2.Write Event listener (Event handler or Event receiver)
  –   Write XXXListener interface and provide implementation
      class of it
  –   There are built-in listerner interfaces (i.e. ActionListener)
3.Write Event source (Event generator)
  –   Add an addXXXListener and removeXXXListener methods,
      where XXX stands for the name of the event
  –   These methods are used by event listeners for registration
  –   There are built-in event source classes                   21
Steps of Adding Event Handling
4.Write a glue class
  –   Register event listener to the event source through
      addXXXListener() method of the event source




                                                            22
Example 1: Button Handler




                            23
1. Write Event Class
●   We are going to use ActionEvent class which is already
    provided in JDK




                                                       24
2. Write Event Listener Class
●   We are going to use ActionListener interface which is
    already provided in JDK
●   We are going to write ButtonHandler class which
    implements ActionListener interface




                                                        25
2. Write Event Listener Class
public class ButtonHandler implements ActionListener {
  /**
   * Component that will contain messages about
   * events generated.
   */
  private JTextArea output;
  /**
   * Creates an ActionListener that will put messages in
   * JTextArea everytime event received.
   */
  public ButtonHandler( JTextArea output ) {
      this.output = output;
  }

  /**
   * When receives action event notification, appends
   * message to the JTextArea passed into the constructor.
   */
  public void actionPerformed( ActionEvent event ) {
      this.output.append( "Action occurred in the Button Handler: " + event + 'n' )
   ;                                                                         26
  }
3. Write Event Source Class
●   We are going to use Button class which is event source
    class and is already provided in JDK
●   Button class already has the following methods
    –   addActionListener
    –   removeActionListener




                                                       27
4. Write Glue Code
●
    Create object instances
●
    Register event handler to the event source




                                                 28
4. Write Glue Code
public class ActionEventExample {

  public static void main(String[] args) {

      JFrame frame = new JFrame( "Button Handler" );
      JTextArea area = new JTextArea( 6, 80 );

      // Create event source object
      JButton button = new JButton( "Fire Event" );

      // Register an ActionListener object to the event source
      button.addActionListener( new ButtonHandler( area ) );

      frame.add( button, BorderLayout.NORTH );
      frame.add( area, BorderLayout.CENTER );
      frame.pack();
      frame.setDefaultCloseOperation( WindowConstants.DISPOSE_ON_CLOS
      frame.setLocationRelativeTo( null );
      frame.setVisible( true );
  }
                                                                 29
What Happens When an Event
             Occurs?
●   Event source invokes event handling method of all
    Event handlers (event listener) registered to it
    –   actionPerformed() method ButtonHandler will be invoked




                                                                 30
Introspection

                31
What is Introspection?
●   Introspection is the automatic process of analyzing
    a bean's design patterns to reveal the bean's
    properties, events, and methods
    –   This process controls the publishing and discovery of
        bean operations and properties
●   By default, introspection is supported by reflection,
    where you name methods with certain naming
    patterns, like set/getProperty() and
    add/removeListener()



                                                                32
FeatureDescriptor




                    33
Things That Can be Found through
          Introspection
●   Simple property
    –   public void setPropertyName(PropertyType value);
    –   public PropertyType getPropertyName();
●   Boolean property
    –   public void setPropertyName(boolean value);
    –   public boolean isPropertyName();
●   Indexed property
    –   public void setPropertyName(int index, PropertyType value);
    –   public PropertyType getPropertyName(int index);
    –   public void setPropertyName(PropertyType[] value);
    –   public PropertyType[] getPropertyName();
                                                               34
Things That can be found through
         Introspection
●   Multicast events
    –   public void addEventListenerType(EventListenerType l);
    –   public void removeEventListenerType(EventListenerType l);
●   Unicast events
    –   public void addEventListenerType(EventListenerType l)
        throws TooManyListenersException;
    –   public void removeEventListenerType(EventListenerType l);
●   Methods
    –   public methods


                                                              35
Bean Persistence

                   36
Bean Persistence
●   Through object serialization
●   Object serialization means converting an object into
    a data stream and writing it to storage.
●   Any applet, application, or tool that uses that bean
    can then "reconstitute" it by deserialization. The
    object is then restored to its original state
●   For example, a Java application can serialize a
    Frame window on a Microsoft Windows machine,
    the serialized file can be sent with e-mail to a
    Solaris machine, and then a Java application can
    restore the Frame window to the exact state which
    existed on the Microsoft Windows machine.            37
Bean Persistence in
      XML
                      38
XMLEncoder Class
●   Enable beans to be saved in XML format
●   The XMLEncoder class is assigned to write output files
    for textual representation of Serializable objects

    XMLEncoder encoder = new XMLEncoder(
           new BufferedOutputStream(
                new FileOutputStream( "Beanarchive.xml" ) ) );

    encoder.writeObject( object );
    encoder.close();


                                                             39
XMLDecoder Class
●   XMLDecoder class reads an XML document that was
    created with XMLEncoder:

    XMLDecoder decoder = new XMLDecoder(
           new BufferedInputStream(
               new FileInputStream( "Beanarchive.xml" ) ) );

    Object object = decoder.readObject();
    decoder.close();



                                                               40
Example: SimpleBean
import java.awt.Color;
import java.beans.XMLDecoder;
import javax.swing.JLabel;
import java.io.Serializable;

public class SimpleBean extends JLabel
               implements Serializable {
  public SimpleBean() {
     setText( "Hello world!" );
     setOpaque( true );
     setBackground( Color.RED );
     setForeground( Color.YELLOW );
     setVerticalAlignment( CENTER );
     setHorizontalAlignment( CENTER );
  }
                                           41
}
Example: XML Representation
<?xml version="1.0" encoding="UTF-8" ?>
<java>
 <object class="javax.swing.JFrame">
   <void method="add">
     <object class="java.awt.BorderLayout" field="CENTER"/>
     <object class="SimpleBean"/>
   </void>
   <void property="defaultCloseOperation">
     <object class="javax.swing.WindowConstants"
   field="DISPOSE_ON_CLOSE"/>
   </void>
   <void method="pack"/>
   <void property="visible">
     <boolean>true</boolean>
   </void>
 </object>
                                                            42
</java>
JavaBeans


            43

More Related Content

What's hot

Bean Intro
Bean IntroBean Intro
Bean Intro
vikram singh
 
Beans presentation
Beans presentationBeans presentation
Beans presentation
manjusha ganesan
 
13 java beans
13 java beans13 java beans
13 java beans
snopteck
 
Javabeans .pdf
Javabeans .pdfJavabeans .pdf
Javabeans .pdf
Rajkiran Mummadi
 
Java beans
Java beansJava beans
Java beans
sptatslide
 
Java Beans
Java BeansJava Beans
Java Beans
Ankit Desai
 
Java Beans Unit 4(part 2)
Java Beans Unit 4(part 2)Java Beans Unit 4(part 2)
Java Beans Unit 4(part 2)
SURBHI SAROHA
 
Java beans
Java beansJava beans
Java beans
Java beansJava beans
Java beans
Umair Liaqat
 
The state of hooking into Drupal - DrupalCon Dublin
The state of hooking into Drupal - DrupalCon DublinThe state of hooking into Drupal - DrupalCon Dublin
The state of hooking into Drupal - DrupalCon Dublin
Nida Ismail Shah
 
JavaScript Coding with Class
JavaScript Coding with ClassJavaScript Coding with Class
JavaScript Coding with Class
davidwalsh83
 
L0043 - Interfacing to Eclipse Standard Views
L0043 - Interfacing to Eclipse Standard ViewsL0043 - Interfacing to Eclipse Standard Views
L0043 - Interfacing to Eclipse Standard Views
Tonny Madsen
 
Composite WPF
Composite WPFComposite WPF
Composite WPF
Martha Rotter
 
Unit4wt
Unit4wtUnit4wt
Unit4wt
vamsi krishna
 
L0036 - Creating Views and Editors
L0036 - Creating Views and EditorsL0036 - Creating Views and Editors
L0036 - Creating Views and Editors
Tonny Madsen
 
L0033 - JFace
L0033 - JFaceL0033 - JFace
L0033 - JFace
Tonny Madsen
 
07 association of entities
07 association of entities07 association of entities
07 association of entities
thirumuru2012
 
No Coding Necessary: Building Confluence User Macros Cheat Sheet - Atlassian ...
No Coding Necessary: Building Confluence User Macros Cheat Sheet - Atlassian ...No Coding Necessary: Building Confluence User Macros Cheat Sheet - Atlassian ...
No Coding Necessary: Building Confluence User Macros Cheat Sheet - Atlassian ...
Atlassian
 
03 programmation mobile - android - (stockage, multithreads, web services)
03 programmation mobile - android - (stockage, multithreads, web services)03 programmation mobile - android - (stockage, multithreads, web services)
03 programmation mobile - android - (stockage, multithreads, web services)
TECOS
 
No Coding Necessary: Building User Macros and Dynamic Reports Inside Confluen...
No Coding Necessary: Building User Macros and Dynamic Reports Inside Confluen...No Coding Necessary: Building User Macros and Dynamic Reports Inside Confluen...
No Coding Necessary: Building User Macros and Dynamic Reports Inside Confluen...
Atlassian
 

What's hot (20)

Bean Intro
Bean IntroBean Intro
Bean Intro
 
Beans presentation
Beans presentationBeans presentation
Beans presentation
 
13 java beans
13 java beans13 java beans
13 java beans
 
Javabeans .pdf
Javabeans .pdfJavabeans .pdf
Javabeans .pdf
 
Java beans
Java beansJava beans
Java beans
 
Java Beans
Java BeansJava Beans
Java Beans
 
Java Beans Unit 4(part 2)
Java Beans Unit 4(part 2)Java Beans Unit 4(part 2)
Java Beans Unit 4(part 2)
 
Java beans
Java beansJava beans
Java beans
 
Java beans
Java beansJava beans
Java beans
 
The state of hooking into Drupal - DrupalCon Dublin
The state of hooking into Drupal - DrupalCon DublinThe state of hooking into Drupal - DrupalCon Dublin
The state of hooking into Drupal - DrupalCon Dublin
 
JavaScript Coding with Class
JavaScript Coding with ClassJavaScript Coding with Class
JavaScript Coding with Class
 
L0043 - Interfacing to Eclipse Standard Views
L0043 - Interfacing to Eclipse Standard ViewsL0043 - Interfacing to Eclipse Standard Views
L0043 - Interfacing to Eclipse Standard Views
 
Composite WPF
Composite WPFComposite WPF
Composite WPF
 
Unit4wt
Unit4wtUnit4wt
Unit4wt
 
L0036 - Creating Views and Editors
L0036 - Creating Views and EditorsL0036 - Creating Views and Editors
L0036 - Creating Views and Editors
 
L0033 - JFace
L0033 - JFaceL0033 - JFace
L0033 - JFace
 
07 association of entities
07 association of entities07 association of entities
07 association of entities
 
No Coding Necessary: Building Confluence User Macros Cheat Sheet - Atlassian ...
No Coding Necessary: Building Confluence User Macros Cheat Sheet - Atlassian ...No Coding Necessary: Building Confluence User Macros Cheat Sheet - Atlassian ...
No Coding Necessary: Building Confluence User Macros Cheat Sheet - Atlassian ...
 
03 programmation mobile - android - (stockage, multithreads, web services)
03 programmation mobile - android - (stockage, multithreads, web services)03 programmation mobile - android - (stockage, multithreads, web services)
03 programmation mobile - android - (stockage, multithreads, web services)
 
No Coding Necessary: Building User Macros and Dynamic Reports Inside Confluen...
No Coding Necessary: Building User Macros and Dynamic Reports Inside Confluen...No Coding Necessary: Building User Macros and Dynamic Reports Inside Confluen...
No Coding Necessary: Building User Macros and Dynamic Reports Inside Confluen...
 

Viewers also liked

Java beans
Java beansJava beans
Java beans
Ravi Kant Sahu
 
Java Networking
Java NetworkingJava Networking
Java Networking
Ankit Desai
 
Interoperability
InteroperabilityInteroperability
Interoperability
sudhakar mandal
 
CORBA Basic and Deployment of CORBA
CORBA Basic and Deployment of CORBACORBA Basic and Deployment of CORBA
CORBA Basic and Deployment of CORBA
Priyanka Patil
 
Deployment
DeploymentDeployment
CORBA
CORBACORBA
Java beans
Java beansJava beans
Java beans
Bipin Bedi
 
Java Course 14: Beans, Applets, GUI
Java Course 14: Beans, Applets, GUIJava Course 14: Beans, Applets, GUI
Java Course 14: Beans, Applets, GUI
Anton Keks
 
Using java beans(ii)
Using java beans(ii)Using java beans(ii)
Using java beans(ii)
Ximentita Hernandez
 
Santa Ana School.pptx
Santa Ana School.pptxSanta Ana School.pptx
Santa Ana School.pptx
sofiathoma
 
EJB 3.1 by Bert Ertman
EJB 3.1 by Bert ErtmanEJB 3.1 by Bert Ertman
EJB 3.1 by Bert Ertman
Stephan Janssen
 
COM
COMCOM
Reflection and Introspection
Reflection and IntrospectionReflection and Introspection
Reflection and Introspection
adil raja
 
Java Serialization
Java SerializationJava Serialization
Java Serialization
imypraz
 
C O R B A Unit 4
C O R B A    Unit 4C O R B A    Unit 4
C O R B A Unit 4
Roy Antony Arnold G
 
Component object model and
Component object model andComponent object model and
Component object model and
Saransh Garg
 
Corba introduction and simple example
Corba introduction and simple example Corba introduction and simple example
Corba introduction and simple example
Alexia Wang
 
Java Reflection Explained Simply
Java Reflection Explained SimplyJava Reflection Explained Simply
Java Reflection Explained Simply
Ciaran McHale
 

Viewers also liked (18)

Java beans
Java beansJava beans
Java beans
 
Java Networking
Java NetworkingJava Networking
Java Networking
 
Interoperability
InteroperabilityInteroperability
Interoperability
 
CORBA Basic and Deployment of CORBA
CORBA Basic and Deployment of CORBACORBA Basic and Deployment of CORBA
CORBA Basic and Deployment of CORBA
 
Deployment
DeploymentDeployment
Deployment
 
CORBA
CORBACORBA
CORBA
 
Java beans
Java beansJava beans
Java beans
 
Java Course 14: Beans, Applets, GUI
Java Course 14: Beans, Applets, GUIJava Course 14: Beans, Applets, GUI
Java Course 14: Beans, Applets, GUI
 
Using java beans(ii)
Using java beans(ii)Using java beans(ii)
Using java beans(ii)
 
Santa Ana School.pptx
Santa Ana School.pptxSanta Ana School.pptx
Santa Ana School.pptx
 
EJB 3.1 by Bert Ertman
EJB 3.1 by Bert ErtmanEJB 3.1 by Bert Ertman
EJB 3.1 by Bert Ertman
 
COM
COMCOM
COM
 
Reflection and Introspection
Reflection and IntrospectionReflection and Introspection
Reflection and Introspection
 
Java Serialization
Java SerializationJava Serialization
Java Serialization
 
C O R B A Unit 4
C O R B A    Unit 4C O R B A    Unit 4
C O R B A Unit 4
 
Component object model and
Component object model andComponent object model and
Component object model and
 
Corba introduction and simple example
Corba introduction and simple example Corba introduction and simple example
Corba introduction and simple example
 
Java Reflection Explained Simply
Java Reflection Explained SimplyJava Reflection Explained Simply
Java Reflection Explained Simply
 

Similar to javabeans

Event handling62
Event handling62Event handling62
Event handling62
myrajendra
 
Unit4wt
Unit4wtUnit4wt
Unit4wt
vamsitricks
 
Swing and Graphical User Interface in Java
Swing and Graphical User Interface in JavaSwing and Graphical User Interface in Java
Swing and Graphical User Interface in Java
babak danyal
 
Fragmentation in android
Fragmentation in android Fragmentation in android
Fragmentation in android
Esraa El Ghoul
 
28-GUI application.pptx.pdf
28-GUI application.pptx.pdf28-GUI application.pptx.pdf
28-GUI application.pptx.pdf
NguynThiThanhTho
 
Jollen's Presentation: Introducing Android low-level
Jollen's Presentation: Introducing Android low-levelJollen's Presentation: Introducing Android low-level
Jollen's Presentation: Introducing Android low-level
Jollen Chen
 
JAVA PROGRAMMING- GUI Programming with Swing - The Swing Buttons
JAVA PROGRAMMING- GUI Programming with Swing - The Swing ButtonsJAVA PROGRAMMING- GUI Programming with Swing - The Swing Buttons
JAVA PROGRAMMING- GUI Programming with Swing - The Swing Buttons
Jyothishmathi Institute of Technology and Science Karimnagar
 
Adobe AIR Development for the BlackBerry PlayBook
Adobe AIR Development for the BlackBerry PlayBookAdobe AIR Development for the BlackBerry PlayBook
Adobe AIR Development for the BlackBerry PlayBook
Kyle McInnes
 
Application Frameworks: The new kids on the block
Application Frameworks: The new kids on the blockApplication Frameworks: The new kids on the block
Application Frameworks: The new kids on the block
Richard Lord
 
iOS app dev Training - Session1
iOS app dev Training - Session1iOS app dev Training - Session1
iOS app dev Training - Session1
Hussain Behestee
 
2006 - Basta!: Advanced server controls
2006 - Basta!: Advanced server controls2006 - Basta!: Advanced server controls
2006 - Basta!: Advanced server controls
Daniel Fisher
 
Dacj 2-2 b
Dacj 2-2 bDacj 2-2 b
Dacj 2-2 b
Niit Care
 
Extending NetBeans IDE
Extending NetBeans IDEExtending NetBeans IDE
Extending NetBeans IDE
Geertjan Wielenga
 
Java session11
Java session11Java session11
Java session11
Niit Care
 
Chap - 2 - Event Handling.pptx
Chap - 2 - Event Handling.pptxChap - 2 - Event Handling.pptx
Chap - 2 - Event Handling.pptx
TadeseBeyene
 
Functional UI testing of Adobe Flex RIA
Functional UI testing of Adobe Flex RIAFunctional UI testing of Adobe Flex RIA
Functional UI testing of Adobe Flex RIA
Viktor Gamov
 
Custom components in JSF
Custom components in JSFCustom components in JSF
Custom components in JSF
ESRI Bulgaria
 
Android Support Library: Using ActionBarCompat
Android Support Library: Using ActionBarCompatAndroid Support Library: Using ActionBarCompat
Android Support Library: Using ActionBarCompat
cbeyls
 
Introduction of Xcode
Introduction of XcodeIntroduction of Xcode
Introduction of Xcode
Dhaval Kaneria
 
Switch! Recommending Artifacts Needed Next Based on Personal and Shared Context
Switch! Recommending Artifacts Needed Next Based on Personal and Shared ContextSwitch! Recommending Artifacts Needed Next Based on Personal and Shared Context
Switch! Recommending Artifacts Needed Next Based on Personal and Shared Context
alexandersahm
 

Similar to javabeans (20)

Event handling62
Event handling62Event handling62
Event handling62
 
Unit4wt
Unit4wtUnit4wt
Unit4wt
 
Swing and Graphical User Interface in Java
Swing and Graphical User Interface in JavaSwing and Graphical User Interface in Java
Swing and Graphical User Interface in Java
 
Fragmentation in android
Fragmentation in android Fragmentation in android
Fragmentation in android
 
28-GUI application.pptx.pdf
28-GUI application.pptx.pdf28-GUI application.pptx.pdf
28-GUI application.pptx.pdf
 
Jollen's Presentation: Introducing Android low-level
Jollen's Presentation: Introducing Android low-levelJollen's Presentation: Introducing Android low-level
Jollen's Presentation: Introducing Android low-level
 
JAVA PROGRAMMING- GUI Programming with Swing - The Swing Buttons
JAVA PROGRAMMING- GUI Programming with Swing - The Swing ButtonsJAVA PROGRAMMING- GUI Programming with Swing - The Swing Buttons
JAVA PROGRAMMING- GUI Programming with Swing - The Swing Buttons
 
Adobe AIR Development for the BlackBerry PlayBook
Adobe AIR Development for the BlackBerry PlayBookAdobe AIR Development for the BlackBerry PlayBook
Adobe AIR Development for the BlackBerry PlayBook
 
Application Frameworks: The new kids on the block
Application Frameworks: The new kids on the blockApplication Frameworks: The new kids on the block
Application Frameworks: The new kids on the block
 
iOS app dev Training - Session1
iOS app dev Training - Session1iOS app dev Training - Session1
iOS app dev Training - Session1
 
2006 - Basta!: Advanced server controls
2006 - Basta!: Advanced server controls2006 - Basta!: Advanced server controls
2006 - Basta!: Advanced server controls
 
Dacj 2-2 b
Dacj 2-2 bDacj 2-2 b
Dacj 2-2 b
 
Extending NetBeans IDE
Extending NetBeans IDEExtending NetBeans IDE
Extending NetBeans IDE
 
Java session11
Java session11Java session11
Java session11
 
Chap - 2 - Event Handling.pptx
Chap - 2 - Event Handling.pptxChap - 2 - Event Handling.pptx
Chap - 2 - Event Handling.pptx
 
Functional UI testing of Adobe Flex RIA
Functional UI testing of Adobe Flex RIAFunctional UI testing of Adobe Flex RIA
Functional UI testing of Adobe Flex RIA
 
Custom components in JSF
Custom components in JSFCustom components in JSF
Custom components in JSF
 
Android Support Library: Using ActionBarCompat
Android Support Library: Using ActionBarCompatAndroid Support Library: Using ActionBarCompat
Android Support Library: Using ActionBarCompat
 
Introduction of Xcode
Introduction of XcodeIntroduction of Xcode
Introduction of Xcode
 
Switch! Recommending Artifacts Needed Next Based on Personal and Shared Context
Switch! Recommending Artifacts Needed Next Based on Personal and Shared ContextSwitch! Recommending Artifacts Needed Next Based on Personal and Shared Context
Switch! Recommending Artifacts Needed Next Based on Personal and Shared Context
 

More from Arjun Shanka

Asp.net w3schools
Asp.net w3schoolsAsp.net w3schools
Asp.net w3schools
Arjun Shanka
 
Php tutorial(w3schools)
Php tutorial(w3schools)Php tutorial(w3schools)
Php tutorial(w3schools)
Arjun Shanka
 
Sms several papers
Sms several papersSms several papers
Sms several papers
Arjun Shanka
 
System simulation 06_cs82
System simulation 06_cs82System simulation 06_cs82
System simulation 06_cs82Arjun Shanka
 
javaexceptions
javaexceptionsjavaexceptions
javaexceptions
Arjun Shanka
 
javainheritance
javainheritancejavainheritance
javainheritance
Arjun Shanka
 
javarmi
javarmijavarmi
javarmi
Arjun Shanka
 
java-06inheritance
java-06inheritancejava-06inheritance
java-06inheritance
Arjun Shanka
 
hibernate
hibernatehibernate
hibernate
Arjun Shanka
 
javapackage
javapackagejavapackage
javapackage
Arjun Shanka
 
javaarray
javaarrayjavaarray
javaarray
Arjun Shanka
 
swingbasics
swingbasicsswingbasics
swingbasics
Arjun Shanka
 
spring-tutorial
spring-tutorialspring-tutorial
spring-tutorial
Arjun Shanka
 
struts
strutsstruts
struts
Arjun Shanka
 
javathreads
javathreadsjavathreads
javathreads
Arjun Shanka
 
72185-26528-StrutsMVC
72185-26528-StrutsMVC72185-26528-StrutsMVC
72185-26528-StrutsMVC
Arjun Shanka
 
javanetworking
javanetworkingjavanetworking
javanetworking
Arjun Shanka
 
javaiostream
javaiostreamjavaiostream
javaiostream
Arjun Shanka
 
servlets
servletsservlets
servlets
Arjun Shanka
 

More from Arjun Shanka (20)

Asp.net w3schools
Asp.net w3schoolsAsp.net w3schools
Asp.net w3schools
 
Php tutorial(w3schools)
Php tutorial(w3schools)Php tutorial(w3schools)
Php tutorial(w3schools)
 
Sms several papers
Sms several papersSms several papers
Sms several papers
 
Jun 2012(1)
Jun 2012(1)Jun 2012(1)
Jun 2012(1)
 
System simulation 06_cs82
System simulation 06_cs82System simulation 06_cs82
System simulation 06_cs82
 
javaexceptions
javaexceptionsjavaexceptions
javaexceptions
 
javainheritance
javainheritancejavainheritance
javainheritance
 
javarmi
javarmijavarmi
javarmi
 
java-06inheritance
java-06inheritancejava-06inheritance
java-06inheritance
 
hibernate
hibernatehibernate
hibernate
 
javapackage
javapackagejavapackage
javapackage
 
javaarray
javaarrayjavaarray
javaarray
 
swingbasics
swingbasicsswingbasics
swingbasics
 
spring-tutorial
spring-tutorialspring-tutorial
spring-tutorial
 
struts
strutsstruts
struts
 
javathreads
javathreadsjavathreads
javathreads
 
72185-26528-StrutsMVC
72185-26528-StrutsMVC72185-26528-StrutsMVC
72185-26528-StrutsMVC
 
javanetworking
javanetworkingjavanetworking
javanetworking
 
javaiostream
javaiostreamjavaiostream
javaiostream
 
servlets
servletsservlets
servlets
 

Recently uploaded

Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
Zilliz
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
James Anderson
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Speck&Tech
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIEnchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Vladimir Iglovikov, Ph.D.
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
SOFTTECHHUB
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
Matthew Sinclair
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
Zilliz
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
Edge AI and Vision Alliance
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
Daiki Mogmet Ito
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
Neo4j
 
Building RAG with self-deployed Milvus vector database and Snowpark Container...
Building RAG with self-deployed Milvus vector database and Snowpark Container...Building RAG with self-deployed Milvus vector database and Snowpark Container...
Building RAG with self-deployed Milvus vector database and Snowpark Container...
Zilliz
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 

Recently uploaded (20)

Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIEnchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
 
Building RAG with self-deployed Milvus vector database and Snowpark Container...
Building RAG with self-deployed Milvus vector database and Snowpark Container...Building RAG with self-deployed Milvus vector database and Snowpark Container...
Building RAG with self-deployed Milvus vector database and Snowpark Container...
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 

javabeans

  • 2. Topics ● JavaBean as a component model ● Core concepts of JavaBeans ● Properties ● Event model ● Introspection ● Bean persistence ● Bean persistence in XML 2
  • 3. JavaBean as a Software Component Model 3
  • 4. Software Component ● Software components are self-contained, reusable software units ● Visual software components – Using visual application builder tools, visual software components can be composed into applets, applications, servlets, and composite components – You perform this composition within a graphical user interface, and you can immediately see the results of your work. ● Non-visual software components – Capture business logic or state 4
  • 5. What is a JavaBean? ● JavaBeans™ is a portable, platform-independent component model written in the Java programming language ● With the JavaBeans API you can create reusable, platform-independent components ● Using JavaBeans-compliant application builder tools such as NetBeans or Eclipse, you can combine these components into applets, applications, or composite components. 5
  • 6. What is a JavaBean? ● JavaBean components are known as beans. ● Beans are dynamic in that they can be changed or customized ● Through the design mode of a builder tool, you use the property sheet or bean customizer to customize the bean and then save (persist) your customized beans. 6
  • 7. Core Concepts of JavaBeans 7
  • 8. Builder Tools & Introspection ● Builder tools discover a bean's features (that is, its properties, methods, and events) by a process known as introspection. ● Beans support introspection in two ways: – By adhering to specific rules, known as design patterns, when naming bean features – By explicitly providing property, method, and event information with a related bean information class. 8
  • 9. Properties ● Properties are the appearance and behavior characteristics of a bean that can be changed at design time ● Beans expose properties so they can be customized at design time ● Builder tools introspect on a bean to discover its properties and expose those properties for manipulation ● Customization is supported in two ways: – by using property editors – by using more sophisticated bean customizers 9
  • 10. Events ● Beans use events to communicate with other beans ● A bean that is to receive events (a listener bean) registers with the bean that fires the event (a source bean) ● Builder tools can examine a bean and determine which events that bean can fire (send) and which it can handle (receive) 10
  • 11. Persistence ● Persistence enables beans to save and restore their state ● After changing a bean's properties, you can save the state of the bean and restore that bean at a later time with the property changes intact ● The JavaBeans architecture uses Java Object Serialization to support persistence. 11
  • 12. JavaBean Method ● A bean's methods are no different from Java methods, and can be called from other beans or a scripting environment ● By default all public methods are exported 12
  • 13. Examples of Beans ● GUI (graphical user interface) component ● Non-visual beans, such as a spelling checker ● Animation applet ● Spreadsheet application 13
  • 14. Examples of GUI Beans ● Button Beans ● Slider Bean 14
  • 16. Properties ● A bean property is a named attribute of a bean that can affect its behavior or appearance ● Examples of bean properties include color, label, font, font size, and display size. 16
  • 17. Types of Properties ● Simple – A bean property with a single value whose changes are independent of changes in any other property. ● Indexed – A bean property that supports a range of values instead of a single value. ● Bound – A bean property for which a change to the property results in a notification being sent to some other bean. ● Constrained – A bean property for which a change to the property results in validation by another bean. The other bean may reject the change if it is not appropriate. 17
  • 19. JavaBeans Event Model ● Based the Java 1.1 event model ● An object interested in receiving events is an event listener – sometimes called event receiver ● An object that generates (fire) events is called an event source – sometimes called event sender ● Event listeners register their interest of receiving events to the event source – Event source provides the methods for event listeners to call for registration ● The event source maintains a list of listeners and invoke them when an event occurs 19
  • 20. Registration of Event Listeners ● Event listeners are registered to the event source through the methods provided by the event source – addXXXListener – removeXXXListener 20
  • 21. Steps of Writing Event Handling 1.Write Event class – Create your own custom event class, named XXXEvent or use an existing event class – There are existing event class (i.e. ActionEvent) 2.Write Event listener (Event handler or Event receiver) – Write XXXListener interface and provide implementation class of it – There are built-in listerner interfaces (i.e. ActionListener) 3.Write Event source (Event generator) – Add an addXXXListener and removeXXXListener methods, where XXX stands for the name of the event – These methods are used by event listeners for registration – There are built-in event source classes 21
  • 22. Steps of Adding Event Handling 4.Write a glue class – Register event listener to the event source through addXXXListener() method of the event source 22
  • 23. Example 1: Button Handler 23
  • 24. 1. Write Event Class ● We are going to use ActionEvent class which is already provided in JDK 24
  • 25. 2. Write Event Listener Class ● We are going to use ActionListener interface which is already provided in JDK ● We are going to write ButtonHandler class which implements ActionListener interface 25
  • 26. 2. Write Event Listener Class public class ButtonHandler implements ActionListener { /** * Component that will contain messages about * events generated. */ private JTextArea output; /** * Creates an ActionListener that will put messages in * JTextArea everytime event received. */ public ButtonHandler( JTextArea output ) { this.output = output; } /** * When receives action event notification, appends * message to the JTextArea passed into the constructor. */ public void actionPerformed( ActionEvent event ) { this.output.append( "Action occurred in the Button Handler: " + event + 'n' ) ; 26 }
  • 27. 3. Write Event Source Class ● We are going to use Button class which is event source class and is already provided in JDK ● Button class already has the following methods – addActionListener – removeActionListener 27
  • 28. 4. Write Glue Code ● Create object instances ● Register event handler to the event source 28
  • 29. 4. Write Glue Code public class ActionEventExample { public static void main(String[] args) { JFrame frame = new JFrame( "Button Handler" ); JTextArea area = new JTextArea( 6, 80 ); // Create event source object JButton button = new JButton( "Fire Event" ); // Register an ActionListener object to the event source button.addActionListener( new ButtonHandler( area ) ); frame.add( button, BorderLayout.NORTH ); frame.add( area, BorderLayout.CENTER ); frame.pack(); frame.setDefaultCloseOperation( WindowConstants.DISPOSE_ON_CLOS frame.setLocationRelativeTo( null ); frame.setVisible( true ); } 29
  • 30. What Happens When an Event Occurs? ● Event source invokes event handling method of all Event handlers (event listener) registered to it – actionPerformed() method ButtonHandler will be invoked 30
  • 32. What is Introspection? ● Introspection is the automatic process of analyzing a bean's design patterns to reveal the bean's properties, events, and methods – This process controls the publishing and discovery of bean operations and properties ● By default, introspection is supported by reflection, where you name methods with certain naming patterns, like set/getProperty() and add/removeListener() 32
  • 34. Things That Can be Found through Introspection ● Simple property – public void setPropertyName(PropertyType value); – public PropertyType getPropertyName(); ● Boolean property – public void setPropertyName(boolean value); – public boolean isPropertyName(); ● Indexed property – public void setPropertyName(int index, PropertyType value); – public PropertyType getPropertyName(int index); – public void setPropertyName(PropertyType[] value); – public PropertyType[] getPropertyName(); 34
  • 35. Things That can be found through Introspection ● Multicast events – public void addEventListenerType(EventListenerType l); – public void removeEventListenerType(EventListenerType l); ● Unicast events – public void addEventListenerType(EventListenerType l) throws TooManyListenersException; – public void removeEventListenerType(EventListenerType l); ● Methods – public methods 35
  • 37. Bean Persistence ● Through object serialization ● Object serialization means converting an object into a data stream and writing it to storage. ● Any applet, application, or tool that uses that bean can then "reconstitute" it by deserialization. The object is then restored to its original state ● For example, a Java application can serialize a Frame window on a Microsoft Windows machine, the serialized file can be sent with e-mail to a Solaris machine, and then a Java application can restore the Frame window to the exact state which existed on the Microsoft Windows machine. 37
  • 39. XMLEncoder Class ● Enable beans to be saved in XML format ● The XMLEncoder class is assigned to write output files for textual representation of Serializable objects XMLEncoder encoder = new XMLEncoder( new BufferedOutputStream( new FileOutputStream( "Beanarchive.xml" ) ) ); encoder.writeObject( object ); encoder.close(); 39
  • 40. XMLDecoder Class ● XMLDecoder class reads an XML document that was created with XMLEncoder: XMLDecoder decoder = new XMLDecoder( new BufferedInputStream( new FileInputStream( "Beanarchive.xml" ) ) ); Object object = decoder.readObject(); decoder.close(); 40
  • 41. Example: SimpleBean import java.awt.Color; import java.beans.XMLDecoder; import javax.swing.JLabel; import java.io.Serializable; public class SimpleBean extends JLabel implements Serializable { public SimpleBean() { setText( "Hello world!" ); setOpaque( true ); setBackground( Color.RED ); setForeground( Color.YELLOW ); setVerticalAlignment( CENTER ); setHorizontalAlignment( CENTER ); } 41 }
  • 42. Example: XML Representation <?xml version="1.0" encoding="UTF-8" ?> <java> <object class="javax.swing.JFrame"> <void method="add"> <object class="java.awt.BorderLayout" field="CENTER"/> <object class="SimpleBean"/> </void> <void property="defaultCloseOperation"> <object class="javax.swing.WindowConstants" field="DISPOSE_ON_CLOSE"/> </void> <void method="pack"/> <void property="visible"> <boolean>true</boolean> </void> </object> 42 </java>
  • 43. JavaBeans 43