🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #14420

Re: Question about strange new operator syntax

#14420
From: Twilex
Date: Tue, 07 Sep 1999 00:00
55 lines
2095 bytes
> public class X extends Frame {
>
> // various
>
> public static void main(String[] args) {
>
> // what is this doing? (I mean syntactically)
> WindowListener l = new WindowAdapter() {
>    public void windowClosing(WindowEvent e) {
>        System.exit(0);
>    }
> };
>
> // etc
>
> }
This is called an inner class adapter (or anonymous adapter).
You can actually do it even more compact (as taken from JBuilder2 Helpfiles)

buttonControl1.addFocusListener(new java.awt.event.FocusAdapter() {
  public void focusGained(FocusEvent e) {
    buttonControl_focusGained(e);
  }
 }

 void buttonControl1_focusGained(FocusEvent e) {
  // your code to respond to event goes here
}

> I understand that WindowAdapter is an
> abstract class that implements WindowListener.
>
> It looks as though the block after the new operator
> redefines one of the WindowAdapter methods, as needed by the program.
This
> looks like very strange syntax to me. It should be something like:
>
> class MyWindowAdapter extends WindowAdapter {
>    public void windowClosing(WindowEvent e) {
>           System.exit(0);
>    }
> }
>
> And then:
>
> WindowListener l = new MyWindowAdapter();
>
Yes, you are right, but then you won't have access to all variables (only
public and package level).


--
Regards Twilex
==================
twilex@c2i.net
Technical Details
Message-ID: <SqbB3.2584$6g7.248619@juliett.dax.net>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <7qf634$4a8$1@uk21.supernews.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,eef714514d3081c4
X-Google-Attributes: gidf74b3,public
From: "Twilex" <twilex@c2i.no>
Subject: Re: Question about strange new operator syntax
Date: 1999/09/07
Message-ID: <SqbB3.2584$6g7.248619@juliett.dax.net>
X-Deja-AN: 522166266
References: <7qf634$4a8$1@uk21.supernews.com>
X-Priority: 3
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2014.211
X-Complaints-To: abuse@tele2.no
X-Trace: juliett.dax.net 936723250 193.217.228.3 (Tue, 07 Sep 1999 18:54:10 MET DST)
Organization: Tele2 Norway AS Public Access
X-MSMail-Priority: Normal
NNTP-Posting-Date: Tue, 07 Sep 1999 18:54:10 MET DST
Newsgroups: borland.public.jbuilder.java.language