SlideShare a Scribd company logo
1 of 26
Working with JavaBean Properties and Events


Pre-assessment Questions
    1.   You need to create an application that validates the username and password
         of various employees in a company using the entries in the employee
         database. The application validates the username and password every time
         the employee makes a request for the database records, reports, or
         company resources. Select the type of JavaBean that should be used to
         create such an application.
         a.   Control JavaBean
         b.   Container JavaBean
         c.   Invisible runtime JavaBean
         d.   Hidden JavaBean




 ©NIIT                   JDBC and JavaBeans                Lesson 2B / Slide 1 of 26
Working with JavaBean Properties and Events


Pre-assessment Questions (Contd.)
    1.   Which of the file enables you to start the BDK in the Windows environment?
         a. run.bat
         b. run.sh
         c. bdkrun.bat
         d. bdkrun.sh

    2.   What is the name of the BDK window that lists the pre-defined events for a
         sample JavaBean?
         a.  EventListener
         b.  EventTargetDialog
         c.  actionPerformedDialog
         d.  Properties




 ©NIIT                   JDBC and JavaBeans                 Lesson 2B / Slide 2 of 26
Working with JavaBean Properties and Events


Pre-assessment Questions (Contd.)
    1.   The   compressed file for a JavaBean application are stored as:
         a.     Manifest file
         b.     Event file
         c.     JAR file
         d.     BeanInfo file

    3.   How can you modify the public properties of a JavaBean in the BDK
         environment?
         a.   Using property editors
         b.   Using property sheets
         c.   Using properties pallete
         d.   Using BeanBox window




 ©NIIT                     JDBC and JavaBeans                 Lesson 2B / Slide 3 of 26
Working with JavaBean Properties and Events


Solutions to Pre-assessment
Questions
    •    a. Control JavaBean
    •    a. run.bat
    •    b. EventTargetDialog
    •    c. JAR file
    •    b. Using property sheets




 ©NIIT                   JDBC and JavaBeans   Lesson 2B / Slide 4 of 26
Working with JavaBean Properties and Events


Objectives
    In this lesson, you will learn about:


         •   Different types of JavaBean properties
         •   Creating custom events
         •   Using JavaBeans in applications




 ©NIIT                     JDBC and JavaBeans         Lesson 2B / Slide 5 of 26
Working with JavaBean Properties and Events


JavaBean Properties
    •    JavaBean properties:
           • Are the private data members of the JavaBean classes.
           • Are used to accept input from an end user in order to customize a
             JavaBean.
           • Can retrieve and specify the values of various attributes, which determine
             the behavior of a JavaBean.




 ©NIIT                     JDBC and JavaBeans                 Lesson 2B / Slide 6 of 26
Working with JavaBean Properties and Events


JavaBean Properties (Contd.)
    •    Types of JavaBeans Properties
           • Simple properties
           • Boolean properties
           • Indexed properties
           • Bound properties
           • Constrained properties




 ©NIIT                    JDBC and JavaBeans   Lesson 2B / Slide 7 of 26
Working with JavaBean Properties and Events


JavaBean Properties (Contd.)
    •    Simple Properties:
           • Refer to the private variables of a JavaBean that can have only a single
             value.
           • Are retrieved and specified using the get and set methods respectively.

          •   The syntax of get method is:
              public return_type get<PropertyName>()


          •   The syntax of set method is:
              public void set<PropertyName>(data_type value)




 ©NIIT                     JDBC and JavaBeans                  Lesson 2B / Slide 8 of 26
Working with JavaBean Properties and Events


JavaBean Properties (Contd.)
    •    Boolean Properties:
          • Have either of the two values, TRUE or FALSE.
          • Are retrieved and specified using the following methods:
               • public boolean is<PropertyName>()
               • public boolean get<PropertyName>()
               • public void set<PropertyName>(boolean value)




 ©NIIT                    JDBC and JavaBeans                Lesson 2B / Slide 9 of 26
Working with JavaBean Properties and Events


JavaBean Properties (Contd.)
    •    Indexed Properties:
         • Are indexed under a single name, with each index being an integer
             value.
         • Enable you to set or retrieve the values from an array of property
             values.
         • Are retrieved using the following get methods:
             • public int[] get<PropertyName>()
             • public property_datatype get<PropertyName>(int index)
         • Are specified using the following set methods:
             • public void set<PropertyName>(int index,
                  property_datatype value)
             • public void set<PropertyName>(property_datatype[]
                  property_array)




 ©NIIT                  JDBC and JavaBeans              Lesson 2B / Slide 10 of 26
Working with JavaBean Properties and Events


JavaBean Properties (Contd.)
    •    Bound Properties:
          • Are the properties of a JavaBean that inform its listeners about
              changes in its values.
          • Are implemented using the PropertyChangeSupport class and its
              methods.
          • Are always registered with an external event listener.




 ©NIIT                  JDBC and JavaBeans             Lesson 2B / Slide 11 of 26
Working with JavaBean Properties and Events


