Copyright  Oracle Corporation, 1998. All rights reserved. 3 JavaBeans: Reusing Application Components.

Slides:



Advertisements
Similar presentations
Introduction to Java 2 Programming
Advertisements

3 Copyright © 2005, Oracle. All rights reserved. Basic Java Syntax and Coding Conventions.
15 Copyright © 2005, Oracle. All rights reserved. Adding User Interface Components and Event Handling.
6 Copyright © 2005, Oracle. All rights reserved. Building Applications with Oracle JDeveloper 10g.
Java Graphical User Interface (GUI) using Visual Editor in eclipse CSI 1390 – Java Programming Instructor: Saeid Nourian University.
Graphic User Interfaces Layout Managers Event Handling.
Copyright  Oracle Corporation, All rights reserved. 2 Java and Databases: An Overview.
Copyright  Oracle Corporation, All rights reserved. 1 Creating an Application: The AppBuilder for Java IDE.
Copyright Ó Oracle Corporation, All rights reserved Sharing Objects and Code.
Guide to Oracle10G1 Introduction To Forms Builder Chapter 5.
Java Programming, 3e Concepts and Techniques Chapter 5 Arrays, Loops, and Layout Managers Using External Classes.
A Guide to Oracle9i1 Introduction To Forms Builder Chapter 5.
CS3157 Java UI Recitation. Material Covered: Overview of AWT components, Event Handling, creating applets, and sample UI. Not covered in recitation: Drawing,
1 of 4 This document is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS OR IMPLIED, IN THIS DOCUMENT. © 2007 Microsoft Corporation.
JAVA BEANS By Madhuri Kakumanu. What is a Java Bean? “ A Java Bean is a reusable software component that can be visually manipulated in builder tools.”
With Microsoft Access 2010 © 2011 Pearson Education, Inc. Publishing as Prentice Hall1 PowerPoint Presentation to Accompany GO! with Microsoft ® Access.
23 Copyright © 2004, Oracle. All rights reserved. Sharing Objects and Code.
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
20-753: Fundamentals of Web Programming Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 16: Java Applets & AWT Fundamentals of Web Programming.
Microsoft Visual Basic 2012 Using Procedures and Exception Handling CHAPTER SEVEN.
Introduction to Graphical User Interfaces. Objectives * Students should understand what a procedural program is. * Students should understand what an.
Java Programming, 3e Concepts and Techniques Chapter 3 Section 65 – Manipulating Data Using Methods – Java Applet.
Java Software Solutions Lewis and Loftus Chapter 10 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Graphical User Interfaces --
MVC and Swing IAT 351 Week 7 Lecture/tutorial Lyn Bartram.
JavaBeans Components. To understand JavaBeans…  Proficient experience with the Java language required  Knowledge of classes and interfaces  Object-Oriented.
Copyright © 2008 Pearson Prentice Hall. All rights reserved. 11 Committed to Shaping the Next Generation of IT Experts. Chapter 5 PivotTables and Charts.
Teacher’s Assessment Assistant Worksheet Builder Starting the Program
3461A Readings from the Swing Tutorial. 3461A Overview  The follow is the Table of Contents from the trail “Creating a GUI with JFC/Swing” in the “The.
Microsoft Visual Basic 2005 CHAPTER 7 Creating Web Applications.
JavaScript, Fourth Edition Chapter 5 Validating Form Data with JavaScript.
Copyright  Oracle Corporation, All rights reserved. 4 Accessing a Database Using JBCL.
Chapter One An Introduction to Visual Basic 2010 Programming with Microsoft Visual Basic th Edition.
Objectives of This Session
Chapter 5 Quick Links Slide 2 Performance Objectives Understanding Framesets and Frames Creating Framesets and Frames Selecting Framesets and Frames Using.
Graphic User Interface. Graphic User Interface (GUI) Most of us interact with computers using GUIs. GUIs are visual representations of the actions you.
Java Bean Definition “A Java Bean is a reusable software component that can be manipulated visually in a builder tool.”
Copyright  Oracle Corporation, All rights reserved. 5 More on Creating Database Forms Using AppBuilder.
Java Applets: GUI Components, Events, Etc. Ralph Westfall June, 2010.
Applets and Frames. Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L14: GUI Slide 2 Applets Usually.
3 Copyright © 2004, Oracle. All rights reserved. Working in the Forms Developer Environment.
Object Oriented Programming.  Interface  Event Handling.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 27 JavaBeans and.
CHAPTER:08 JAVA IDE PROGRAMMING-III Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
Csc Basic Graphical User Interface (GUI) Components.
Advanced Java Session 4 New York University School of Continuing and Professional Studies.
Swinging in Your Java Playground. Background Swing is a part of the Java Foundation Classes (JFC). The JFC is made up of features intended to give a programmer.
Swing - 2 Session 13. Swing - 2 / 2 of 38 Objectives (1) Discuss trees and tables Discuss progress bars Discuss MVC architecture Describe menus.
Java Programming, Second Edition Chapter Thirteen Understanding Swing Components.
Copyright © Curt Hill More Widgets In Abstract Window Toolbox.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 32 JavaBeans and Bean.
5 Copyright © 2011, Oracle and/or its affiliates. All rights reserved. Working with Layout Editor.
JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN © 2012 Pearson Education, Inc., Upper Saddle River,
COMPUTER PROGRAMMING I 3.01 Apply Controls Associated With Visual Studio Form.
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
10 Copyright © 2004, Oracle. All rights reserved. Building ADF View Components.
22 Copyright © 2009, Oracle. All rights reserved. Filtering Requests in Oracle Business Intelligence Answers.
Developing GUIs With the Eclipse Visual Editor, Swing/AWT Edition David Gallardo.
2 Copyright © 2004, Oracle. All rights reserved. ADF Development Process.
24 Copyright © 2009, Oracle. All rights reserved. Building Views and Charts in Requests.
COMPUTER PROGRAMMING I 3.01 Apply Controls Associated With Visual Studio Form.
Lesson 3: Working with Forms. Learning Objectives After studying this lesson, you will be able to: Identify form design elements Create and print forms.
 2002 Prentice Hall. All rights reserved. 1 Introduction to the Visual Studio.NET IDE Outline Introduction Visual Studio.NET Integrated Development Environment.
