Re: Anonymous Inner class Creation
From: Kevin McMurtrie (mcmurtri_at_dslextreme.com)
Date: 03/03/05
- Next message: fxn_at_hashref.com: "How to speed up a simple paintComponent()"
- Previous message: Kevin McMurtrie: "Re: threadaches"
- In reply to: cbongior_at_stny.rr.com: "Anonymous Inner class Creation"
- Next in thread: Chris Uppal: "Re: Anonymous Inner class Creation"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 02 Mar 2005 22:20:15 -0800
In article <1109787295.577274.178570@l41g2000cwc.googlegroups.com>,
cbongior@stny.rr.com wrote:
> I have recently begun to experiment more with Anonymous Inner classes
> (I still consider them a devils deal). However, I did come upon a
> situation where it was nice:
>
> JPanel myPanel = new JPanel() {
> public String toString() { return "Default";}
> };
>
> I used this so I could added panels to my JComboBox and swap them on
> and off of another portion of the display. However, my hopes were
> dashed when I wanted that Anonymous Inner Class to implement and
> interface.
>
> JPanel myPanel = new JPanel() implements QueryFormatter {
> public String toString() { return "Default";}
> public String getFormat() {return "";} // interface method.
> };
>
> I got an unexpected token compile error. So, is it possible to do this
> with anonymous inner classes? I am thinking not, judging by the
> compiler errors and the fact that the lanaguage specification is silent
> on this.
>
> Comments?
>
> Christian
> http://christian.bongiorno.org/resume.PDF
Why implement that interface? You're casting the result to a JPanel.
It is possible to implement interfaces. I do it to avoid having a
public run() method for thread entry.
Runnable r= new Runnable ()
{
public void run () {myProtectedMethod();}
};
new Thread (r).start();
- Next message: fxn_at_hashref.com: "How to speed up a simple paintComponent()"
- Previous message: Kevin McMurtrie: "Re: threadaches"
- In reply to: cbongior_at_stny.rr.com: "Anonymous Inner class Creation"
- Next in thread: Chris Uppal: "Re: Anonymous Inner class Creation"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|