Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.gui > #2230 > unrolled thread

hooking up arrays of List

Started by"Roedy Green" <roedy.green@THRWHITE.remove-dii-this>
First post2011-04-27 15:37 +0000
Last post2011-04-27 15:37 +0000
Articles 2 — 2 participants

Back to article view | Back to comp.lang.java.gui


Contents

  hooking up arrays of List "Roedy Green" <roedy.green@THRWHITE.remove-dii-this> - 2011-04-27 15:37 +0000
    Re: hooking up arrays of "Thomas Hawtin" <thomas.hawtin@THRWHITE.remove-dii-this> - 2011-04-27 15:37 +0000

#2230 — hooking up arrays of List

From"Roedy Green" <roedy.green@THRWHITE.remove-dii-this>
Date2011-04-27 15:37 +0000
Subjecthooking up arrays of List
Message-ID<gt14c35gk3c2arnvcmeee5tmic7a8onlti@4ax.com>
  To: comp.lang.java.gui
I have doubly dimensioned arrays of widgets.  I would like to set the
up with ChangeListeners -- each individual e.g.

 rgbSlider[0][0].addChangeListener( new ChangeListener() {
            /**
             * Invoked when the target of the listener has changed its
state.
             *
             * @param e a ChangeEvent object
             */
            public void stateChanged( ChangeEvent e )
                {
                int value = rgbSlider[0][0].getValue();
                rgbDecSpinner[0][0].setValue( value );
                }
        } );

What is the cleanest way to pass the two subscript parameters to the
stateChanged method? or concoct a common listener that handles all 6
widgets?
-- 
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

[toc] | [next] | [standalone]


#2231 — Re: hooking up arrays of

From"Thomas Hawtin" <thomas.hawtin@THRWHITE.remove-dii-this>
Date2011-04-27 15:37 +0000
SubjectRe: hooking up arrays of
Message-ID<46c269f2$0$1603$ed2619ec@ptn-nntp-reader02.plus.net>
In reply to#2230
  To: comp.lang.java.gui
Roedy Green wrote:
> I have doubly dimensioned arrays of widgets.  I would like to set the
> up with ChangeListeners -- each individual e.g.

> What is the cleanest way to pass the two subscript parameters to the
> stateChanged method? or concoct a common listener that handles all 6
> widgets?

I suggest not passing the subscripts at all. Instead pass the objects 
that you are actually using:

         final BoundedRangeModel rgbSlider = rgbSliders[i][j];
         final BoundedRangeModel rgbDecSlider = rgbDecSliders[i][j];

         rgbSlider.addChangeListener(new ChangeListener() {
                 public void stateChanged(ChangeEvent event) {
                     int value = rgbSlider.getValue();
                     rgbDecSpinner.setValue(value);
                 }
         });

IMO, a better way to go about it is not to duplicate state 
unnecessarily. Instead make the rgbDecSliders always read data from 
their associated rgbSlider. rgbDecSliders fire a change event in 
response to rgbSlider doing so (put be careful not to leak).

Tom Hawtin

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.gui


csiph-web