🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.swing
Article #9534

Re: Problem adding an ActionListener to a JButton

#9534
From: Paul Furbacher [TeamB]
Date: Thu, 09 Mar 2000 00:00
33 lines
2212 bytes
Jeff Marendo wrote:

> I've got some code where I'm trying to initialize a button's state in a
> class that extends from a JPanel.  I have private ActionListener members for
> this class; and, within a 'setButton' type function, I'm trying to add the
> ActionListener to the button, as well register a keyboard action.
> 
> The problem that I'm having is that the listener doesn't seem to be
> registering (i.e. I can't execute the code in the actionPerformed method).
> I thought that by having private members that this would give me global
> scope in the class that would sidestep the local scope of the function I'm
> using.  

This notion of private vs. global is confusing.  First off, it's not
common for the listening class (your subclass of Frame) to maintain a 
reference to the listener instance that is created by 
"new ActionListener() { ... }".  You simply want to create the 
instance and immediately give it to the "listenable" class, 
which is the button.  The button maintains the reference 
to the listener. 

All your listening class has to do is provide the 
"insertBtn_actionPerformed(...)" class.  The scope of that may 
be private, package, protected, or public.  Typically, it is 
private (or perhaps protected if you anticipate that classes which 
extend this class will somehow want to utilize this same method?!).  
In your code [snipped], you don't show the exixtence of this 
"insertBtn_actionPerformed()" method.  Does it exist in your class 
which contains the "setInsertButton()" code?  If not, that's 
your problem.
 

Paul Furbacher (TeamB)
Technical Details
Message-ID: <38C81C6A.DEA90251@home.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <8a3nmf$54a7@bornews.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,e0b4324bb89268d4
X-Google-Attributes: gid111d45,public
From: "Paul Furbacher [TeamB]" <pnf@home.com>
Subject: Re: Problem adding an ActionListener to a JButton
Date: 2000/03/09
Message-ID: <38C81C6A.DEA90251@home.com>
X-Deja-AN: 595339617
Content-Transfer-Encoding: 7bit
References: <8a3nmf$54a7@bornews.borland.com>
X-Accept-Language: en
Content-Type: text/plain; charset=us-ascii
Organization: Another Netscape Collabra Server User
Mime-Version: 1.0
Reply-To: pnf@home.com
Newsgroups: borland.public.jbuilder.java.swing