16 Copyright © 2004, Oracle. All rights reserved. Building ADF UIX View Components.
Chapter 5 Validating Form Data with JavaScript
Java FX: Scene Builder.
Using Procedures and Exception Handling
Chap 7. Building Java Graphical User Interfaces
Graphical User Interfaces -- Introduction
AWT Components and Containers
Presentation transcript:

Copyright  Oracle Corporation, All rights reserved. 3 JavaBeans: Reusing Application Components

Copyright  Oracle Corporation, All rights reserved. 3-2 Objectives After completing this lesson, you should be able to do the following: Describe the JavaBeans architecture Identify the properties, methods, and events for a JavaBean Use JavaBeans provided in the JavaBeans Component Library (JBCL) After completing this lesson, you should be able to do the following: Describe the JavaBeans architecture Identify the properties, methods, and events for a JavaBean Use JavaBeans provided in the JavaBeans Component Library (JBCL)

Copyright  Oracle Corporation, All rights reserved. 3-3 Overview A JavaBean is a reusable Java component that conforms to a standard pattern Public methods Protected methods Private methods Data Events Methods and property accessors A JavaBean component

Copyright  Oracle Corporation, All rights reserved. 3-4 The aim is to be able to construct programs as a series of components Components can be visual or nonvisual The aim is to be able to construct programs as a series of components Components can be visual or nonvisual Aim of the Component Model Word processor program Thesaurus component TextEditor component SpellChecker component

Copyright  Oracle Corporation, All rights reserved. 3-5 Components in Java: JavaBeans Any Java class has the capability of being a JavaBean, such as ButtonControl getLabel() label setLabel() requestFocus() enable() buttonControl1 Methods Properties Events

