I haven't listened to the podcast yet, so I'm not sure what they were
referring to. I'm just demonstrating the JavaFX Script syntax.
What makes the syntax great (and an improvement over the Swing way) is
a couple of things:
closures, slightly cleaner than inner classes in Java
button.onMousePressed = myFunction
object literal syntax: much cleaner and more compact than anonymous
inner classes, and fits the way most people actually think about guis
(as an in order tree)
the swing way is
button = new JButton();
button.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent e) {
//do stuff
}
});
the javafx way can do more with less code
VBox { content: [
Button { action: action1 }
Button { action: function() {
// do stuff
} }
Button { action: action 3 }
]
}
We considered the += for event handlers but decided against it because
it made the language more confusing, had some weird corner cases, and
for most uses there were simpler ways of doing what you want.
We say JavaFX encourages component driven development because the
language and the apis were designed for it. It encourages composition
over inheritance, and encourages mixes vs deep inheritance
hierarchies. With binding we have properties (we call them attributes)
and the ability to make something private, read only, write only on
init, and fully writeable. This means you can cleanly expose just the
parts of your component you want and restrict access to the rest.
After coding Swing for nearly 12 years it's quite a nice change. A
very clean way to code.
- Josh
On Sep 16, 2009, at 1:06 PM, Reinier Zwitserloot wrote:
>
> If that's all, I'm thoroughly confused.
>
> button.onclick = mymethod
>
> is some sort of revelation compared to:
>
> button.addClickListener(#mymethod);
>
> (yes, closures are nice things, and if that's what this is all about,
> that's fine, but the word wasn't mentioned once in the entire podcast,
> hence my confusion).
>
> Using += as a list append operator is not universally considered a
> good idea, and for good reason. Operators are great when the operation
> is usually done as part of a massive chain - 5 + 2 * 10 is much more
> readable than 5.add(2.multiply(10)). add doesn't qualify.
>
>
> So, 'components' just means: "Closures + modules"? In that case, I'm
> all for it.
>
> On Sep 16, 5:48 pm, phil swenson <[email protected]> wrote:
>> Haven't done delphi in 10 years, but it was something like this
>> (delphi people, i know this isn't correct, but it conveys the
>> concept):
>>
>> button.onclick = mymethod
>>
>> I believe that in later versions they did something like:
>>
>> button.onclick += mymethod
>>
>> that way you could have multiple listeners.
>>
>> I remember when I switched from delphi to java I was surprised at how
>> many features Delphi had that Java didn't. 10 years later and that
>> is
>> still the case (properties and events for example).
>>
>> On Sep 16, 5:37 am, Reinier Zwitserloot <[email protected]> wrote:
>>
>>
>>
>>> So, after listening to #278 (What do you want from JavaFX?), I'm
>>> curious: How exactly do you 'just register' a listener and forget
>>> about it? In what way is this different from the java experience. If
>>> anyone could put some examples of either C# or delphi source here,
>>> that'd be great.
> >
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "The
Java Posse" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/javaposse?hl=en
-~----------~----~----~----~------~----~------~--~---