Chapter 6 Java Beans Component Model Outline 6
Chapter 6: Java Beans Component Model Outline 6. 1 6. 2 6. 3 6. 4 6. 5 6. 6 6. 7 6. 8 Introduction Using Beans in Forte for Java Community Edition Preparing a Class to be a Java. Bean Creating a Java. Bean: Java Archive Files Java. Bean Properties Bound Properties Indexed Properties and Custom Events Customizing Java. Beans for Builder Tools 6. 8. 1 Property. Editors 6. 8. 2 Customizers 2002 Prentice Hall. All rights reserved.
6. 1 Introduction • Java. Beans – Used for rapid application development • Assembling predefined software components – Used by a component assembler – Communicate through well-defined services (i. e. , methods) – Promote code reuse 2002 Prentice Hall. All rights reserved.
6. 2 Using Beans in Forte for Java Community Edition • Forte for Java Community Edition – Integrated development environment – Provides builder tool for assembling Java. Beans • Installing and manipulating beans – Beans must be installed before being manipulated – After being installed, beans can be inserted in Forms 2002 Prentice Hall. All rights reserved.
6. 2 Using Beans in Forte for Java Community Edition (cont. ) Fig. 6. 1 2002 Prentice Hall. All rights reserved. Forte for Java Community Edition 2. 0.
6. 2 Using Beans in Forte for Java Community Edition (cont. ) Fig. 6. 2 2002 Prentice Hall. All rights reserved. Install New Java. Bean. . . menu item.
6. 2 Using Beans in Forte for Java Community Edition (cont. ) Fig. 6. 3 2002 Prentice Hall. All rights reserved. Install Java. Bean dialog.
6. 2 Using Beans in Forte for Java Community Edition (cont. ) Fig. 6. 4 Select Java. Bean and Palette Category dialogs. 2002 Prentice Hall. All rights reserved.
6. 2 Using Beans in Forte for Java Community Edition (cont. ) Component Palette Fig. 6. 5 Beans tab in the Component Palette and tooltip for Logo. Animator Java. Bean. 2002 Prentice Hall. All rights reserved.
6. 2 Using Beans in Forte for Java Community Edition (cont. ) Fig. 6. 6 2002 Prentice Hall. All rights reserved. Filesystems tab in the Explorer window.
6. 2 Using Beans in Forte for Java Community Edition (cont. ) Fig. 6. 7 Development directory selected in Explorer window. 2002 Prentice Hall. All rights reserved.
6. 2 Using Beans in Forte for Java Community Edition (cont. ) Fig. 6. 8 2002 Prentice Hall. All rights reserved. New. . . menu item.
6. 2 Using Beans in Forte for Java Community Edition (cont. ) Fig. 6. 9 2002 Prentice Hall. All rights reserved. New. . . - Template Chooser dialog.
6. 2 Using Beans in Forte for Java Community Edition (cont. ) Fig. 6. 10 GUI Editing tab of Forte. 2002 Prentice Hall. All rights reserved.
6. 2 Using Beans in Forte for Java Community Edition (cont. ) Fig. 6. 11 Component Inspector and Form windows 2002 Prentice Hall. All rights reserved.
6. 2 Using Beans in Forte for Java Community Edition (cont. ) Fig. 6. 12 Source Editor window. 2002 Prentice Hall. All rights reserved.
6. 2 Using Beans in Forte for Java Community Edition (cont. ) Fig. 6. 13 Beans tab of the Component Palette. 2002 Prentice Hall. All rights reserved.
6. 2 Using Beans in Forte for Java Community Edition (cont. ) Fig. 6. 14 Logo. Animator icon. 2002 Prentice Hall. All rights reserved.
6. 2 Using Beans in Forte for Java Community Edition (cont. ) Fig. 6. 15 Logo. Animator animation in the Form window. 2002 Prentice Hall. All rights reserved.
6. 2 Using Beans in Forte for Java Community Edition (cont. ) Fig. 6. 16 Component Inspector with Logo. Animator Properties sheet. 2002 Prentice Hall. All rights reserved.
6. 2 Using Beans in Forte for Java Community Edition (cont. ) Fig. 6. 17 Component Inspector drop down-menu for the background property. 2002 Prentice Hall. All rights reserved.
6. 2 Using Beans in Forte for Java Community Edition (cont. ) Fig. 6. 18 Changing background color of Logo. Animator. 2002 Prentice Hall. All rights reserved.
6. 2 Using Beans in Forte for Java Community Edition (cont. ) Fig. 6. 19 Animation. Window selected in Explorer. 2002 Prentice Hall. All rights reserved.
6. 2 Using Beans in Forte for Java Community Edition (cont. ) Fig. 6. 20 Selecting Flow. Layout in the Explorer menu. 2002 Prentice Hall. All rights reserved.
6. 2 Using Beans in Forte for Java Community Edition (cont. ) Fig. 6. 21 Swing tab of the Component Palette. 2002 Prentice Hall. All rights reserved.
6. 2 Using Beans in Forte for Java Community Edition (cont. ) Fig. 6. 22 JButton icon in the Component Palette. 2002 Prentice Hall. All rights reserved.
6. 2 Using Beans in Forte for Java Community Edition (cont. ) Fig. 6. 23 Adding a JButton to Animation. Window. 2002 Prentice Hall. All rights reserved.
6. 2 Using Beans in Forte for Java Community Edition (cont. ) Fig. 6. 24 Editing text property of JButton. 2002 Prentice Hall. All rights reserved.
6. 2 Using Beans in Forte for Java Community Edition (cont. ) Fig. 6. 25 Component Palette Selection mode. 2002 Prentice Hall. All rights reserved.
6. 2 Using Beans in Forte for Java Community Edition (cont. ) Fig. 6. 26 Component Palette Connection mode. 2002 Prentice Hall. All rights reserved.
6. 2 Using Beans in Forte for Java Community Edition (cont. ) Fig. 6. 27 Select Connection mode. 2002 Prentice Hall. All rights reserved.
6. 2 Using Beans in Forte for Java Community Edition (cont. ) Fig. 6. 28 Connecting JButton and Logo. Animator. 2002 Prentice Hall. All rights reserved.
6. 2 Using Beans in Forte for Java Community Edition (cont. ) Fig. 6. 29 Connection Wizard dialog. 2002 Prentice Hall. All rights reserved.
6. 2 Using Beans in Forte for Java Community Edition (cont. ) Fig. 6. 30 Select action. Performed event. 2002 Prentice Hall. All rights reserved.
6. 2 Using Beans in Forte for Java Community Edition (cont. ) Fig. 6. 31 Selecting method start. Animation for the target component. 2002 Prentice Hall. All rights reserved.
6. 2 Using Beans in Forte for Java Community Edition (cont. ) Fig. 6. 32 Select Execute from Explorer menu. 2002 Prentice Hall. All rights reserved.
6. 2 Using Beans in Forte for Java Community Edition (cont. ) Fig. 6. 33 Animation. Window running in Forte. 2002 Prentice Hall. All rights reserved.
6. 3 Preparing a Class to be a Java. Bean • Use our Logo. Animator bean – Examine Logo. Animator. class 2002 Prentice Hall. All rights reserved.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 // Fig. 6. 34: Logo. Animator. java // Logo. Animator is a Java. Bean containing an animated logo. package com. deitel. advjhtp 1. beans; // Java core packages import java. awt. *; import java. awt. event. *; import java. io. *; import java. net. *; // Java extension packages import javax. swing. *; public class Logo. Animator extends JPanel implements Action. Listener, Serializable { protected Image. Icon images[]; protected int total. Images = 30, current. Image; protected Timer animation. Timer; // load images and start animation public Logo. Animator() { images = new Image. Icon[ total. Images ]; Outline Logo. Animator extends JPanel, making it a GUI component All Java. Beans must implements interface Serializable Fig. 6. 34 Definition of class Logo. Array of Image. Icons, which 1). Animator (part contains 30 PNG image that comprise the animated logo Line 14 Line 15 Lines 17 -33 URL url; // load animation frames for ( int i = 0; i < images. length; ++i ) { url = Log. Animator. class. get. Resource( "images/deitel" + i + ". png" ); images[ i ] = new Image. Icon( url ); } start. Animation(); 2002 Prentice Hall. All rights reserved.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 Outline } // render one frame of the animation public void paint. Component( Graphics g ) { super. paint. Component( g ); // draw current animation frame images[ current. Image ]. paint. Icon( this, g, 0, 0 ); current. Image = ( current. Image + 1 ) % total. Images; } // start Timer that drives animation public void start. Animation() { // if animation. Timer is null, restart animation if ( animation. Timer == null ) { current. Image = 0; animation. Timer = new Timer( 50, this ); animation. Timer. start(); } else // continue from last image displayed if ( !animation. Timer. is. Running() ) animation. Timer. restart(); Display next frame of animation Fig. 6. 34 Definition of class Logo. Animator (part 2). Create Timer object to invoke 44 -45 method Lines action. Performed every 50 milliseconds Lines 52 -56 Lines 65 -68 } // repaint when Timer event occurs public void action. Performed( Action. Event action. Event ) { repaint(); } Repaint screen every 50 milliseconds 2002 Prentice Hall. All rights reserved.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 // stop Timer that drives animation public void stop. Animation() { animation. Timer. stop(); } Outline // get animation preferred width and height public Dimension get. Preferred. Size() { return new Dimension( 160, 80 ); } // get animation minimum width and height public Dimension get. Minimum. Size() { return get. Preferred. Size(); } // execute bean as standalone application public static void main( String args[] ) { // create new Logo. Animator animation = new Logo. Animator(); The Layout. Manager calls these two methods to determine how to size Logo. Animator Fig. 6. 34 Definition of class Logo. Animator (part 3). Lines 77 -86 // create new JFrame with title "Animation test" JFrame application = new JFrame( "Animator test" ); application. set. Default. Close. Operation ( JFrame. EXIT_ON_CLOSE ); // add Logo. Animator to JFrame application. get. Content. Pane(). add( animation, Border. Layout. CENTER ); 2002 Prentice Hall. All rights reserved.
103 104 105 106 107 108 // set the window size and validate layout application. pack(); application. set. Visible( true ); Outline } } // end class Logo. Animator Fig. 6. 34 Definition of class Logo. Animator (part 4). 2002 Prentice Hall. All rights reserved.
6. 3 Preparing a Class to be a Java. Bean (cont. ) Fig. 6. 35 Compile option in the Source Editor menu. 2002 Prentice Hall. All rights reserved.
6. 4 Creating a Java. Bean: Java Archive Files • Java Archive Files – Also known as JAR files – Contain Java. Beans – Contains a manifest file • Describes JAR-file contents • MANIFEST. MF – Placed in the META-INF directory in JAR file 2002 Prentice Hall. All rights reserved.
1 2 3 4 Outline Main-Class: com. deitel. advjhtp 1. beans. Logo. Animator Name: com/deitel/advjhtp 1/beans/Logo. Animator. class Java-Bean: True Class Logo. Animator contains method main, so virtual machines can execute the application in this JAR file directly Specify that Logo. Animator should be treated as a Java. Bean Fig. 6. 36 Method file manifest. tmp for the Logo-Animator bean. Line 1 Line 4 2002 Prentice Hall. All rights reserved.
6. 4 Creating a Java. Bean: Java Archive Files (cont. ) Fig. 6. 37 Add images directory to Logo. Animator. jar. 2002 Prentice Hall. All rights reserved.
6. 4 Creating a Java. Bean: Java Archive Files (cont. ) Fig. 6. 38 Manifest tab of JAR Packager dialog. 2002 Prentice Hall. All rights reserved.
6. 5 Java. Bean Properties • Property – Specific attribute of a Java. Bean – Read/Write property • Defined as a set/get method pair of the form public void set. Property. Name( Data. Type value ) public Data. Type get. Property. Name() • Builder tool inspects bean methods for these pairs – Process known as introspection – Builder exposes that pair of methods as a property • e. g. , to expose the background property: public void set. Background( Color color ) public Color get. Background() 2002 Prentice Hall. All rights reserved.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 // Fig. 6. 39: Logo. Animator 2. java // Logo. Animator 2 extends Logo. Animator to include // animation. Delay property and implements Color. Listener package com. deitel. advjhtp 1. beans; Outline // Java core packages import java. awt. *; import java. awt. event. *; // Java extension packages import javax. swing. *; public class Logo. Animator 2 extends Logo. Animator { // set animation. Delay property public void set. Animation. Delay( int delay ) { animation. Timer. set. Delay( delay ); } // get animation. Delay property public int get. Animation. Delay() { return animation. Timer. get. Delay(); } Extend Logo. Animator to enable 6. 39 of animation Logouser to modify. Fig. the rate Animator 2 with property animation. Delay (part 1). Builder tool will 13 expose Line animation. Delay property Lines 16 -25 // launch Logo. Animator in JFrame for testing public static void main( String args[] ) { // create new Logo. Animator 2 animation = new Logo. Animator 2(); 2002 Prentice Hall. All rights reserved.
33 34 35 36 37 38 39 40 41 42 43 44 // create new JFrame and add Logo. Animator 2 to it JFrame application = new JFrame( "Animator test" ); application. get. Content. Pane(). add( animation, Border. Layout. CENTER ); Outline application. set. Default. Close. Operation ( JFrame. EXIT_ON_CLOSE ); application. pack(); application. set. Visible( true ); } } // end class Logo. Animator 2 Fig. 6. 39 Logo. Animator 2 with property animation. Delay (part 2). 2002 Prentice Hall. All rights reserved.
6. 5 Java. Bean Properties (cont. ) Fig. 6. 40 Logo. Animator 2 bean with property animation. Delay exposed in Forte’s Component Inspector. 2002 Prentice Hall. All rights reserved.
6. 6 Bound Properties • Bound property – Java. Bean notifies other objects when property value changes • Accomplished via standard Java event-handling features – java. beans. Property. Change. Listener • Listens for java. beans. Property. Change. Events 2002 Prentice Hall. All rights reserved.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 // Fig. 6. 41: Slider. Field. Panel. java // Slider. Field. Panel provides a slider to adjust the animation // speed of Logo. Animator 2. package com. deitel. advjhtp 1. beans; Outline // Java core packages import java. io. *; import java. awt. event. *; import java. beans. *; // Java extension packages import javax. swing. *; import javax. swing. event. *; public class Slider. Field. Panel extends JPanel implements Serializable { private JSlider slider; JText. Field field; Box box. Container; int current. Value; When the JSlider value Fig. 6. 41 Definition changes, the JText. Field value for class Slideris updated automatically with the Field. Panel new value (and vice versa) (part 1). // object to support bound property changes private Property. Change. Support change. Support ; // Slider. Field. Panel constructor public Slider. Field. Panel() { // create Property. Change. Support for bound properties change. Support = new Property. Change. Support( this ); Lines 19 -20 Lines 25 -31 Property. Change. Support provides the listener registration and notification services 2002 Prentice Hall. All rights reserved.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 Outline // initialize slider and text field slider = new JSlider( Swing. Constants. HORIZONTAL, 1, 100, 1 ); field = new JText. Field( String. value. Of( slider. get. Value() ), 5 ); // set box layout and add slider and text field box. Container = new Box( Box. Layout. X_AXIS ); box. Container. add( slider ); box. Container. add( Box. create. Horizontal. Strut( 5 ) ); box. Container. add( field ); set. Layout( new Border. Layout() ); add( box. Container ); // add Change. Listener for JSlider slider. add. Change. Listener( new Change. Listener() { Fig. 6. 41 Definition for class Slider. Register the Change. Listener Field. Panel for JSlider (part 2). // handle state change for JSlider public void state. Changed( Change. Event change. Event ) { set. Current. Value ( slider. get. Value() ); } } // end anonymous inner class ); // end call to add. Change. Listener Line 49 Line 56 When JSlider value changes, call set. Current. Value to update the JText. Field and notify registered Property. Change. Listeners of change 2002 Prentice Hall. All rights reserved.
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 Outline Register the Change. Listener for JText. Field // add Action. Listener for JText. Field field. add. Action. Listener( new Action. Listener() { // handle action for JText. Field public void action. Performed( Action. Event action. Event ) { set. Current. Value ( Integer. parse. Int( field. get. Text() ) ); } } // end anonymous inner class ); // end call to add. Action. Listener } // end Slider. Field. Panel constructor Fig. 6. 41 Definition When JSlider value changes, call for class Sliderset. Current. Value to update the Field. Panel JSlider and notify registered (part 3). Property. Change. Listeners of change // add Property. Change. Listener public void add. Property. Change. Listener ( Property. Change. Listener listener ) { change. Support. add. Property. Change. Listener ( listener ); } Line 64 Line to 69 support the Methods registration of Property. Change. Listeners Lines 83 -94 // remove Property. Change. Listener public void remove. Property. Change. Listener ( Property. Change. Listener listener ) { change. Support. remove. Property. Change. Listener ( listener ); } 2002 Prentice Hall. All rights reserved.
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 // set minimum. Value property public void set. Minimum. Value( int minimum ) { slider. set. Minimum( minimum ); Outline Builder tool will expose minimum. Value as a property if ( slider. get. Value() < slider. get. Minimum() ) { slider. set. Value( slider. get. Minimum() ); field. set. Text( String. value. Of( slider. get. Value() ) ); } } // get minimum. Value property public int get. Minimum. Value() { return slider. get. Minimum(); } // set maximum. Value property public void set. Maximum. Value( int maximum ) { slider. set. Maximum( maximum ); Fig. 6. 41 Definition for class Slider. Field. Panel (part 4). Builder tool will 97 -111 expose Lines maximum. Value as a property if ( slider. get. Value() > slider. get. Maximum() ) { slider. set. Value( slider. get. Maximum() ); field. set. Text( String. value. Of( slider. get. Value() ) ); } Lines 114 -128 } // get maximum. Value property public int get. Maximum. Value() { return slider. get. Maximum(); } 2002 Prentice Hall. All rights reserved.
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 Outline // set current. Value property public void set. Current. Value( int current ) throws Illegal. Argument. Exception { if ( current < 0 ) throw new Illegal. Argument. Exception (); int old. Value = current. Value; // set current. Value property current. Value = current; // change slider and textfield values slider. set. Value( current. Value ); field. set. Text( String. value. Of( current. Value ) ); // fire Property. Change change. Support. fire. Property. Change( "current. Value", new Integer( old. Value ), new Integer( current. Value ) ); } // get current. Value property public int get. Current. Value() { return slider. get. Value(); } // set field. Width property public void set. Field. Width( int columns ) { field. set. Columns( columns ); box. Container. validate(); } Fig. 6. 41 Definition for class Slider. Field. Panel (partwill 5). expose Builder tool current. Value as a property Lines 131 -156 current. Value is. Lines a bound property, 147 -149 because it notifies registered Property. Change. Listeners change (via Lineof 159 method fire. Property. Change) Builder tool will expose field. Width as a property 2002 Prentice Hall. All rights reserved.
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 // get field. Width property public int get. Field. Width() { return field. get. Columns(); } Builder tool will expose field. Width as a property Outline // get minimum panel size public Dimension get. Minimum. Size() { return box. Container. get. Minimum. Size(); } // get preferred panel size public Dimension get. Preferred. Size() { return box. Container. get. Preferred. Size(); } } // end class Slider. Field. Panel Fig. 6. 41 Definition for class Slider. Field. Panel (part 6). Line 166 2002 Prentice Hall. All rights reserved.
1 2 3 Outline Name: com/deitel/advjhtp 1/beans/Slider. Field. Panel. class Java-Bean: True Specify that Slider. Field. Panel should be treated as a Java. Bean Fig. 6. 42 Manifest file for the Slider. Field. Panel Java. Bean. Line 3 2002 Prentice Hall. All rights reserved.
6. 6 Bound Properties (cont. ) Fig. 6. 43 Change properties current. Value and maximum. Value. 2002 Prentice Hall. All rights reserved.
6. 6 Bound Properties (cont. ) Fig. 6. 44 Select property. Change event. 2002 Prentice Hall. All rights reserved.
6. 6 Bound Properties (cont. ) Fig. 6. 45 Select animation. Delay property of Logo. Animator 2. 2002 Prentice Hall. All rights reserved.
6. 6 Bound Properties (cont. ) Fig. 6. 46 Select current. Value Bound Property. 2002 Prentice Hall. All rights reserved.
6. 6 Bound Properties (cont. ) Fig. 6. 47 JFrame with Logo. Animator 2 and Slider. Field. Panel. 2002 Prentice Hall. All rights reserved.
6. 7 Indexed Properties and Custom Events • Indexed property – Similar to standard property – Array of primitives of objects public void set. Property. Name( Data. Type[] data ) public void set. Property. Name( int index, Data. Type data ) public Data. Type[] get. Property. Name() public Data. Type get. Property. Name( int index ) 2002 Prentice Hall. All rights reserved.
6. 7 Indexed Properties and Custom Events (cont. ) • Custom event – Provides functionality not provided by standard Java events – Extends class java. util. Event. Object – Listener interface extends java. util. Event. Listener 2002 Prentice Hall. All rights reserved.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 // Fig. 6. 48 Color. Event. java // Color. Event is an Event. Object subclass that indicates a // change in color. package com. deitel. advjhtp 1. beans; Outline // Java core packages import java. util. *; import java. awt. Color; public class Color. Event extends Event. Object { private Color color; // constructor sets color property public Color. Event( Object source, Color color ) { super( source ); set. Color( color ); } // set method for color property public void set. Color( Color new. Color ) { color = new. Color; } // get method for color property public Color get. Color() { return color; } } Represents the value of Color. Event’s color property Fig. 6. 48 Color. Event custom-event class indicating a color change. Line 12 Lines 22 -31 Builder tool will expose color as a property // end class Color. Event 2002 Prentice Hall. All rights reserved.
1 2 3 4 5 6 7 8 9 10 11 12 13 // Fig. 6. 49 Color. Listener. java // Color listener is the interface for custom event Color. Event. package com. deitel. advjhtp 1. beans; Outline // Java core packages import java. util. *; public interface Color. Listener extends Event. Listener { // send color. Changed Color. Event to listener public void color. Changed( Color. Event color. Event ); } // end interface Color. Listener Custom listener interface that calls registered listeners’ color. Changed method with a Color. Event describing the change Fig. 6. 48 Color. Listener interface for receiving color. Changed notifications. Lines 8 -11 2002 Prentice Hall. All rights reserved.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 // Fig. 6. 50 Color. Slider. Panel. java // Color. Slider. Panel contains 3 Slider. Field. Panels connected to // indexed property red. Green. Blue that adjusts the red, green // and blue colors of an object. package com. deitel. advjhtp 1. beans; // Java core packages import java. io. *; import java. awt. event. *; import java. beans. *; import java. util. *; // Java extension packages import javax. swing. *; import javax. swing. event. *; public class Color. Slider. Panel extends JPanel implements Serializable { Outline Color. Slider. Panel is a Java. Bean that issues color. Changed Color. Events when sliders change color value Fig. 6. 50 Definition of class Color. Slider. Panel (part 1). Line 18 private JLabel red. Label, green. Label, blue. Label; private Slider. Field. Panel red. Slider , green. Slider, blue. Slider; private JPanel label. Panel, slider. Panel; Lines 24 -34 private int[] red. Green. Blue; public int RED_INDEX = 0; public int GREEN_INDEX = 1; public int BLUE_INDEX = 2; Initialize the indexed private Set listeners = new Hash. Set(); property red. Green. Blue // constructor for Color. Slider. Panel public Color. Slider. Panel() { // initialize red. Green. Blue property red. Green. Blue = new int[] { 0, 0, 0 }; 2002 Prentice Hall. All rights reserved.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 // initialize gui components for red slider red. Label = new JLabel( "Red: " ); red. Slider = new Slider. Field. Panel(); red. Slider. set. Minimum. Value( 0 ); red. Slider. set. Maximum. Value( 255 ); // initialize gui components for green slider green. Label = new JLabel( "Green: " ); green. Slider = new Slider. Field. Panel(); green. Slider. set. Minimum. Value( 0 ); green. Slider. set. Maximum. Value( 255 ); // initialize gui components for blue slider blue. Label = new JLabel( "Blue: " ); blue. Slider = new Slider. Field. Panel(); blue. Slider. set. Minimum. Value( 0 ); blue. Slider. set. Maximum. Value( 255 ); // set layout and add components set. Layout( new Border. Layout() ); label. Panel = new JPanel( new Grid. Layout( 3, 1 ) ); label. Panel. add( red. Label ); label. Panel. add( green. Label ); label. Panel. add( blue. Label ); Outline Initialize the red, green and blue Slider. Field. Panels Fig. 6. 50 Definition of class Color. Slider. Panel (part 2). Lines 37 -52 slider. Panel = new JPanel( new Grid. Layout( 3, 1 ) ); slider. Panel. add( red. Slider ); slider. Panel. add( green. Slider ); slider. Panel. add( blue. Slider ); add( label. Panel, Border. Layout. WEST ); add( slider. Panel, Border. Layout. CENTER ); 2002 Prentice Hall. All rights reserved.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 // add Property. Change. Listener for red. Slider. add. Property. Change. Listener ( new Property. Change. Listener() { // handle property. Change for red. Slider public void property. Change( Property. Change. Event property. Change. Event ) { set. Red. Green. Blue ( RED_INDEX, red. Slider. get. Current. Value() ); } } // end anonymous inner class ); // end call to add. Property. Change. Listener // add Property. Change. Listener for green. Slider. add. Property. Change. Listener ( new Property. Change. Listener() { // handle property. Change for green. Slider public void property. Change( Property. Change. Event property. Change. Event ) { set. Red. Green. Blue ( GREEN_INDEX, green. Slider. get. Current. Value() ); } Outline When user changes red. Slider value, red. Slider sets indexed property red. Green. Blue Fig. 6. 50 Definition of class Color. Slider. Panel (part 3). Lines 71 -85 When user changes green. Slider value, Lines 88 -102 green. Slider sets indexed property red. Green. Blue } // end anonymous inner class ); // end call to add. Property. Change. Listener 2002 Prentice Hall. All rights reserved.
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 // add Property. Change. Listener for blue. Slider. add. Property. Change. Listener ( new Property. Change. Listener() { // handle property. Change for blue. Slider public void property. Change( Property. Change. Event property. Change. Event ) { set. Red. Green. Blue ( BLUE_INDEX, blue. Slider. get. Current. Value() ); } Outline When user changes blue. Slider value, blue. Slider sets indexed property red. Green. Blue } // end anonymous inner class ); // end call to add. Property. Change. Listener } // end Color. Slider. Panel constructor // add Color. Listener public void add. Color. Listener( Color. Listener color. Listener ) { // listeners must be accessed atomically synchronized ( listeners ) { listeners. add( color. Listener ); } } Fig. 6. 50 Definition of class Color. Slider. Panel (part 4). Lines 105 -121 2002 Prentice Hall. All rights reserved.
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 // remove Color. Listener public void remove. Color. Listener( Color. Listener color. Listener ) { // listeners must be accessed by one thread only synchronized ( listeners ) { listeners. remove( color. Listener ); } } // fire Color. Event public void fire. Color. Changed() { Iterator iterator; // listeners must be accessed atomically synchronized ( listeners ) { iterator = new Hash. Set( listeners ). iterator(); } Outline Invoked when user changes red. Green. Blue property Fig. 6. 50 Definition of class Color. Slider. Panel (part 5). // create new Color with values of red. Green. Blue // create new Color. Event with color variable Color color = new Color( red. Green. Blue[ RED_INDEX ], red. Green. Blue[ GREEN_INDEX ], red. Green. Blue [ BLUE_INDEX ] ); Color. Event color. Event = new Color. Event( this, color ); // notify all registered Color. Listeners of Color. Change while ( iterator. has. Next() ) { Color. Listener color. Listener = ( Color. Listener ) iterator. next(); color. Listener. color. Changed( color. Event ); } } Line 144 to send Create Color. Event to all Color. Listeners Lines 155 -158 Lines 161 -165 Notify all Color. Listeners of color change 2002 Prentice Hall. All rights reserved.
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 // get red. Green. Blue property public int[] get. Red. Green. Blue() { return red. Green. Blue; } // get red. Green. Blue indexed property public int get. Red. Green. Blue( int index ) { return red. Green. Blue[ index ]; } // set red. Green. Blue property public void set. Red. Green. Blue( int[] array ) { red. Green. Blue = array; } // set red. Green. Blue indexed property public void set. Red. Green. Blue( int index, int value ) { red. Green. Blue[ index ] = value; fire. Color. Changed(); } } Outline Builder tool will expose red. Green. Blue as a indexed property Fig. 6. 50 Definition of class Color. Slider. Panel (part 6). Lines 169 -191 // end class Color. Slider. Panel 2002 Prentice Hall. All rights reserved.
1 2 3 Outline Name: com/deitel/advjhtp 1/beans/Color. Slider. Panel. class Java-Bean: True Specify that Color. Slider. Panel should be treated as a Java. Bean Fig. 6. 51 Manifest file for the Color. Slider. Panel Java. Bean. Line 3 2002 Prentice Hall. All rights reserved.
6. 7 Indexed Properties and Custom Events (cont. ) Fig. 6. 52 Selecting color. Changed method in Connection Wizard 2002 Prentice Hall. All rights reserved.
6. 7 Indexed Properties and Custom Events (cont. ) Fig. 6. 53 Selecting set. Background method for target Logo. Animator 2. 2002 Prentice Hall. All rights reserved.
6. 7 Indexed Properties and Custom Events (cont. ) Fig. 6. 54 Entering user code in Connection Wizard. 2002 Prentice Hall. All rights reserved.
6. 7 Indexed Properties and Custom Events (cont. ) Fig. 6. 55 Using the Color. Slider. Panel to change the background color of Logo. Animator 2. 2002 Prentice Hall. All rights reserved.
6. 8 Customizing Java. Beans for Builder Tools • Customizing exposed sets of properties – Supply class that implements interface Bean. Info • Package java. beans provides class Simple. Bean. Info • Describes to builder tool how to present customized features 2002 Prentice Hall. All rights reserved.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 // Fig. 6. 56 Slider. Field. Panel. Bean. Info. java // Slider. Field. Panel. Bean. Info is the Bean. Info class for // Slider. Field. Panel package com. deitel. advjhtp 1. beans; // Java core packages import java. beans. *; import java. awt. Image; // Java extension packages import javax. swing. *; public class Slider. Field. Panel. Bean. Info extends public static final Class bean. Class = Slider. Field. Panel. class; Slider. Field. Panel. Bean. Info extends Simple. Bean. Info, which implements interface Bean. Info Fig. 6. 56 Slider. Field. Panel Simple. Bean. Info { Bean. Info exposes properties and events Override method get. Bean. Descriptor for Slider. Fieldto return Java. Bean’s Panel name and of description class (part 1). // return general description of bean public Bean. Descriptor get. Bean. Descriptor () { Bean. Descriptor descriptor = new Bean. Descriptor( bean. Class, Slider. Field. Panel. Customizer. class ); descriptor. set. Display. Name( "Slider Field" ); descriptor. set. Short. Description( "A slider bar to change a numerical property. " ); return descriptor; Outline Line 13 Line 19 Line 31 } // return bean icon public Image get. Icon( int icon. Kind ) { Image image = null; Override method get. Icon to display the appropriate image 2002 Prentice Hall. All rights reserved.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 switch( icon. Kind ) { Outline case ICON_COLOR_16 x 16: image = load. Image( "icon 1. gif" ); break; case ICON_COLOR_32 x 32: image = load. Image( "icon 2. gif" ); break; case ICON_MONO_16 x 16: image = load. Image( "icon 3. gif" ); break; case ICON_MONO_32 x 32: image = load. Image( "icon 4. gif" ); break; default: break; } return image; } Fig. 6. 56 Slider. Field. Panel Bean. Info exposes properties and events for Slider. Field. Panel of class (part 2). Line 62 // return array of Method. Descriptors for public get methods // of class Slider. Field. Panel public Method. Descriptor[] get. Method. Descriptors() Each Method. Descriptor { represents a specific method // create array of Method. Descriptors try { exposed to the builder tool Method. Descriptor get. Minimum. Value = new Method. Descriptor ( bean. Class. get. Method( "get. Minimum. Value", null ) ); 2002 Prentice Hall. All rights reserved.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 Method. Descriptor get. Maximum. Value = new Method. Descriptor ( bean. Class. get. Method( "get. Maximum. Value", null ) ); Method. Descriptor get. Current. Value = new Method. Descriptor ( bean. Class. get. Method( "get. Current. Value", null ) ); Outline Describe get methods for properties maximum. Value, minimum. Value, current. Value and field. Width Method. Descriptor get. Field. Width = new Method. Descriptor ( bean. Class. get. Method( "get. Field. Width", null ) ); Method. Descriptor [] descriptors = { get. Minimum. Value, get. Maximum. Value , get. Current. Value, get. Field. Width }; return descriptors; } // print. Stack. Trace if No. Such. Method. Exception thrown catch ( No. Such. Method. Exception method. Exception ) { method. Exception. print. Stack. Trace(); } // print. Stack. Trace if Security. Exception thrown catch ( Security. Exception security. Exception ) { security. Exception. print. Stack. Trace(); } Fig. 6. 56 Slider. Field. Panel Bean. Info exposes properties and events for Slider. Field. Panel of class (part 3). Line 70 -82 return null; } 2002 Prentice Hall. All rights reserved.
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 // return Property. Descriptor array public Property. Descriptor[] get. Property. Descriptors() throws Runtime. Exception { // create array of Property. Descriptors try { // field. Width property Property. Descriptor field. Width = new Property. Descriptor ( "field. Width", bean. Class ); field. Width. set. Short. Description( "Width of the text field. " ); // current. Value property Property. Descriptor current. Value = new Property. Descriptor ( "current. Value", bean. Class ); current. Value. set. Short. Description( "Current value of slider. " ); // maximum. Value property Property. Descriptor maximum. Value = new Property. Descriptor ( "maximum. Value", bean. Class ); maximum. Value. set. Property. Editor. Class( Maximum. Value. Editor. class ); maximum. Value. set. Short. Description( "Maximum value of slider. " ); // minimum. Value property Property. Descriptor minimum. Value = new Property. Descriptor ( "minimum. Value", bean. Class ); minimum. Value. set. Short. Description( "Minimum value of slider. " ); minimum. Value. set. Property. Editor. Class( Minimum. Value. Editor. class ); Outline Property. Descriptors represents specific properties exposed to the builder tool Fig. 6. 56 Slider. Field. Panel Properties maximum. Bean. Info exposes Value, minimum. Value, properties andand events current. Value for Slider. Fieldfield. Width will be Panel of class exposed to the builder tool (part 4). Line 101 Lines 108 -133 2002 Prentice Hall. All rights reserved.
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 // ensure Property. Change. Event occurs for this property current. Value. set. Bound( true ); Property. Descriptor descriptors[] = { field. Width, current. Value , maximum. Value, minimum. Value }; Outline Specify that current. Value is a bound property return descriptors; } // throw Runtime. Exception if Introspection. Exception // thrown catch ( Introspection. Exception exception ) { throw new Runtime. Exception( exception. get. Message() ); } } // get current. Value property index public int get. Default. Property. Index () { return 1; } Fig. 6. 56 Slider. Field. Panel Bean. Info exposes properties and events Indicate thatfor the. Slider. Fieldproperty at position 1 in Property. Panel of class Descriptor (partarray 5). is the default property Line 136 // return Event. Set. Descriptors array Return public Event. Set. Descriptor[] get. Event. Set. Descriptors() Line array 152 of throws Runtime. Exception Event. Set. Descriptors that { describe to a builder Line 158 tool the // create array of Event. Set. Descriptors events supports by this bean try { Event. Set. Descriptor changed = new Event. Set. Descriptor ( bean. Class, "property. Change", java. beans. Property. Change. Listener. class, "property. Change"); 2002 Prentice Hall. All rights reserved.
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 Outline // set event description and name changed. set. Short. Description( "Property change event for current. Value. " ); changed. set. Display. Name( "Slider. Field. Panel value changed" ); Event. Set. Descriptor [] descriptors = { changed }; return descriptors; } // throw Runtime. Exception if Introspection. Exception // thrown catch ( Introspection. Exception exception ) { throw new Runtime. Exception( exception. get. Message() ); } } // get Property. Change event index public int get. Default. Event. Index() { return 0; } } // end class Slider. Field. Panel. Bean. Info Fig. 6. 56 Slider. Field. Panel Bean. Info exposes properties and events Indicate that the event at for Slider. Fieldposition 0 in Event. Set. Panel of class Descriptor array is the (part 6). default event Line 187 2002 Prentice Hall. All rights reserved.
6. 8 Customizing Java. Beans for Builder Tools (cont. ) Fig. 6. 57 Properties and events exposed by Slider. Field. Panel. Bean. Info. 2002 Prentice Hall. All rights reserved.
6. 8. 1 Property. Editors • Property. Editor – Determines how a property is edited inside the editor tool – Allows for further customization 2002 Prentice Hall. All rights reserved.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 // Fig. 6. 58 Maximum. Value. Editor. java // Maximum. Value. Editor is the Property. Editor for the // maximum. Value property of the Slider. Field. Panel bean. package com. deitel. advjhtp 1. beans; // Java core packages import java. beans. *; Outline Edits the maximum. Value property of class Slider. Field. Panel public class Maximum. Value. Editor extends Property. Editor. Support { private Integer maximum. Value; // set maximum. Value property public void set. Value( Object value ) { maximum. Value = ( Integer ) value; fire. Property. Change (); } // get maximum. Value property public Object get. Value() { return maximum. Value; } // set maximum. Value property from text string public void set. As. Text( String string ) { // decode may throw Number. Format. Exception try { maximum. Value = Integer. decode( string ); fire. Property. Change (); } maximum. Value stores. Maximumthe Fig. 6. 58 value selected. Value. Editor in the combo boxis a Property. Editor for Slider. Field. Panel’s maximum. Set maximum. Value (part 1). and notify listeners Line 9 Line 11 Lines 14 -18 2002 Prentice Hall. All rights reserved.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 // throw Illegal. Argument. Exception if decode throws // Number. Format. Exception catch ( Number. Format. Exception number. Format. Exception ) { throw new Illegal. Argument. Exception (); } } // end method set. As. Text // get String array for pull-down menu public String[] get. Tags() { return new String[] { "50", "100", "150", "200", "250", "300", "350", "400", "450", "500" }; } // get maximum. Value property as string public String get. As. Text() { return get. Value(). to. String(); } // get initialization string for Java code public String get. Java. Initialization. String () { return get. Value(). to. String(); } } Outline Return array of all tags that appear in combo box Fig. 6. 58 Maximum. Value. Editor is a Property. Editor for Slider. Field. Panel’s maximum. Value (part 2). Lines 44 -48 // end class Maximum. Value. Editor 2002 Prentice Hall. All rights reserved.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 // Fig. 6. 59 Minimum. Value. Editor. java // Minimum. Value. Editor is the Property. Editor for the // minimum. Value property of the Slider. Field. Panel bean. package com. deitel. advjhtp 1. beans; // Java core packages import java. beans. *; Outline Edits the minimum. Value property of class Slider. Field. Panel public class Minimum. Value. Editor extends Property. Editor. Support { protected Integer minimum. Value; // set minimum. Value property public void set. Value( Object value ) { minimum. Value = ( Integer ) value; fire. Property. Change (); } // get value of property minimum public Object get. Value() { return minimum. Value; } // set maximum. Value property from text string public void set. As. Text( String string ) { // decode may throw Number. Format. Exception try { minimum. Value = Integer. decode( string ); fire. Property. Change (); } minimum. Value the Fig. 6. 59 stores Minimum. Value. Editor is a value selected in the combo box Property. Editor for Slider. Field. Panel’s minimum. Set minimum. Value (part 1). and notify listeners Line 9 Line 11 Lines 14 -18 2002 Prentice Hall. All rights reserved.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 // throw Illegal. Argument. Exception if decode throws // Number. Format. Exception catch ( Number. Format. Exception number. Format. Exception ) { throw new Illegal. Argument. Exception (); } } // string array for pull-down menu public String[] get. Tags() { return new String[] { "50", "100", "150", "200", "250", "300", "350", "400", "450", "500" }; } // get minimum. Value property as string public String get. As. Text() { return get. Value(). to. String(); } // get initialization string for Java code public String get. Java. Initialization. String () { return get. Value(). to. String(); } } Outline Return array of all tags that appear in combo box Fig. 6. 59 Minimum. Value. Editor is a Property. Editor for Slider. Field. Panel’s minimum. Value (part 2). Lines 43 -47 // end class Minimum. Value. Editor 2002 Prentice Hall. All rights reserved.
6. 8. 1 Property. Editors (cont. ) Fig. 6. 60 Maximum. Value. Editor and Minimum. Value. Editor pull-down menus in Forte. 2002 Prentice Hall. All rights reserved.
6. 8. 1 Property. Editors (cont. ) Fig. 6. 61 Slider. Field. Panel values constrained by Property. Editors. 2002 Prentice Hall. All rights reserved.
6. 8. 2 Customizers • Customizer – Creates customized interface for setting bean properties – Useful for manipulating beans that cannot be edited in standard property sheets 2002 Prentice Hall. All rights reserved.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 Outline // Fig. 6. 62 Slider. Field. Panel. Customizer. java // Slider. Field. Panel. Customizer is the Customizer class for // Slider. Field. Panel. package com. deitel. advjhtp 1. beans; // Java core packages import java. awt. *; import java. awt. event. *; import java. beans. *; import java. util. *; // Java extension packages import javax. swing. *; public class Slider. Field. Panel. Customizer extends JPanel implements Customizer { Classes that implement Customizer must provide a no-argument constructor, Fig. 6. 62 so the builder tool Slider. Fieldcan instantiate it Panel. Customizer custom GUI for modifying Slider. Field. Panel beans (part 1). private JCombo. Box maximum. Combo, minimum. Combo; private JLabel minimum. Label, maximum. Label; protected Slider. Field. Panel slider; private Property. Change. Support change. Support ; private static final String[] VALUES = { "50", "100", "150", "200", "250", "300", "350", "400", "450", "500" }; // initialize GUI components public Slider. Field. Panel. Customizer () { // create Property. Change. Support to handle Property. Change change. Support = new Property. Change. Support( this ); // labels for maximum and minimum properties minimum. Label = new JLabel( "Minimum Slider Value: " ); maximum. Label = new JLabel( "Maximum Slider Value: " ); Line 15 Array of all tags that appear in combo box Lines 22 -23 Line 29 Property. Change. Support provides the listener registration and notification services 2002 Prentice Hall. All rights reserved.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 Outline // combo boxes adjust maximum and minimum properties minimum. Combo = new JCombo. Box( VALUES ); Properties minimum. Value and minimum. Combo. set. Selected. Index( 0 ); maximum. Combo = new JCombo. Box( VALUES ); maximum. Value can be set from 50 maximum. Combo. set. Selected. Index( 9 ); through 500, in increments of 50 // add Action. Listener to minimum. Value combo box minimum. Combo. add. Action. Listener( When user accesses maximum. Value new Action. Listener() { combo box, change maximum. Value Fig. 6. 62 Slider. Field// handle action of minimum combo box public void action. Performed( Action. Event event ) Panel. Customizer { custom GUI for set. Minimum ( minimum. Combo. get. Selected. Index() ); modifying Slider} Field. Panel beans } // end anonymous inner class (part 2). ); // end add. Action. Listener // add Action. Listener to maximum. Value combo box maximum. Combo. add. Action. Listener( new Action. Listener() { Lines 36 -39 When user accesses minimum. Value Line 42 combo box, change minimum. Value // handle action of maximum combo box public void action. Performed( Action. Event event ) { set. Maximum ( maximum. Combo. get. Selected. Index() ); } Line 57 } // end anonymous inner class ); // end add. Action. Listener 2002 Prentice Hall. All rights reserved.
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 add( minimum. Label minimum. Combo maximum. Label maximum. Combo Outline ); ); } // set the customized object public void set. Object( Object bean ) { slider = ( Slider. Field. Panel ) bean; } Method set. Object takes as an argument an instance of the Java. Bean being instantiaed // add Property. Change. Listener with Property. Change. Support public void add. Property. Change. Listener ( Property. Change. Listener listener ) { change. Support. add. Property. Change. Listener ( listener ); } // remove Property. Change. Listener with Property. Change. Support public void remove. Property. Change. Listener ( Property. Change. Listener listener ) { change. Support. remove. Property. Change. Listener ( listener ); } // set public { int Fig. 6. 62 Slider. Field. Panel. Customizer custom GUI for modifying Slider. Field. Panel beans (part 3). Lines 78 -81 minimum. Value property void set. Minimum( int index ) old. Value = slider. get. Minimum. Value(); new. Value = Integer. parse. Int( VALUES[ index ] ); 2002 Prentice Hall. All rights reserved.
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 slider. set. Minimum. Value( new. Value ); change. Support. fire. Property. Change( "minimum. Value", new Integer( old. Value ), new Integer( new. Value ) ); } // set public { int maximum. Value property void set. Maximum( int index ) old. Value = slider. get. Maximum. Value(); new. Value = Integer. parse. Int( VALUES[ index ] ); slider. set. Maximum. Value( new. Value ); change. Support. fire. Property. Change( "maximum. Value", new Integer( old. Value ), new Integer( new. Value ) ); } } Notify all Property. Outline Change. Listeners of change in minimum. Value // end class Slider. Field. Panel. Customizer Notify. Fig. all Property 6. 62 Change. Listeners of Slider. Fieldchange in maximum. Value Panel. Customizer custom GUI for modifying Slider. Field. Panel beans (part 4). Lines 104 -105 Lines 115 -116 2002 Prentice Hall. All rights reserved.
6. 8. 2 Customizers (cont. ) Fig. 6. 63 Select Customize from Component Inspector menu. 2002 Prentice Hall. All rights reserved.
6. 8. 2 Customizers (cont. ) Fig. 6. 64 Slider. Field. Panel’s Customizer Dialog. 2002 Prentice Hall. All rights reserved.
- Slides: 100