Copyright  Oracle Corporation, All rights reserved. 3-6 Assembling JavaBeans Components AppBuilder enables components to be plugged together using drag and drop Components have property sheets Design time and run time configuration AppBuilder enables components to be plugged together using drag and drop Components have property sheets Design time and run time configuration

Copyright  Oracle Corporation, All rights reserved. 3-7 The JavaBean Component Library (JBCL) AppBuilder provides many JavaBeans, in the JBCL Some of the JavaBeans are contained in the Component Palette – Grouped by category AppBuilder provides many JavaBeans, in the JBCL Some of the JavaBeans are contained in the Component Palette – Grouped by category

Copyright  Oracle Corporation, All rights reserved. 3-8 Anatomy of a JavaBean: GridControl Example GridControl is a visible JBCL JavaBean Located in the Controls tab Defined in borland.jbcl.control package GridControl is a visible JBCL JavaBean Located in the Controls tab Defined in borland.jbcl.control package

Copyright  Oracle Corporation, All rights reserved. 3-9 JavaBean Properties Properties have “get” and “set” methods // Possible implementation public class GridControl … { private int columnHeaderHeight; public int getColumnHeaderHeight() { return columnHeaderHeight; } public void setColumnHeaderHeight(int h) { columnHeaderHeight = h; } … Height of column header (pixels)

Copyright  Oracle Corporation, All rights reserved JavaBean boolean Properties boolean property methods have a different name: // Possible implementation public class GridControl … { private boolean multiSelect; public boolean isMultiSelect() { return multiSelect; } public void setMultiSelect(boolean m) { multiSelect = m; } … Allow multiple selection

