Article View: borland.public.jbuilder.java.language
Article #15170Re: internal classes and methods
From: Steve Horsley
Date: Fri, 02 Jul 1999 00:00
Date: Fri, 02 Jul 1999 00:00
37 lines
1750 bytes
1750 bytes
It is right that you should do this. An inner class (named or
anonymous) has access to the class methods and variables of
its enclosing class.
This allows you to make e.g. action listener inner classes that
access the outer class variables or call functions. I believe that
this capability was seen as essential for the java 1.1 event model.
Here's an example...
public void init() {
// work, work...
buttonGo = new JButton("Go");
// define anonymous inner class actionlistener for button
buttonGo.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
buttonGo.setEnabled(false); // accesses outer class
variable
go(); // accesses outer-class method
}});
// work, work...
}
void go() {
// work, work...
}
Marcel van den Dungen wrote:
<snip>
>
> I thought it would be impossible to call the doThis()-method in
> the internal class (MyInternalClass), but it seems to be no problem.
> Why is it possible to do such a call? And is this a proper solution?
>
> thanks in advance,
>
> vincent nuijten
Technical Details
Message-ID:
<377C78F9.5B8FDD6B@cwcom.co.uk>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<7lfv3u$qn13@forums.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,d0974d1e5be948a3 X-Google-Attributes: gidf74b3,public From: Steve Horsley <steve.horsley@cwcom.co.uk> Subject: Re: internal classes and methods Date: 1999/07/02 Message-ID: <377C78F9.5B8FDD6B@cwcom.co.uk> X-Deja-AN: 496344669 Content-Transfer-Encoding: 7bit References: <7lfv3u$qn13@forums.borland.com> X-Accept-Language: en Content-Type: text/plain; charset=us-ascii Organization: Cable & Wireless Communications Mime-Version: 1.0 Newsgroups: borland.public.jbuilder.java.language