JavaBean Properties (Contd.)
    •    Constrained Properties:
         • Are the properties that are protected from being changed by other
             JavaBeans.
         • Are implemented using the VetoableChangeSupport class.
         • Are registered with an external event listener that has the ability to
             either accept or reject the change in the value of a constrained
             property.
         • Can be retrieved using the get method. The prototype of the get
             method is:
             public string get<ConstrainedPropertyName>()
         • Can be specified using the set method. The prototype of the set method
             is:
             public string set<ConstrainedPropertyName>(String str)throws
             PropertyVetoException



 ©NIIT                  JDBC and JavaBeans              Lesson 2B / Slide 12 of 26
Working with JavaBean Properties and Events


Handling Events in JavaBeans
    •    User-defined JavaBeans interact with the help of user-defined events, which
         are also called custom events.
    •    You can use the Java event delegation model to handle these custom events.
    •    The components of the event delegation model are:
         • Event Source: Generates the event and informs all the event listeners
              that are registered with it.
         • Event Listener: Receives the notification, when an event source
              generates an event.
         • Event Object: Represents the various types of events that can be
              generated by the event sources.




 ©NIIT                   JDBC and JavaBeans               Lesson 2B / Slide 13 of 26
Working with JavaBean Properties and Events


Handling Events in JavaBeans
  (Contd.)
    •    Creating Custom Events
         • The classes and interfaces that you need to define to create the custom
              JavaBean events are:
              • An event class to define a custom JavaBean event.
              • An event listener interface for the custom JavaBean event.
              • An event handler to process the custom JavaBean event.
              • A target Java application that implements the custom event.




 ©NIIT                  JDBC and JavaBeans               Lesson 2B / Slide 14 of 26
Working with JavaBean Properties and Events


Handling Events in JavaBeans (Contd.)
    •    Creating the Event Class
         • The event class that defines the custom event extends the EventObject
              class of the java.util package. For example,
              public class NumberEvent extends EventObject
              {
                   public int number1,number2;
                   public NumberEvent(Object o,int number1,int number2)
                   {
                              super(o);
                              this.number1=number1;
                              this.number2=number2;
                   }
              }



 ©NIIT                  JDBC and JavaBeans             Lesson 2B / Slide 15 of 26
Working with JavaBean Properties and Events


Handling Events in JavaBeans
  (Contd.)
    •    Creating Event Listeners
         • When the event source triggers an event, it sends a notification to the
              event listener interface.
         • The event listener interface implements the java.util.EventListener
              interface.
         • The target application that uses the custom event implements the
              custom listener. For example,
              public interface NumberEnteredListener extends EventListener
              {
              public void arithmeticPerformed(NumberEvent mec);
              }




 ©NIIT                  JDBC and JavaBeans               Lesson 2B / Slide 16 of 26
Working with JavaBean Properties and Events


Handling Events in JavaBeans
  (Contd.)
    •    Creating Event Handler
         • Custom event handlers should define the following methods:
              • addXXListener(): Registers listeners of a JavaBean event.
              • fireXX(): Notifies the listeners of the occurrence of a JavaBean
                   event.
              • removeXXListener(): Removes a listener from the list of
                   registered listeners of a JavaBean.




 ©NIIT                   JDBC and JavaBeans              Lesson 2B / Slide 17 of 26
Working with JavaBean Properties and Events


Handling Events in JavaBeans
  (Contd.)
         •   The code snippet to define an event handler for the custom event
             NumberEvent is:
             public class NumberBean extends JPanel implements
                  ActionListener
             {
                  public NumberBean()
                  {}
                  NumberEnteredListener mel;
                  public void addNumberListener(NumberEnteredListener mel)
                  {
                           this.mel = mel;
                  }


 ©NIIT                 JDBC and JavaBeans             Lesson 2B / Slide 18 of 26
Working with JavaBean Properties and Events


Handling Events in JavaBeans
  (Contd.)
             /* The following method is used to notify all listeners
             about the completion of data entry */
             NumberEvent mec;
             public void fireNumberEvent(NumberEvent mec)
             {
                      mel.arithmeticPerformed(mec);
             }
             public void actionPerformed(ActionEvent ae)
             {
                      ..
                      ..
             }
         }
 ©NIIT            JDBC and JavaBeans           Lesson 2B / Slide 19 of 26
Working with JavaBean Properties and Events


Handling Events in JavaBeans
  (Contd.)
    •    Using Custom Event in a Target Application
         • A target application, which uses the JavaBean that fires the custom
              event, must first register itself as a listener of the event.
         • A target application must define the code to specify what has to be
              done when the custom event is fired.
         • For example, a sample target application that uses the NumberEvent
              custom event accepts two numbers as input from an end user, fires the
              custom event, and displays the result of adding two numbers.




 ©NIIT                   JDBC and JavaBeans               Lesson 2B / Slide 20 of 26
Working with JavaBean Properties and Events


Demonstration-Creating User-Defined
JavaBean
    •    Problem Statement


          •   A JavaBean has to be created to accept the login information
              from a customer. The JavaBean should accept the login name
              and the password. The login information will be used by
              Earnest Bank for several purposes, such as to store the login
              details in the database of Customer Call Center and ATM
              Centers of the bank. You need to create the login JavaBean
              that does the following:




 ©NIIT                JDBC and JavaBeans             Lesson 2B / Slide 21 of 26
