Home  >  

Hello, Flex, Silverlight and JavaFX

Author photo
| | Comments (7)
AddThis Social Bookmark Button
fjs.png
The RIA world has been seeing intensified competition since last year's releases of Microsoft Silverlight and Sun JavaFX, which joined the Adobe Flex/AIR to become the major RIA development platforms. Even though all three of them intent to reach the the same goal, richer user experience and more creative media delivering, the technologies behind them are vast different. But how different from a RIA developer's perspective? Let's do a quick comparison by writing a small program on these three platforms.


The program does a very simple thing. You click the button, Say Hello, then in a text field, the program responses by saying "Hey". The following are the screen shots of the Flex, Silverlight and JavaFX version of the running programs.

flex.png
Flex

silverlight.png
SilverLight

javafx.png
JavaFX

Now, let's take look at the code behind them.


1. "Hello, Flex!"


<?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
backgroundColor="#FFFFFF">

<mx:TextArea x="114" y="11" height="169" id="txtResponse"/>
<mx:Button x="28" y="10" label="Say Hello" click="sayIt()"/>

<mx:Script>
<![CDATA[
public function sayIt():void{
txtResponse.htmlText =
txtResponse.htmlText +
"<b>You:</b> Hello, Flex!<br/>";

txtResponse.htmlText =
txtResponse.htmlText +
"<b>Flex:</b> Hey you, welcome to Flex world!<br/>";
}
]]>
</mx:Script>
</mx:Application>

In Flex, the UI components are defined and laid out using MXML, a XML based markup language introduced with Flex. MXML includes a set of tags for UI components or controls. For example, Button, TextArea, DataGrid, Tree, TabNavigator, Accordion, and Menu are all part of the standard set of tags. You can also extend the MXML tags and create your own components. In the program above, there are only two components, a TextArea for displaying "hello" messages and a Button to say "hello".

As you can see, Flex event handling is straight forward. Within the Buttion tag, "click="sayIt()" Specifies when the mouse is clicked the button, the even handler function sayIt()will run. Also noticed is that you can embed ActionScript code inside the MXML program. Just be aware though, something you can do might not something you want to do in a real world Flex project. By the way, ActionScript is a scripting language based on ECMAScript (JavaScript), used primarily for the development of websites and software using the Adobe Flash Player based platform.

This small program was written using Flex Builder 2.0. In this post I won't go through details on how to use Flex Builder, Silverlgiht and JavaFX development environments.

Next, we'll see how exactly the same function is written in Silverlight.

2. "Hello, Silverlight!"


<Canvas x:Name="parentCanvas"
xmlns="http://schemas.microsoft.com/client/2007"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Loaded="Page_Loaded"
x:Class="HelloSilverlight.Page;assembly=ClientBin/HelloSilverlight.dll" xmlns:UIControls="clr-namespace:Silverlight.Samples.Controls;assembly=ClientBin/Silverlight.Samples.Controls.dll"
Width="640"
Height="480"
Background="White"
>
<TextBlock Canvas.Left="130" Canvas.Top="11" Height="169"
x:Name="txtResponse"/>
<UIControls:Button Canvas.Left="10" Canvas.Top="10" Text="Say Hello"
Click="SayIt"/>
</Canvas>

You can see the above Silverlight code closely resembles what we've seen in Flex code. Indeed, Silverlight employs the same approach as Flex does for UI definition and layout. With Silverlight, the XML based markup language is called XAML, which is used in the .NET Framework technologies, particularly in Windows Presentation Foundation (WPF). The above code was written in Silverlight 1.1 Alpha, where there are very limited amount UI controls can be used to write a interactive application. The Button control is provided from Silverlight SDK as an example.

The mouse event handling is similar to Flex's too. The actual code that implements the SayIt() handler is in a JavaScript file that represents the the program source code of the XAML page. The code snipe is shown as following.

private void SayIt(object sender, EventArgs args)
       {
         txtResponse.Text = txtResponse.Text +
                          "You: Hello, Silverlight!\n";
         txtResponse.Text = txtResponse.Text +
                 "Silverlight: Hey You, Welcome to the Silverlight world!\n";
        }

Even though all C#, VB.Net and ASP.net can be used to develop Silverlight application, in this case the code behind is JavaScript.

The current Silverlight 1.1 Alpha focuses on features that deal with bits and bytes on screen, the creative media rendering aspect of RIA. Writing sophisticate interactive Silverlight application has to wait the soon releasing Silverlight 2.0, which will include a rich set of UI controls for RIA application development.

Let's find out how JavaFX does it.

3. "Hello, JavaFX!"


package hellojavafx;
import javafx.ui.*;

class HelloModel {
attribute saying: String;
}

var model = HelloModel {
saying: ""
};

Frame {
title: "Hello, JavaFX"
width: 500
height: 300
content: Panel {
content:
[Button {
x: 10 y: 10 text: "Say Hello"
action: operation() {
model.saying = model.saying.concat("You: Hello, JavaFX!\n");
model.saying = model.saying.concat("JavaFX: Hey you, Welcome to JavaFX World!\n");
}
},
TextArea {
x: 110 y: 11 height: 169 width: 350
text: bind model.saying
}
]
}
visible: true
}

