/ Forside / Teknologi / Udvikling / Java / Nyhedsindlæg
Login
Glemt dit kodeord?
Brugernavn

Kodeord


Reklame
Top 10 brugere
Java
#NavnPoint
molokyle 3688
Klaudi 855
strarup 740
Forvirret 660
gøgeungen 500
Teil 373
Stouenberg 360
vnc 360
pmbruun 341
10  mccracken 320
Instantiat Interface ??
Fra : Mike T. Altun


Dato : 29-01-01 13:23

I have a question to Java. I hope you can answer me.

How can it be possible to instantiate an interface like this code below :

ActionListener al = new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
if (ae.getSource() == button1)
{

System.out.println("Button selected!");

}
else
if (ae.getSource() == text1)
{
String text2 = ((JTextField)ae.getSource()).getText();

String text3 = ae.getActionCommand();

System.out.println("Text from ActionEvent : " + text2);
System.out.println("Text from TextField : " + text3);

}
}
};

button1.addActionListener(al);

Thank You !





 
 
Lars Dam (29-01-2001)
Kommentar
Fra : Lars Dam


Dato : 29-01-01 13:45

On Mon, 29 Jan 2001 13:22:31 +0100, "Mike T. Altun"
<Tuncay.love@worldonline.dk> wrote:

>I have a question to Java. I hope you can answer me.
>
>How can it be possible to instantiate an interface like this code below :

Part of the java specification. Read the docs 'Anonymous classes'.

>
>Thank You !
>

kr. ld

--
"Time is the fire in which we burn"

Ulrik Magnusson (29-01-2001)
Kommentar
Fra : Ulrik Magnusson


Dato : 29-01-01 15:33

"Mike T. Altun" wrote:

> How can it be possible to instantiate an interface like this code below :

Because you are defining the (anonymous) class that implements the interface
in the very same statement.

Anonymous inner classes:
http://www.boisejug.org/tij2/Chapter08.html#Heading263

Ulrik Magnusson

--
"Look! Ducks in the lake"
'Agent Cooper' in Twin Peaks - Lynch, 1990
Visit my home page: http://www.geocities.com/ulrikm



Søg
Reklame
Statistik
Spørgsmål : 177558
Tips : 31968
Nyheder : 719565
Indlæg : 6408929
Brugere : 218888

Månedens bedste
Årets bedste
Sidste års bedste