Working with JavaBean Properties and Events


Demonstration-Creating User-Defined
JavaBean (Contd.)
         •   Provides a user-interface to accept the login name and password.




 ©NIIT                   JDBC and JavaBeans            Lesson 2B / Slide 22 of 26
Working with JavaBean Properties and Events


Demonstration-Creating User-Defined
JavaBean (Contd.)
         •   Creates an event object that stores the login information and fires
             an event every time a user logs on.
         •   You should verify the JavaBean functionality by creating a simple
             target application that checks that the name and password are not
             same.




 ©NIIT                   JDBC and JavaBeans             Lesson 2B / Slide 23 of 26
Working with JavaBean Properties and Events


Demonstration-Creating User-Defined
  JavaBean (Contd.)
    •    Solution


         •   To create the login JavaBean that uses the custom event to
             check that the login name and password are not same, the
             following tasks need to be performed:
             1. Creating an event class
             2. Creating an event listener
             3. Creating an event handler
             4. Using the custom event in a target Java application
             5. Verifying the execution of custom event




 ©NIIT                 JDBC and JavaBeans            Lesson 2B / Slide 24 of 26
Working with JavaBean Properties and Events


Summary
    In this lesson, you learned:
         • The properties of a JavaBean are the private data members of the
               JavaBean class.
         • Properties are used to define the behavior of JavaBean components.
         • The properties of a JavaBean that can have only one value at a time are
               called simple properties.
         • The boolean properties of a JavaBean can have one of the two values,
               true or false.
         • The JavaBean properties that are indexed under a single name are
               called indexed properties. The index in the property array of an indexed
               property is an integer value.
         • The bound properties of a JavaBean are registered with an external
               event listener.




 ©NIIT                    JDBC and JavaBeans                Lesson 2B / Slide 25 of 26
Working with JavaBean Properties and Events