The JavaFx script code looks quite different from both Flex and Silverlight codes. JavaFX Script is a new script language introduced as part of the JavaFX technology and tool set. JavaFX Script uses a declarative syntax for specifying GUI components. It intents to make the UI code closely matches the actual layout of the GUI. Another observation is that the JavaFX script code looks similar to the legacy Flash declarative coding. That fuels the speculation that Sun is targeting the Flash designers for the adaption of JavaFX technologies.

Since JavaFX is built on top of the Java technology stack, all the Swing components are exposed to JavaFX as well. Even though JavaFX is initially marketed as Flash alike creative media delivering platform, the rich UI components allow develop complex RIA applications.

In next few weeks we will see the new releases of Flex 3.0 and Silverlight 2.0. There will be JavaFX design tool in the pipe line for this year as well. The RIA technologies in general is getting even more mature in 2008.

In conclusion, let me organize some information in the following table.

FlexSilverlightJavaFX
Version3.01.1 Alpha1.0
Built-in UI ControlsYesVery limited to noneVia Swing
IDEFlex Builder 3.0 (Eclipse platform)Visual Studio 2008
.NET Platform 3.5
Silverlight 1.1 Alpha Visual
Studio 2008 Template
NetBean 6.01
JavaFX plugin
IDE Visual DesignYesNoNo
IDE Toolbar for ControlsYesNoNo
Browser ClientAdobe Flash Player 9Silverlight 1.1 AlphaJava Plugin with JavaFX extension
LanguagesMXML
ActionScript
XAML
JavaScript
(C#, VB.Net, ASP.Net)
JavaFX Script
Java


Read more from Moxie Zhang. Moxie Zhang's Atom feed flexria on Twitter

Comments

7 Comments

John Dowdell said:

True... but has JavaFX shipped? Can you use it?

Same with Silverlight... there will soon be the first beta of the functionality Bill Gates described in Nov 05, and Microsoft announced in March 06... an actual release version may arrive by the end of 2008.

Flex 3 and AIR 1 are finalized and usable today, for realworld projects. It's good to examine syntactic and functional differences (thanks for the "Hello World" survey!), but today it's still hard to compare actual deployable capabilities and promises of future capabilities.

Agree, disagree, modify...?

tx, jd/adobe

Joe said:

You could simplify the Silverlight code by using an even trigger.
Interesting to see JavaFX's approach. Wonder how easy that's going to work with tool support (IDE designers etc).

Rich Tretola said:

Joe, can you show a sample of what you are suggesting? You will need to escape the brackets within comments.

Moxie said:

you can do something like this:
<Button.Triggers>
<EventTrigger RoutedEvent="Button.Click">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
.....

It's very wordy. Developers could feel it's just too tedious for a simple thing.

Mike K said:

The thing that bugs me the most is that Silverlight came later, and you should say stole the syntax to do a me too technology. But that is the story of Microsoft's history. Wait until the market gets big enough, steal ideas, recruiit employees for those companies doing innovative work, take from our cash cow of OS monopoly for legal costs, then claim the market share, and protect their MSDN Matrix headplug developers. Frankly, it pisses me off that is so blatent. They need to hire Roger Clemens for their spokesmodel for Silverlight. (Flame away or check your facts)

Julien Royer said:
in this case the code behind is JavaScript
Nice JavaScript code. ;-)
Jamie said:

Mike K - Silverlight has been in the pipeline for a very long time, so while concepts may have been adopted, the Silverlight platform has been built for developers who are sick of the separation between code and ui. Silverlight is an amazing tool, as is Flex, but if you're a C# developer, the choice is obvious

Leave a comment


Type the characters you see in the picture above.

Tag Cloud

Poll: Sci-Fi Movies

What's Your Favorite Sci-Fi Movie of All Time?

Vote | View Poll Results | Read Related Blog Entry

Latest Features

  •     Welcome back to the series. This time we are goings to build a really exciting component that will be used to simply display information about the user. Well, you might say why to we need such a component, is there... Continue Reading
  •    Welcome back to our exciting Facebook ActionScript series. In this article we will discuss one of most important (and most exciting) features of the FB platform, it's the publishing of news. We all know when we log in to facebook,... Continue Reading
  • This article provides 10 tips and best practices (in no particular order) for maximizing the benefits that Dojo can bring to your next project. For a more thorough introduction to Dojo, see the article Dojo: The JavaScript Toolkit with... Continue Reading
  •     The notifications are one of the most interesting (and important) parts of the facebook area. In order to completely understand the Flash side of it, we need to understand the basics of the facebook notification, what it is and how... Continue Reading

Development Series

Get an overview of the tools and technologies that work together to allow developers to build Rich Internet Applications (RIAs) quickly and easily.

facebook icon Facebook Application Development

Anatomy of an Enterprise Flex RIA

Recommended for You

@InsideRIA on Twitter

Archives

  • Or, visit our complete archive.  

About This Site

Welcome to the premiere community site for all things RIA sponsored by O'Reilly Media and Adobe Systems Incorporated.