Re: Getting a reference to an object instantiated by doClick()

From: Rhino (rhino1_at_NOSPAM.sympatico.ca)
Date: 02/14/05


Date: Sun, 13 Feb 2005 20:35:20 -0500

Posting my code is something of a problem because of confidentiality
concerns. I could construct an example that illustrates the point without
giving away any secrets but that might take a while to put together. I'd
like to try to clarify my situation verbally first and see if someone can
see the solution.

I agree that my design is not ideal and I'm already thinking of ways to
improve it. However, I still want to pursue this approach just so that I
understand programatic operations, like doClick(), somewhat better, even if
I don't actually implement this approach in the program.

The two doClicks() that I am currently doing are on a JMenu and a JMenuItem
in the JMenuBar of my main GUI. Interrogating those menu items is only going
to give me a reference to the main GUI class, which is a JFrame, not the
Preferences dialog.

I'm really not clear *how* this works but the second doClick() instantiates
my Preferences dialog (actually, JDialog). I'd like to figure out how to get
a reference to that dialog. The API says that doClick() is a method from
AbstractButton and it returns void so I don't see how I can get a reference
to the dialog it launched, as opposed to the JFrame which contained the
control which had the doClick() done. I can SEE the dialog so I know it has
been instantiated but I can't figure out how to get a reference to it.
Surely if an object exists and I created it, there should be a way to get a
reference to it, right?

Rhino

"Alex Molochnikov" <NOBODY@NOSPAM.COM> wrote in message
news:3VSPd.381636$8l.306754@pd7tw1no...
> I am not sure what your problem is, since you obviously create a dialog
and
> therefore must have a reference to it. The doClick() method merely
simulates
> clicking on a button, which in turn generates an action event. The button
> has an action listener attached to it, which is where the dialog could be
> instantiated.
>
> From the sound of it, it looks like your design is seriously flawed. Why
do
> you need to create the dialog twice, instead of reusing the one created
the
> first time?
>
> Perhaps, posting some of your code could help.
>
> Alex Molochnikov
> Gestalt Corporation
>
> "Rhino" <rhino1@NOSPAM.sympatico.ca> wrote in message
> news:nzSPd.46$dZ.34485@news20.bellglobal.com...
> > How do I select a particular tab of a tabbed pane in a dialog that I
> display
> > via doClick()?
> >
> > My main GUI gives my user the option of creating a new Foo, which has a
> > variety of attributes. I need my user to confirm the values of all of
> those
> > attributes so I want to force them to go to a particular tab of my
> > Preferences dialog. Once they are there, they can change any attribute
> > values that they don't like and press 'Save'. Then they return to the
main
> > GUI where they left off and the new Foo is there waiting for them.
> >
> > I can launch the Preferences dialog programatically via doClick() -
> >
> > fileMenu.doClick();
> > changePreferencesItem.doClick();
> >
> > - but I don't see how to select a particular tab of my Preferences
dialog,
> > which is basically a big JTabbedPane. I wanted to do this:
> >
> > setSelectedIndex(7);
> >
> > but I get a compile error because setSelectedIndex refers to my main GUI
> > class, which is *not* a JTabbedPane. In other words, I need a reference
to
> > the Preferences dialog preceding the method, something like this:
> >
> > myPreferencesDialog.setSelectedIndex(7);
> >
> > I'm not sure how to get a reference to the Preferences dialog. I *could*
> > instantiate it but the second doClick() has *already* instantiated it so
> > doing so a second time seems redundant. However, I don't see how to get
a
> > reference to the instance that doClick() created.
> >
> > Can anyone help me out?
> >
> > --
> > Rhino
> > ---
> > rhino1 AT sympatico DOT ca
> > "There are two ways of constructing a software design. One way is to
make
> it
> > so simple that there are obviously no deficiencies. And the other way is
> to
> > make it so complicated that there are no obvious deficiencies." - C.A.R.
> > Hoare
> >
> >
>
>



Relevant Pages

  • Re: Getting a reference to an object instantiated by doClick()
    ... me into my logic for handling a 'Change Preferences' click in the GUI's ... instantiation of my Preferences dialog and a reference to that dialog. ... the doClick() caused me to go to the 'Change Preferences' logic. ... > instantiates it, post this stripped-down code. ...
    (comp.lang.java.gui)
  • Re: Getting a reference to an object instantiated by doClick()
    ... instantiates it, post this stripped-down code. ... the action listener creates the dialog. ... > a reference to that dialog. ... The API says that doClick() is a method from ...
    (comp.lang.java.gui)
  • Re: Getting a reference to an object instantiated by doClick()
    ... The doClick() method merely simulates ... > GUI where they left off and the new Foo is there waiting for them. ... > I can launch the Preferences dialog programatically via doClick- ... > reference to the instance that doClickcreated. ...
    (comp.lang.java.gui)
  • Re: Question for everyone
    ... > I'm looking for a good reference or two that will give me Windows GUI ... Right now the only book I have is Petzold's Programming for ... The O'Reilly Windows Forms in a Nutshell is good as a reference - the first ...
    (microsoft.public.dotnet.languages.vc)
  • MrEd beginner questions
    ... I am a Scheme newbie and I have just started writing an application ... I really like it very much, but I'm having some trouble: ... expression that uses the GUI). ... reference to undefined identifier: new ...
    (comp.lang.scheme)