Re: newbie question about java's syntax
- From: "Bjorn Abelli" <bjorn_abelli@xxxxxxxxxxxxxxxxxxxxx>
- Date: 9 Dec 2005 09:24:06 +0100
"donovan" wrote...
>I have a background in c++ and this syntax looks basically
> just like C++. What throws me off is the first line and
> the last line. I'm thinking it's a statement because it
> has ; at the very end,
It is. If you look more closely, you'll see that it ends the following
statement:
ipField.addFocusListener( ... );
> but it looks like a function definition sqeezed in
> as an argument of a function call.
Not quite, but almost... ;-)
You're instantiating an object, which will be the argument of the function
call:
ipField.addFocusListener(new FocusAdapter() {...} );
> Can someone give me a clue?
As FocusAdapter is an abstract class, you need to implement an own subclass
of it, which in Java can be done "anonymously", i.e. without giving it a new
class name, just as you've done.
new FocusAdapter() {
public void focusLost(FocusEvent e) {
ipField.selectAll();
if (connectionStatus != DISCONNECTED) {
changeStatusNTS(NULL, true);
}
else {
hostIP = ipField.getText();
}
}
}
// Bjorn A
.
- References:
- newbie question about java's syntax
- From: donovan
- newbie question about java's syntax
- Prev by Date: Re: need help on this problem.
- Next by Date: [OT] Re: need help on this problem.
- Previous by thread: Re: newbie question about java's syntax
- Next by thread: Re: newbie question about java's syntax
- Index(es):