Copyright  Oracle Corporation, All rights reserved Accessing Properties at Run Time The get and set methods for a property can be called at run time public class MyClass { public void myMethod() { boolean b = gridControl1.isEnabled(); gridControl1.setEnabled(!b); b = gridControl1.isColumnHeaderVisible(); gridControl1.setColumnHeaderVisible(!b); }

Copyright  Oracle Corporation, All rights reserved Examining Properties in the Help System The Help System defines properties for each component 2 1

Copyright  Oracle Corporation, All rights reserved Property Editors for More Complex Properties Property Editors can be provided to edit more complex properties at design time Background color

Copyright  Oracle Corporation, All rights reserved Guided Practice: Using Property Editors If a GridControl is added to an applet: How can you specify the items property? How is the items property defined in the GridControl class? How are the accessor methods defined? If a GridControl is added to an applet: How can you specify the items property? How is the items property defined in the GridControl class? How are the accessor methods defined?

Copyright  Oracle Corporation, All rights reserved JavaBean Methods JavaBeans provide public methods, as for a regular class

Copyright  Oracle Corporation, All rights reserved Using JavaBean Methods You can use JavaBean methods in your code, to manipulate the component public class MyClass { public void myMethod() { for (int r = 0; r < 3; r++) { gc1.addRow(); gc1.addColumn(); } for (int r = 0; r < gc1.getRowCount(); r++) gc1.set(r, 0, "hello row " + r + " col 0"); }

Copyright  Oracle Corporation, All rights reserved JavaBean Events JavaBeans generate events to notify listeners when something important happens Can use existing event types, or define custom event types New event types extend EventObject JavaBeans generate events to notify listeners when something important happens Can use existing event types, or define custom event types New event types extend EventObject XYZEvent EventObject

Copyright  Oracle Corporation, All rights reserved Event Listeners For each type of event, there is an “event listener” interface Listeners must implement this interface JavaBean provides methods to add and remove listener objects For each type of event, there is an “event listener” interface Listeners must implement this interface JavaBean provides methods to add and remove listener objects Listener implements XYZListener handler method XYZEvent addXYZListener JavaBean component (event source)

Copyright  Oracle Corporation, All rights reserved Examining Events in the Help System The Help System defines the event listeners for each component Notice the model event listener The Help System defines the event listeners for each component Notice the model event listener

Copyright  Oracle Corporation, All rights reserved JBCL Components Use the Model-View Architecture “View” object defines visual appearance “Model” object maintains the data “View” object defines visual appearance “Model” object maintains the data Model type Singleton Vector Matrix Graph Description Single data item (used by text fields) List of items (used by list controls) Table of items (used by grid controls) Tree of items (used by tree controls)

Copyright  Oracle Corporation, All rights reserved Dealing with Model Events GridControl generates model events when its data changes Model content changed event GridControl generates model events when its data changes Model content changed event ModelContentChanged

Copyright  Oracle Corporation, All rights reserved Guided Practice: modelContentChanged Events What is the effect of this handler method? void gridControl1_modelContentChanged (MatrixModelEvent e) { MatrixModel model = e.getModel(); MatrixLocation location = e.getLocation(); int r = location.row; int c = location.column; System.out.println(" Row: " + r + " Col: " + c + " Data: " + model.get(r, c)); }

Copyright  Oracle Corporation, All rights reserved Other JBCL Controls JBCL includes a set of controls similar to the AWT controls AWT controls Button Checkbox CheckboxGroup Choice, List Label TextArea, TextField Comparable JBCL controls ButtonControl CheckboxControl CheckboxPanel ChoiceControl, ListControl LabelControl TextAreaControl, TextFieldControl

Copyright  Oracle Corporation, All rights reserved AWT and JBCL Components Reasons to use AWT components: – Standard Java classes – Retain native appearance – Less overhead Reasons to use JBCL components: – Many are data aware – More sophisticated – Conform to model-view architecture Reasons to use AWT components: – Standard Java classes – Retain native appearance – Less overhead Reasons to use JBCL components: – Many are data aware – More sophisticated – Conform to model-view architecture

Copyright  Oracle Corporation, All rights reserved Other JBCL Components in the Controls Tab ButtonBar TabsetControl TreeControl ImageControl StatusBar

Copyright  Oracle Corporation, All rights reserved JBCL Components in the Containers Tab TabsetPanel BevelPanel SplitPanel GroupBox

Copyright  Oracle Corporation, All rights reserved JBCL Components in the Dialogs Tab Representing standard dialog boxes: Filer, ColorChooser, FontChooser Representing standard dialog boxes: Filer, ColorChooser, FontChooser

Copyright  Oracle Corporation, All rights reserved Guided Practice: Using Dialog Box Components Consider that a Filer component has been added to a program Describe the following code: How can a FontChooser be used? Consider that a Filer component has been added to a program Describe the following code: How can a FontChooser be used? void aMethod() { filer1.setMode(Filer.LOAD); filer1.setFrame(new Frame()); filer1.show(); System.out.println(filer1.getFile()); }

Copyright  Oracle Corporation, All rights reserved Summary A JavaBean is a Java component AppBuilder provides many JavaBeans in the JBCL, including: – Enhanced versions of AWT controls – Containers – Dialog boxes – Data controls, the theme of the next two lessons A JavaBean is a Java component AppBuilder provides many JavaBeans in the JBCL, including: – Enhanced versions of AWT controls – Containers – Dialog boxes – Data controls, the theme of the next two lessons

Copyright  Oracle Corporation, All rights reserved Practice 3-1 Overview Use the JBCL components to enhance the user interface Use JBCL property editors to fine tune component appearance and behavior Deal with JBCL events Work with the JBCL model-view architecture Use the JBCL components to enhance the user interface Use JBCL property editors to fine tune component appearance and behavior Deal with JBCL events Work with the JBCL model-view architecture

Copyright  Oracle Corporation, All rights reserved Full Notes Page for Practices

Copyright  Oracle Corporation, All rights reserved Full Notes Page for Practices

Copyright  Oracle Corporation, All rights reserved Full Notes Page for Practices

Copyright  Oracle Corporation, All rights reserved Full Notes Page for Practices

Copyright  Oracle Corporation, All rights reserved Full Notes Page for Practices

Copyright  Oracle Corporation, All rights reserved Full Notes Page for Practices