Summary (Contd.)
         •   The constrained properties of a JavaBean are also registered with an
             external listener. The external event listener for the constrained
             property can revert the changes in the value of JavaBean property, if
             the change is invalid.
         •   The event delegation model of Java is used to handle custom events.
         •   The event source generates an event.
         •   The event listener interfaces are notified, when an event is generated.
         •   The event classes define the various events that can be generated by
             the event source.
         •   The steps to create a custom event and implement it in a target
             application are:
             • Create an event class.
             • Create an event listener interface.
             • Create an event handler JavaBean to process the event.
             • Create a target application to implement the custom event. `
 ©NIIT                  JDBC and JavaBeans                 Lesson 2B / Slide 26 of 26

More Related Content

What's hot

Session 5 Tp5
Session 5 Tp5Session 5 Tp5
Session 5 Tp5phanleson
 
Java session16
Java session16Java session16
Java session16Niit Care
 
Vb.net session 16
Vb.net session 16Vb.net session 16
Vb.net session 16Niit Care
 
Introduction to JPA and Hibernate including examples
Introduction to JPA and Hibernate including examplesIntroduction to JPA and Hibernate including examples
Introduction to JPA and Hibernate including examplesecosio GmbH
 
Hibernate inheritance and relational mappings with examples
Hibernate inheritance and relational mappings with examplesHibernate inheritance and relational mappings with examples
Hibernate inheritance and relational mappings with examplesEr. Gaurav Kumar
 
Java questions with answers
Java questions with answersJava questions with answers
Java questions with answersKuntal Bhowmick
 
Java Web Programming Using Cloud Platform: Module 3
Java Web Programming Using Cloud Platform: Module 3Java Web Programming Using Cloud Platform: Module 3
Java Web Programming Using Cloud Platform: Module 3IMC Institute
 
ORM Concepts and JPA 2.0 Specifications
ORM Concepts and JPA 2.0 SpecificationsORM Concepts and JPA 2.0 Specifications
ORM Concepts and JPA 2.0 SpecificationsAhmed Ramzy
 
JUG Berlin Brandenburg: What's new in Java EE 7?
JUG Berlin Brandenburg: What's new in Java EE 7?JUG Berlin Brandenburg: What's new in Java EE 7?
JUG Berlin Brandenburg: What's new in Java EE 7?gedoplan
 

What's hot (20)

Javabean1
Javabean1Javabean1
Javabean1
 
Dacj 2-2 c
Dacj 2-2 cDacj 2-2 c
Dacj 2-2 c
 
Session 5 Tp5
Session 5 Tp5Session 5 Tp5
Session 5 Tp5
 
Java session16
Java session16Java session16
Java session16
 
Java Beans
Java BeansJava Beans
Java Beans
 
Java EE and Glassfish
Java EE and GlassfishJava EE and Glassfish
Java EE and Glassfish
 
Jpa
JpaJpa
Jpa
 
Vb.net session 16
Vb.net session 16Vb.net session 16
Vb.net session 16
 
Introduction to JPA and Hibernate including examples
Introduction to JPA and Hibernate including examplesIntroduction to JPA and Hibernate including examples
Introduction to JPA and Hibernate including examples
 
Hibernate inheritance and relational mappings with examples
Hibernate inheritance and relational mappings with examplesHibernate inheritance and relational mappings with examples
Hibernate inheritance and relational mappings with examples
 
Java beans
Java beansJava beans
Java beans
 
Java questions with answers
Java questions with answersJava questions with answers
Java questions with answers
 
introduction of Java beans
introduction of Java beansintroduction of Java beans
introduction of Java beans
 
Java Web Programming Using Cloud Platform: Module 3
Java Web Programming Using Cloud Platform: Module 3Java Web Programming Using Cloud Platform: Module 3
Java Web Programming Using Cloud Platform: Module 3
 
Bean Intro
Bean IntroBean Intro
Bean Intro
 
Java beans
Java beansJava beans
Java beans
 
ORM Concepts and JPA 2.0 Specifications
ORM Concepts and JPA 2.0 SpecificationsORM Concepts and JPA 2.0 Specifications
ORM Concepts and JPA 2.0 Specifications
 
JUG Berlin Brandenburg: What's new in Java EE 7?
JUG Berlin Brandenburg: What's new in Java EE 7?JUG Berlin Brandenburg: What's new in Java EE 7?
JUG Berlin Brandenburg: What's new in Java EE 7?
 
Jdbc sasidhar
Jdbc  sasidharJdbc  sasidhar
Jdbc sasidhar
 
Javabeans
JavabeansJavabeans
Javabeans
 

Viewers also liked

Regiones del noa y cronología
Regiones del noa y cronologíaRegiones del noa y cronología
Regiones del noa y cronologíaRoberto Rios
 
Presentación1.pptx-
 Presentación1.pptx- Presentación1.pptx-
Presentación1.pptx-eva94
 
Managing Current Liabilities (Gitman)
Managing Current Liabilities (Gitman)Managing Current Liabilities (Gitman)
Managing Current Liabilities (Gitman)Mikee Bylss
 
Case study marki Krakus z Albumu Superbrands Polska 2016
Case study marki Krakus z Albumu Superbrands Polska 2016 Case study marki Krakus z Albumu Superbrands Polska 2016
Case study marki Krakus z Albumu Superbrands Polska 2016 Superbrands Polska
 
La civilización en Egipto. 1ºESO, Curso 2016
La civilización en Egipto. 1ºESO, Curso 2016La civilización en Egipto. 1ºESO, Curso 2016
La civilización en Egipto. 1ºESO, Curso 2016Chema R.
 
Tema 2.2º ESO. La península Ibérica durante el reino visigodo.
Tema 2.2º ESO. La península Ibérica durante el reino visigodo.Tema 2.2º ESO. La península Ibérica durante el reino visigodo.
Tema 2.2º ESO. La península Ibérica durante el reino visigodo.Chema R.
 
Religions of europe maps
Religions of europe mapsReligions of europe maps
Religions of europe mapsDavid Poss
 
7.7 kingdoms of europe powerpoint
7.7 kingdoms of europe powerpoint7.7 kingdoms of europe powerpoint
7.7 kingdoms of europe powerpointDavid Poss
 
Chapter 14, lesson 4 enslaved people in the south
Chapter 14, lesson 4   enslaved people in the southChapter 14, lesson 4   enslaved people in the south
Chapter 14, lesson 4 enslaved people in the southDavid Poss
 

Viewers also liked (14)

Nómina de inscriptos cursos de verano 2012
Nómina de inscriptos cursos de verano 2012Nómina de inscriptos cursos de verano 2012
Nómina de inscriptos cursos de verano 2012
 
Regiones del noa y cronología
Regiones del noa y cronologíaRegiones del noa y cronología
Regiones del noa y cronología
 
Presentación1.pptx-
 Presentación1.pptx- Presentación1.pptx-
Presentación1.pptx-
 
COC - MySQL Performance Tuning
COC - MySQL Performance TuningCOC - MySQL Performance Tuning
COC - MySQL Performance Tuning
 
Civilizaciones Egipto.
Civilizaciones Egipto.Civilizaciones Egipto.
Civilizaciones Egipto.
 
Introduccion al Metabolismo
Introduccion al MetabolismoIntroduccion al Metabolismo
Introduccion al Metabolismo
 
Managing Current Liabilities (Gitman)
Managing Current Liabilities (Gitman)Managing Current Liabilities (Gitman)
Managing Current Liabilities (Gitman)
 
Resumen parcial
Resumen parcialResumen parcial
Resumen parcial
 
Case study marki Krakus z Albumu Superbrands Polska 2016
Case study marki Krakus z Albumu Superbrands Polska 2016 Case study marki Krakus z Albumu Superbrands Polska 2016
Case study marki Krakus z Albumu Superbrands Polska 2016
 
La civilización en Egipto. 1ºESO, Curso 2016
La civilización en Egipto. 1ºESO, Curso 2016La civilización en Egipto. 1ºESO, Curso 2016
La civilización en Egipto. 1ºESO, Curso 2016
 
Tema 2.2º ESO. La península Ibérica durante el reino visigodo.
Tema 2.2º ESO. La península Ibérica durante el reino visigodo.Tema 2.2º ESO. La península Ibérica durante el reino visigodo.
Tema 2.2º ESO. La península Ibérica durante el reino visigodo.
 
Religions of europe maps
Religions of europe mapsReligions of europe maps
Religions of europe maps
 
7.7 kingdoms of europe powerpoint
7.7 kingdoms of europe powerpoint7.7 kingdoms of europe powerpoint
7.7 kingdoms of europe powerpoint
 
Chapter 14, lesson 4 enslaved people in the south
Chapter 14, lesson 4   enslaved people in the southChapter 14, lesson 4   enslaved people in the south
Chapter 14, lesson 4 enslaved people in the south
 

Similar to Dacj 4 2-b

Similar to Dacj 4 2-b (20)

Dacj 4 2-a
Dacj 4 2-aDacj 4 2-a
Dacj 4 2-a
 
CommercialSystemsBahman.ppt
CommercialSystemsBahman.pptCommercialSystemsBahman.ppt
CommercialSystemsBahman.ppt
 
Java beans
Java beansJava beans
Java beans
 
Lecture 8 Enterprise Java Beans (EJB)
Lecture 8  Enterprise Java Beans (EJB)Lecture 8  Enterprise Java Beans (EJB)
Lecture 8 Enterprise Java Beans (EJB)
 
Dacj 4 1-a
Dacj 4 1-aDacj 4 1-a
Dacj 4 1-a
 
javabeans
javabeansjavabeans
javabeans
 
Unit4wt
Unit4wtUnit4wt
Unit4wt
 
Unit4wt
Unit4wtUnit4wt
Unit4wt
 
Java bean
Java beanJava bean
Java bean
 
P20CSP105-AdvJavaProg.pptx
P20CSP105-AdvJavaProg.pptxP20CSP105-AdvJavaProg.pptx
P20CSP105-AdvJavaProg.pptx
 
Introduction to EJB
Introduction to EJBIntroduction to EJB
Introduction to EJB
 
Lecture 9 - Java Persistence, JPA 2
Lecture 9 - Java Persistence, JPA 2Lecture 9 - Java Persistence, JPA 2
Lecture 9 - Java Persistence, JPA 2
 
The Latest in Enterprise JavaBeans Technology
The Latest in Enterprise JavaBeans TechnologyThe Latest in Enterprise JavaBeans Technology
The Latest in Enterprise JavaBeans Technology
 
30 perfms~access~vba~programming
30 perfms~access~vba~programming30 perfms~access~vba~programming
30 perfms~access~vba~programming
 
Ejb (1)
Ejb (1)Ejb (1)
Ejb (1)
 
AAI-1713 Introduction to Java EE 7
AAI-1713 Introduction to Java EE 7AAI-1713 Introduction to Java EE 7
AAI-1713 Introduction to Java EE 7
 
AAI 1713-Introduction to Java EE 7
AAI 1713-Introduction to Java EE 7AAI 1713-Introduction to Java EE 7
AAI 1713-Introduction to Java EE 7
 
Dacj 1-2 b
Dacj 1-2 bDacj 1-2 b
Dacj 1-2 b
 
WEB PROGRAMMING UNIT IV NOTES BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT IV NOTES BY BHAVSINGH MALOTHWEB PROGRAMMING UNIT IV NOTES BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT IV NOTES BY BHAVSINGH MALOTH
 
Building gui
Building guiBuilding gui
Building gui
 

More from Niit Care (20)

Ajs 1 b
Ajs 1 bAjs 1 b
Ajs 1 b
 
Ajs 4 b
Ajs 4 bAjs 4 b
Ajs 4 b
 
Ajs 4 a
Ajs 4 aAjs 4 a
Ajs 4 a
 
Ajs 4 c
Ajs 4 cAjs 4 c
Ajs 4 c
 
Ajs 3 b
Ajs 3 bAjs 3 b
Ajs 3 b
 
Ajs 3 a
Ajs 3 aAjs 3 a
Ajs 3 a
 
Ajs 3 c
Ajs 3 cAjs 3 c
Ajs 3 c
 
Ajs 2 b
Ajs 2 bAjs 2 b
Ajs 2 b
 
Ajs 2 a
Ajs 2 aAjs 2 a
Ajs 2 a
 
Ajs 2 c
Ajs 2 cAjs 2 c
Ajs 2 c
 
Ajs 1 a
Ajs 1 aAjs 1 a
Ajs 1 a
 
Ajs 1 c
Ajs 1 cAjs 1 c
Ajs 1 c
 
Dacj 1-3 c
Dacj 1-3 cDacj 1-3 c
Dacj 1-3 c
 
Dacj 1-3 b
Dacj 1-3 bDacj 1-3 b
Dacj 1-3 b
 
Dacj 1-3 a
Dacj 1-3 aDacj 1-3 a
Dacj 1-3 a
 
Dacj 1-2 c
Dacj 1-2 cDacj 1-2 c
Dacj 1-2 c
 
Dacj 1-2 a
Dacj 1-2 aDacj 1-2 a
Dacj 1-2 a
 
Dacj 1-1 c
Dacj 1-1 cDacj 1-1 c
Dacj 1-1 c
 
Dacj 1-1 b
Dacj 1-1 bDacj 1-1 b
Dacj 1-1 b
 
Dacj 1-1 a
Dacj 1-1 aDacj 1-1 a
Dacj 1-1 a
 

Recently uploaded

AI mind or machine power point presentation
AI mind or machine power point presentationAI mind or machine power point presentation
AI mind or machine power point presentationyogeshlabana357357
 
How we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdfHow we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdfSrushith Repakula
 
Design and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data ScienceDesign and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data SciencePaolo Missier
 
Cyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptx
Cyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptxCyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptx
Cyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptxMasterG
 
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...ScyllaDB
 
“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf
“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf
“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdfMuhammad Subhan
 
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...ScyllaDB
 
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...panagenda
 
Introduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptxIntroduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptxFIDO Alliance
 
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc
 
Long journey of Ruby Standard library at RubyKaigi 2024
Long journey of Ruby Standard library at RubyKaigi 2024Long journey of Ruby Standard library at RubyKaigi 2024
Long journey of Ruby Standard library at RubyKaigi 2024Hiroshi SHIBATA
 
The Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and InsightThe Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and InsightSafe Software
 
Top 10 CodeIgniter Development Companies
Top 10 CodeIgniter Development CompaniesTop 10 CodeIgniter Development Companies
Top 10 CodeIgniter Development CompaniesTopCSSGallery
 
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPTiSEO AI
 
TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024Stephen Perrenod
 
Revolutionizing SAP® Processes with Automation and Artificial Intelligence
Revolutionizing SAP® Processes with Automation and Artificial IntelligenceRevolutionizing SAP® Processes with Automation and Artificial Intelligence
Revolutionizing SAP® Processes with Automation and Artificial IntelligencePrecisely
 
UiPath manufacturing technology benefits and AI overview
UiPath manufacturing technology benefits and AI overviewUiPath manufacturing technology benefits and AI overview
UiPath manufacturing technology benefits and AI overviewDianaGray10
 
Generative AI Use Cases and Applications.pdf
Generative AI Use Cases and Applications.pdfGenerative AI Use Cases and Applications.pdf
Generative AI Use Cases and Applications.pdfalexjohnson7307
 
Design Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptxDesign Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptxFIDO Alliance
 

Recently uploaded (20)

AI mind or machine power point presentation
AI mind or machine power point presentationAI mind or machine power point presentation
AI mind or machine power point presentation
 
How we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdfHow we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdf
 
Design and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data ScienceDesign and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data Science
 
Overview of Hyperledger Foundation
Overview of Hyperledger FoundationOverview of Hyperledger Foundation
Overview of Hyperledger Foundation
 
Cyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptx
Cyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptxCyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptx
Cyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptx
 
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
 
“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf
“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf
“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf
 
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
 
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
 
Introduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptxIntroduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptx
 
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
 
Long journey of Ruby Standard library at RubyKaigi 2024
Long journey of Ruby Standard library at RubyKaigi 2024Long journey of Ruby Standard library at RubyKaigi 2024
Long journey of Ruby Standard library at RubyKaigi 2024
 
The Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and InsightThe Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and Insight
 
Top 10 CodeIgniter Development Companies
Top 10 CodeIgniter Development CompaniesTop 10 CodeIgniter Development Companies
Top 10 CodeIgniter Development Companies
 
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
 
TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024
 
Revolutionizing SAP® Processes with Automation and Artificial Intelligence
Revolutionizing SAP® Processes with Automation and Artificial IntelligenceRevolutionizing SAP® Processes with Automation and Artificial Intelligence
Revolutionizing SAP® Processes with Automation and Artificial Intelligence
 
UiPath manufacturing technology benefits and AI overview
UiPath manufacturing technology benefits and AI overviewUiPath manufacturing technology benefits and AI overview
UiPath manufacturing technology benefits and AI overview
 
Generative AI Use Cases and Applications.pdf
Generative AI Use Cases and Applications.pdfGenerative AI Use Cases and Applications.pdf
Generative AI Use Cases and Applications.pdf
 
Design Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptxDesign Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptx
 

Dacj 4 2-b

  • 1. Working with JavaBean Properties and Events Pre-assessment Questions 1. You need to create an application that validates the username and password of various employees in a company using the entries in the employee database. The application validates the username and password every time the employee makes a request for the database records, reports, or company resources. Select the type of JavaBean that should be used to create such an application. a. Control JavaBean b. Container JavaBean c. Invisible runtime JavaBean d. Hidden JavaBean ©NIIT JDBC and JavaBeans Lesson 2B / Slide 1 of 26
  • 2. Working with JavaBean Properties and Events Pre-assessment Questions (Contd.) 1. Which of the file enables you to start the BDK in the Windows environment? a. run.bat b. run.sh c. bdkrun.bat d. bdkrun.sh 2. What is the name of the BDK window that lists the pre-defined events for a sample JavaBean? a. EventListener b. EventTargetDialog c. actionPerformedDialog d. Properties ©NIIT JDBC and JavaBeans Lesson 2B / Slide 2 of 26
  • 3. Working with JavaBean Properties and Events Pre-assessment Questions (Contd.) 1. The compressed file for a JavaBean application are stored as: a. Manifest file b. Event file c. JAR file d. BeanInfo file 3. How can you modify the public properties of a JavaBean in the BDK environment? a. Using property editors b. Using property sheets c. Using properties pallete d. Using BeanBox window ©NIIT JDBC and JavaBeans Lesson 2B / Slide 3 of 26
  • 4. Working with JavaBean Properties and Events Solutions to Pre-assessment Questions • a. Control JavaBean • a. run.bat • b. EventTargetDialog • c. JAR file • b. Using property sheets ©NIIT JDBC and JavaBeans Lesson 2B / Slide 4 of 26
  • 5. Working with JavaBean Properties and Events Objectives In this lesson, you will learn about: • Different types of JavaBean properties • Creating custom events • Using JavaBeans in applications ©NIIT JDBC and JavaBeans Lesson 2B / Slide 5 of 26
  • 6. Working with JavaBean Properties and Events JavaBean Properties • JavaBean properties: • Are the private data members of the JavaBean classes. • Are used to accept input from an end user in order to customize a JavaBean. • Can retrieve and specify the values of various attributes, which determine the behavior of a JavaBean. ©NIIT JDBC and JavaBeans Lesson 2B / Slide 6 of 26
  • 7. Working with JavaBean Properties and Events JavaBean Properties (Contd.) • Types of JavaBeans Properties • Simple properties • Boolean properties • Indexed properties • Bound properties • Constrained properties ©NIIT JDBC and JavaBeans Lesson 2B / Slide 7 of 26
  • 8. Working with JavaBean Properties and Events JavaBean Properties (Contd.) • Simple Properties: • Refer to the private variables of a JavaBean that can have only a single value. • Are retrieved and specified using the get and set methods respectively. • The syntax of get method is: public return_type get<PropertyName>() • The syntax of set method is: public void set<PropertyName>(data_type value) ©NIIT JDBC and JavaBeans Lesson 2B / Slide 8 of 26
  • 9. Working with JavaBean Properties and Events JavaBean Properties (Contd.) • Boolean Properties: • Have either of the two values, TRUE or FALSE. • Are retrieved and specified using the following methods: • public boolean is<PropertyName>() • public boolean get<PropertyName>() • public void set<PropertyName>(boolean value) ©NIIT JDBC and JavaBeans Lesson 2B / Slide 9 of 26
  • 10. Working with JavaBean Properties and Events JavaBean Properties (Contd.) • Indexed Properties: • Are indexed under a single name, with each index being an integer value. • Enable you to set or retrieve the values from an array of property values. • Are retrieved using the following get methods: • public int[] get<PropertyName>() • public property_datatype get<PropertyName>(int index) • Are specified using the following set methods: • public void set<PropertyName>(int index, property_datatype value) • public void set<PropertyName>(property_datatype[] property_array) ©NIIT JDBC and JavaBeans Lesson 2B / Slide 10 of 26
  • 11. Working with JavaBean Properties and Events JavaBean Properties (Contd.) • Bound Properties: • Are the properties of a JavaBean that inform its listeners about changes in its values. • Are implemented using the PropertyChangeSupport class and its methods. • Are always registered with an external event listener. ©NIIT JDBC and JavaBeans Lesson 2B / Slide 11 of 26
  • 12. Working with JavaBean Properties and Events JavaBean Properties (Contd.) • Constrained Properties: • Are the properties that are protected from being changed by other JavaBeans. • Are implemented using the VetoableChangeSupport class. • Are registered with an external event listener that has the ability to either accept or reject the change in the value of a constrained property. • Can be retrieved using the get method. The prototype of the get method is: public string get<ConstrainedPropertyName>() • Can be specified using the set method. The prototype of the set method is: public string set<ConstrainedPropertyName>(String str)throws PropertyVetoException ©NIIT JDBC and JavaBeans Lesson 2B / Slide 12 of 26
  • 13. Working with JavaBean Properties and Events Handling Events in JavaBeans • User-defined JavaBeans interact with the help of user-defined events, which are also called custom events. • You can use the Java event delegation model to handle these custom events. • The components of the event delegation model are: • Event Source: Generates the event and informs all the event listeners that are registered with it. • Event Listener: Receives the notification, when an event source generates an event. • Event Object: Represents the various types of events that can be generated by the event sources. ©NIIT JDBC and JavaBeans Lesson 2B / Slide 13 of 26
  • 14. Working with JavaBean Properties and Events Handling Events in JavaBeans (Contd.) • Creating Custom Events • The classes and interfaces that you need to define to create the custom JavaBean events are: • An event class to define a custom JavaBean event. • An event listener interface for the custom JavaBean event. • An event handler to process the custom JavaBean event. • A target Java application that implements the custom event. ©NIIT JDBC and JavaBeans Lesson 2B / Slide 14 of 26
  • 15. Working with JavaBean Properties and Events Handling Events in JavaBeans (Contd.) • Creating the Event Class • The event class that defines the custom event extends the EventObject class of the java.util package. For example, public class NumberEvent extends EventObject { public int number1,number2; public NumberEvent(Object o,int number1,int number2) { super(o); this.number1=number1; this.number2=number2; } } ©NIIT JDBC and JavaBeans Lesson 2B / Slide 15 of 26
  • 16. Working with JavaBean Properties and Events Handling Events in JavaBeans (Contd.) • Creating Event Listeners • When the event source triggers an event, it sends a notification to the event listener interface. • The event listener interface implements the java.util.EventListener interface. • The target application that uses the custom event implements the custom listener. For example, public interface NumberEnteredListener extends EventListener { public void arithmeticPerformed(NumberEvent mec); } ©NIIT JDBC and JavaBeans Lesson 2B / Slide 16 of 26
  • 17. Working with JavaBean Properties and Events Handling Events in JavaBeans (Contd.) • Creating Event Handler • Custom event handlers should define the following methods: • addXXListener(): Registers listeners of a JavaBean event. • fireXX(): Notifies the listeners of the occurrence of a JavaBean event. • removeXXListener(): Removes a listener from the list of registered listeners of a JavaBean. ©NIIT JDBC and JavaBeans Lesson 2B / Slide 17 of 26
  • 18. Working with JavaBean Properties and Events Handling Events in JavaBeans (Contd.) • The code snippet to define an event handler for the custom event NumberEvent is: public class NumberBean extends JPanel implements ActionListener { public NumberBean() {} NumberEnteredListener mel; public void addNumberListener(NumberEnteredListener mel) { this.mel = mel; } ©NIIT JDBC and JavaBeans Lesson 2B / Slide 18 of 26
  • 19. Working with JavaBean Properties and Events Handling Events in JavaBeans (Contd.) /* The following method is used to notify all listeners about the completion of data entry */ NumberEvent mec; public void fireNumberEvent(NumberEvent mec) { mel.arithmeticPerformed(mec); } public void actionPerformed(ActionEvent ae) { .. .. } } ©NIIT JDBC and JavaBeans Lesson 2B / Slide 19 of 26
  • 20. Working with JavaBean Properties and Events Handling Events in JavaBeans (Contd.) • Using Custom Event in a Target Application • A target application, which uses the JavaBean that fires the custom event, must first register itself as a listener of the event. • A target application must define the code to specify what has to be done when the custom event is fired. • For example, a sample target application that uses the NumberEvent custom event accepts two numbers as input from an end user, fires the custom event, and displays the result of adding two numbers. ©NIIT JDBC and JavaBeans Lesson 2B / Slide 20 of 26
  • 21. Working with JavaBean Properties and Events Demonstration-Creating User-Defined JavaBean • Problem Statement • A JavaBean has to be created to accept the login information from a customer. The JavaBean should accept the login name and the password. The login information will be used by Earnest Bank for several purposes, such as to store the login details in the database of Customer Call Center and ATM Centers of the bank. You need to create the login JavaBean that does the following: ©NIIT JDBC and JavaBeans Lesson 2B / Slide 21 of 26
  • 22. Working with JavaBean Properties and Events Demonstration-Creating User-Defined JavaBean (Contd.) • Provides a user-interface to accept the login name and password. ©NIIT JDBC and JavaBeans Lesson 2B / Slide 22 of 26
  • 23. Working with JavaBean Properties and Events Demonstration-Creating User-Defined JavaBean (Contd.) • Creates an event object that stores the login information and fires an event every time a user logs on. • You should verify the JavaBean functionality by creating a simple target application that checks that the name and password are not same. ©NIIT JDBC and JavaBeans Lesson 2B / Slide 23 of 26
  • 24. Working with JavaBean Properties and Events Demonstration-Creating User-Defined JavaBean (Contd.) • Solution • To create the login JavaBean that uses the custom event to check that the login name and password are not same, the following tasks need to be performed: 1. Creating an event class 2. Creating an event listener 3. Creating an event handler 4. Using the custom event in a target Java application 5. Verifying the execution of custom event ©NIIT JDBC and JavaBeans Lesson 2B / Slide 24 of 26
  • 25. Working with JavaBean Properties and Events Summary In this lesson, you learned: • The properties of a JavaBean are the private data members of the JavaBean class. • Properties are used to define the behavior of JavaBean components. • The properties of a JavaBean that can have only one value at a time are called simple properties. • The boolean properties of a JavaBean can have one of the two values, true or false. • The JavaBean properties that are indexed under a single name are called indexed properties. The index in the property array of an indexed property is an integer value. • The bound properties of a JavaBean are registered with an external event listener. ©NIIT JDBC and JavaBeans Lesson 2B / Slide 25 of 26
  • 26. Working with JavaBean Properties and Events Summary (Contd.) • The constrained properties of a JavaBean are also registered with an external listener. The external event listener for the constrained property can revert the changes in the value of JavaBean property, if the change is invalid. • The event delegation model of Java is used to handle custom events. • The event source generates an event. • The event listener interfaces are notified, when an event is generated. • The event classes define the various events that can be generated by the event source. • The steps to create a custom event and implement it in a target application are: • Create an event class. • Create an event listener interface. • Create an event handler JavaBean to process the event. • Create a target application to implement the custom event. ` ©NIIT JDBC and JavaBeans Lesson 2B / Slide 26 of 26