Declarative programming in Flex
When building applications using Flex (for AIR or Flash Player), you can use declarative programming to specify part of your user interface. The declarative language of Flex is XML-based and called MXML.
Here’s a simple app in Flex/MXML:
<?xml version="1.0" encoding="utf-8"?><mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" title="Hello Rich Internet Application" backgroundColor="#FFFFFF" > <mx:VBox horizontalAlign="center" horizontalCenter="0" verticalCenter="0"> <mx:Button label="Click Me" click="mx.controls.Alert.show( 'ActionScript and Flex are a match made in heaven!', 'Flex Rocks!');"/> <mx:Label fontSize="24" fontWeight="bold" color="#1A49DF" text="Flex Makes RIA Development Easy" /> </mx:VBox> </mx:WindowedApplication>
Here’s the equivalent app in JavaFX:
/* * HelloCompiledJavaFX.fx - A "Hello World" style, but slightly more * sophisticated, compiled JavaFX Script example * * Developed 2008 by James L. Weaver (jim.weaver at lat-inc.com) * to serve as a compiled JavaFX Script example. */package mypackage; import javafx.ui.*;import javafx.ui.canvas.*; Frame { title: "Hello Rich Internet Applications!" width: 550 height: 200 background: Color.WHITE visible: true content: BorderPanel { top: FlowPanel { content: Button { text: "Click Me" action: function():Void { MessageDialog { title: "JavaFX Script Rocks!" // This string has a newline in the source code message: "JavaFX Script is Simple, Elegant, and Leverages the Power of Java" visible: true } } } } center: Canvas { content: Text { font: Font { faceName: "Sans Serif" style: FontStyle.BOLD size: 24 } x: 20 y: 40 stroke: Color.BLUE fill: Color.BLUE content: "JavaFX Script Makes RIA Development Easy" } } }}
(from http://java.sun.com/developer/technicalArticles/scripting/javafx/ria_1/)