martes, 28 de julio de 2009

What is a JavaFX app?



It depends on who you ask. For the programmer is code. For the designer is media (images, video, layout, fonts). For the art director is the way you combine all things. For the user, an app is 'cool' or does not exist.

In any case, a JavaFX app is a combination of multiple ingredients. If one ingredient of the recipe lacks, there is no app.

Tools like the Google CC media search engine are great because represent an easy way to locate media for our apps.

Related resources:


How to embed fonts in JavaFX




Let's supose you want to use a font not present in the system. For example you want to use a 'grunge' font:



The font used here is Viper Vera. It turns out that you can 'embed' the font with your application. How?

At the Java FX forum you can read:

You embed the font along with your application. You load the font by name. Simply place the ttf font file in a package in your application. Then you need to include a fonts.mf file in the META-INF of the jar so that we can discover the embedded fonts at runtime. The fonts.mf file is simply a properties file that lists the name of the font and the location of the font.

fonts.mf:

Arindam\ Neo\ Bold = /com/mycompany/fonts/arind.ttf

for example. Then in code you just load a font by name, using the name that you entered into your fonts.mf:

Font {
name: "Arindam Neo Bold"
size: 27
}





domingo, 26 de julio de 2009

IDEOLOGIA

Imagine an authentication scheme without textual passwords. Welcome to IDEOLOGIA, a system that allows the user to log on different websites with spatial based gestures.
Based on the previous works KAOS and ILLITERATE.

User instructions:
In order to be directed to the NSA website (www.nsa.gov) the user needs to invoke the following sequence of gestures:

1. NORTH
2. NORTH
3. NORTHEAST

After the sequence is "typed" IDEOLOGIA will open a browser with the URL www.nsa.gov. No button or any usual user interface has to be pressed, just drag&drop gestures.

See a demo on youtube:


Illiterate


Imagine a computer environment without buttons o textboxes. Welcome to ILLITERATE.

Based on the previous work Kaos, ILLITERATE is a learning tool for disabled people.
Every word is presented to the user with a twist: a visual representation of the 'kaos level' of the word presented.
While the user advances on the typing work, the initial order is restored.

You can watch a ILLITERATE demo (you tube video) here:



Kaos, the roadmap

My name is Joan and I am a lawyer [*].

mmm.. so, how can a lawyer write JavaFX applications?

Well, thats a wrong question, man. Who invented XML? A lawyer. Who was the best number theorist mathematician? Fermat, a french lawyer. Who.... well, that's enough for today.

Let's talk about Kaos, a Java FX application. Java FX is an interesting beast, a DSL with very interisting skills. One is closures. If you know Smalltalk o Newspeak you know waht I mean.

Kaos is a litte prototype or proof of concept. Also is a engine that will be used in posterior applications: Illiterate andIDEOLOGIA.

Playing Kaos is very easy. Your goal is to restore the initial order. In order to do so, you can drag&drop the scrambled pieces of the initial image.

Playing Kaos you will feel like Sisyphus a greek king punished in Tartarus by being cursed to roll a huge boulder up a hill, only to watch it roll back down, and to repeat this throughout eternity.


You can watch a demo of a KAOS session here:




[*] Well, a studend lawyer is more accurate.

Playing with licenses - Exercises



Now let's present some practical license exercises.

Don't forget to review prior related posts:
Also you can execute the JavaFX app here.

Exercise 1.
Let's supose you have found the following image:


This image has a CC license: BY-SA

Can I use the following derived work in my web blog?


Response: Yes. You are allowed to copy and modify the image. But don't forget to tag the derived image with a BY-SA license.

sábado, 25 de julio de 2009

How to clear the JavaFX caché



Just go to the Control Panel and click on the Java icon:





Then go to the Delete Files... button and voilà, that's all!

lunes, 20 de julio de 2009

JavaFX App Store dictionary



30 % comission. Official stores collect a 30% commision from the sellers on its stores.

Android Market (Google) Available in some countries.

App Store. Note that the term App Store is not entirely correct because some stores sell also content (ringtones, movies, music), games,... Anyway, the term has stuck and is any good as any other.

App World (RIM Blackberry)
Enter BlackBerry App World

Bulk applications. Also Known as the dirty little secret of Apple Store. iTunes has 65.000 apps on sale, but most of they are little variations of the same application written by the same publisher. Template-based apps makes you wonder how real the 65.000 number is.

Ecosystem. Many journalist see App Stores not like an integration of some hardware, developers plus consumers. For them, an App store is just a manifestation of a complete ecosystem and a thriving developer platform.

Ericsson App Store. By August its customers will be able to personalize their phones with a range of downloadable utilities, tools, and games over multiple platforms. Dont expect to find Sony (a partner of Ericcson) here.


iTunes App Store. Dubbed the last greatest capitalism experiment. Has been a terrific success. More than 500m applications, from games to interactive travel guides, have been downloaded in just a year.


Java Store. From Sun-Oracle.




mStore From Movistar. Just one of the worst user interface of the whole cyberspace.




Orange Application Store. It is already available for selected handsets in France, official release will happen before the year is over in France first, followed by the UK.


Ovi Store. From Nokia.

Ovi_lockup


Oracle Store. Custormers can purchase Oracle VM Support, Oracle VM media packs, and Oracle Enterprise Linux support services media packs.



Plaza Retail Store. This is the Qualcom store.





Race to the bottom. Apps in the Stores have to compete with lower prices in order to try to boost their exposure on the rankings. Critics of this system have argued that this encorauges a "$0.99" economy which will prevent companies from investing in higher quality titles.

Rogue App Store. Online App Store not authorized by the official store. The most famous rogue App Store is Cydia Store that sells hundreds of iPhone applications not available at the Apple official store. Cydia was created by Jay Freeman (a.k.a. Saurik), a 27-year-old computer science doctoral student in Santa Barbara, California. Cydia Store users pay through Amazon Payments.


Vodafone App Store. Just announced.

Windows MarketPlace. (Microsoft)

jueves, 16 de julio de 2009

Who killed Swing?


Figure 1. Marcus Aurelius emperor

Good question. Who killed Swing? It seems no one knows the answer. In theory Swing was not a bad boy, and it does not deserve this slow passing away. So, what happened?

Marcus Aurelius was a Roman emperor, he ruled the western world from 161 to his death in 180 A.D. People describe him as a 'perfect emperator', except for one detail: he named succesor his son Commodus, not a balanced boy, so to speak.

He is also known for his book Meditations writen in campaign. Meditations is still revered as a literary monument of service and duty. One fragment:

"To be kind is invincible"

Well, Swing was not kind at all. It was complex and bloated. Writing a simple layout with Swing was difficult. The same layout in JavaFX is a piece of cake.

How easy is to be kind with JavaFX!

Marcus Aurelius "the wise" faced many challenges. In Asia, the Parthian empire invaded Armenia and Syria. From the north germanic tribes launched raids againts the border. He deal successfully with the attacks. Key to their success was a prior decission:
Marcus accepted the emperor throne with one condition: that he and Verus (military chief) were made joint emperors. This way, Verus had little incentive to overthrow Marcus. Verus remained loyal until his dead in 169.

Today, this would be an example of 'strategic partnership'. Really it was just common sense. Java FX has a very good foundation, but you need more than a nice language to thrive. Strategic alliances are needed to leverage the JavaFX potential.

miércoles, 15 de julio de 2009

Playing with licenses - II



In the last post Playing with licenses we have outlined the main points for two kind of licenses:

- All right reserved: Author (the person who created the media work) has all the rights.
- Creative Commons (CC) license: Author leaves some rights. This license can take six forms:




Attribution (BY)

Figure 1. License BY



This license lets others distribute, remix, tweak, and build upon your work, even commercially, as long as they credit you for the original creation. This is the most accommodating of licenses offered, in terms of what others can do with your works licensed under Attribution.



Attribution - Share Alike (BY-SA)

Figure 2. License BY-SA


This license lets others remix, tweak, and build upon your work even for commercial reasons, as long as they credit you and license their new creations under the identical terms. This license is often compared to open source software licenses. All new works based on yours will carry the same license, so any derivatives will also allow commercial use.



Atribution - No Derivatives (BY-ND)

Figure 3. BY-ND license


This license allows for redistribution, commercial and non-commercial, as long as it is passed
along unchanged and in whole, with credit to you.



Attribution - Non commercial (BY-NC)

Figure 4. Attribution - Non commercial

This license lets others remix, tweak, and build upon your work non-commercially, and although their new works must also acknowledge you and be non-commercial, they don’t have to license their derivative works on the same terms.



Attribution Non Commercial Share-Alike (BY-NC-SA)

Figure 5. BY-NC-SA


This license lets others remix, tweak, and build upon your work non-commercially, as long as they credit you and license their new creations under the identical terms. Others can download and redistribute your work just like the by-nc-nd license, but they can also translate, make remixes, and produce new stories based on your work. All new work based on yours will carry the same license, so any derivatives will also be non-commercial in nature.




Attribution Non commercial Non derivatives (BY-NC-ND)

Figure 6. BY-NC-ND


This license is the most restrictive of our six main licenses, allowing redistribution. This license is often called the “free advertising” license because it allows others to download your works and share them with others as long as they mention you and link back to you, but they can’t change them in any way or use them commercially.


jueves, 9 de julio de 2009

Playing with licenses




Image Licenses are not necessarily a complex subject. You can even play with the concept. Let's take a very practical approach:

Consider the portal Picasa. Picasa (www.picasa.com) is a google online portal where photo aficionados can upload their captures. Users can take pictures and backup them online. You can easily tag, order, share and even manipulate every item of your great picture collection.
Picasa allows the user to decide the license of their creations, you can do it in Settings -> Privacy and Permissions .
Here you can choose an appropiate license for yout photos. Here is a screenshot:





Figure1. Choosing a license in Picasa


In short, you have two options: All rights reserved or a CreativeCommons license:


  • All right reserved
Wiht this license you retain all rights of your creation. It is a fair decission, for one thing you are the autor of the picture!
In this case, you can add the legend: ©All rights reserved.
What does that mean? If someone want to use your creation(for example, allocating your photo in their personal blog) needs to ask you for permission.
Every person o company that uses your photo without your permission can be sued.
May be you are asking, what is the point of this? Would not it be better to allow everybody to use all images? Well, it is your entire decission. If you want to allow
everybody to use your creation you can use other license (we will review theses licenses later), on the other hand if you want to retain all rights on your
creation you can do it. In theory (some authors disagree here )licenses provide authors with a greater incentive to create. This economic incentive fosters creation and innovation.


  • Creative Commons licenses
Leave some rights of your images. Of course, there are some rights you can not renounce,
for example attribution: You are the author of this great picture, and no license can change this fact. But you can renounce to some other rights, for example, you can allow everybody to use your picture without asking permission. In this case you can tag the image with this legend. CreativeCommons(CC)


OK, after this introduction let's present a JavaFX app equivalent to the Picasa license page:

Figure 2. Click for full size


In order to execute the application click the following link

More on the next blog post!

miércoles, 1 de julio de 2009

Shop till U drop!








Apple iTunes App Store (dubbed the last greatest capitalism experiment) has been a terrific success. More than 500m applications, from games to interactive travel guides, have been downloaded.

Without surprise more companies are roolling out their App Store:

  • Ericsson App Store. (Ericsson without Sony)
By August its customers will be able to personalize their phones with a range of downloadable utilities, tools, and games over multiple platforms
  • Vodafone App Store. Just announced.
  • Orange Application Store which is already available for selected handsets in France, official release will happen before the year is over in France first, followed by the UK.
  • Plaza Retail Store (Qualcomm)



  • Oracle Store (Oracle) Custormers can purchase Oracle VM Support, Oracle VM media packs, and Oracle Enterprise Linux support services media packs.

Ovi_lockup

At a glance: users from 152 countries around the world. Support for more than 75 Nokia devices. Integrated mobile billing with 27 operators globally. Localized in 5 different languages. Opened two weeks ago
  • Windows Marketplace (Microsoft)
Enter BlackBerry App World









Only a few shops will thrive. Without doubt Java Store will be one of these. You need more than a closed platform (you know? Ericsson phone chargers are not comppatible with their own previous models!) in order to be successful.


Update 1. Tony Cripps, principal analyst at mobile phone consultancy Ovum, said: "Every man and his dog wants an apps store. Apple's has been such a phenomenal success that all the other players are desperately trying to play catch-up as traditional revenues fall."

Update 2. "Two months ago Nokia launched a revamped app store called Ovi that featured games, applications, podcasts and videos. But the store got off to a rocky start, as users faced problems accessing it and downloading the programs. Nokia blamed the “extraordinarily high spikes of traffic” for the performance issues. "
Source: wired.com

jueves, 25 de junio de 2009

Code: Ten minute introduction to JavaFX




package tutorial;

import java.lang.Thread;
import javafx.data.pull.PullParser;
import javafx.data.xml.QName;
import javafx.io.http.HttpRequest;
import javafx.scene.Group;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.paint.Color;
import javafx.scene.paint.LinearGradient;
import javafx.scene.paint.Stop;
import javafx.scene.Scene;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import javafx.stage.StageStyle;


def sceneWidth = 425;
def sceneHeight = 300;

var sunrise: String; // sunrise time
var sunset: String; // sunset time

var topRectangle: Rectangle = Rectangle {
translateX: 0
translateY: 10
width: sceneWidth - 2
height: 60
stroke: Color.DARKBLUE
strokeWidth: 1
arcWidth: 32
arcHeight: 32
fill: LinearGradient {
endY: 0
stops: [
Stop {
offset: 0
color: Color.DARKBLUE
}
Stop {
offset: 1
color: Color.LIGHTBLUE
}
]
}
}

var bottomRectangle: Rectangle = Rectangle {
translateX: 2
translateY: 160
width: 400
height: 60
stroke: Color.DARKBLUE
arcWidth: 32
arcHeight: 32
fill: LinearGradient {
endY: 0
stops: [
Stop {
offset: 0
color: Color.DARKBLUE
}
Stop {
offset: 1
color: Color.LIGHTBLUE
}
]
}
}

var result: String = " Sunrise: {sunrise} \n Sunset: {sunset}" on replace oldValue {
println("replace");
}

var textResult = Text {
wrappingWidth: 200
translateX: 25
translateY: 100
content: bind result ;
fill: Color.DARKBLUE
font: Font { size: 18
}
}



var rightRectangle: Rectangle = Rectangle {
translateX: topRectangle.width - 210
translateY: 10
width: 210
height: 60
stroke: Color.DARKBLUE
arcWidth: 32
arcHeight: 32
fill: LinearGradient {
endY: 0
stops: [
Stop {
offset: 0
color: Color.DARKBLUE
}
Stop {
offset: 1
color: Color.LIGHTBLUE
}
]
}
}

var text = Text {
x: 10
y: 50
font: Font { size: 20
}
fill: Color.WHITE
content: " Barajas - Madrid "
}

var url = "http://weather.yahooapis.com/forecastrss?p=SPXX0050&u=c";
println(" url.length : {url.length()} ");
if (url.length() == 55 ) {
result = " Getting data .... ";

HttpRequest {

location: url
onDone: function() {
print ("done");
// Simulating a slow service
Thread.sleep(1000);
result = " Sunrise: {sunrise} \n Sunset: {sunset}" ;
}
onInput: function(input) {
try {
PullParser {
input: input
onEvent: function(event) {
if ((event.type == PullParser.START_ELEMENT) and (event.qname.prefix == "yweather")) {
if (event.qname.name == "astronomy") {
sunrise = event.getAttributeValue(QName{name: "sunrise"
});
println("sunrise = {sunrise}");


sunset = event.getAttributeValue(QName{name: "sunset"
});
println(" sunset = {sunset}");

}
}

}

}.parse()

} finally {
input.close();
}

}
}
}.start();

// Image
var sunImage: Image = Image {
url: "{__DIR__}media/sun.png"
}

var sunView: ImageView = ImageView {
translateX: 200
translateY: 50
image: sunImage
}

Stage {
title: " Sunrise and sunset in Barajas "
width: sceneWidth
height: sceneHeight
style: StageStyle.TRANSPARENT
scene: Scene {
width: sceneWidth
height: sceneHeight
content: Group {
content: bind [ topRectangle, text, rightRectangle, textResult, bottomRectangle, sunView ]

clip: Rectangle {
width: sceneWidth
height: sceneHeight
arcWidth: 32
arcHeight: 32
}
}
fill: Color.TRANSPARENT
}
}




Related post: Ten minute introduction to JavaFX

lunes, 22 de junio de 2009

A ten minute introduction to JavaFX



While RIA (which stands for Rich Internet Application) is not a very popular acronym , everybody knows what a Flash app is. Surfing the web we find Flash animations all the time. From simulations of the driving test exam to the operation of the Patriot missile interceptors.
Adobe Flash applications provide a user interface (drag and drop, sound, effects, graphics, animations) that would be very difficult to achieve using HTML and JavaScript, even using high-level libraries like Prototype. Adobe gives developers a programming environment (based on language ActionScript 3) to create Flash applications. This environment is very popular and provides tools to effectively coordinate the work of designers (Adobe Photoshop, Illustrator, sounds) and programmers. Flash applications are also popular among Internet users who do not hesitate to download the browser Flash plug-in.
The popularity of Flash makes it an attractive target for Adobe competition. Thus, alternatives have emerged that aim to put a dent in the market: Microsoft has released Silverlight. Of course, Flash developers are not going to change their platform without a compelling reason. By launching Silverlight Microsoft gave developers a full-screen graphics that used the GPU (graphics accelerator card). Adobe knows that and will offer this feature in the next release of Flash.

Figure1. Flash applications

This article (written in June 2009) will show us the features offered by Java FX and how is positioned against its competitors (Adobe Flash and Microsoft Silverlight).

Although the first official release 1.2 is available right now, important improvements and updates are in the way.

Go ahead to the official website of Java Fx , and download the Netbeans IDE. Once installed the environment, create a project (File>> New Project), we add an FX file (Empty Java FX file) and let's create a first test by dragging a rectangle from the palette 'Basic Shapes" on the editor:


Figure 2. Netbeans IDE

Note that when you release the rectangle, the environment automatically imports all necesary classes. If we execute the project (right click>> Debug) we get a window with no title that contains a rectangle:










Figure3. Execution of a JavaFX project

We did our first test !

We have to take into account some considerations: The language used is not Java but JavaScript FX, a new declarative language that runs onto the Java virtual machine. The reason to use a new language is to simplify the developer's life with a syntax more suitable for multimedia applications. It is a DSL (Domain Specific Language) that specializes in interactive entertainment. Here below the main features of the language.

Java FX Script language

We will now see a summary of the features of the Java FX Script language. For a broader view is recommended to consult the excellent tutorials from Sun.
The language incorporates the following basic types: String, Boolean, and Number. Variables are declared using the var keyword. Consider the following examples:


var x: Number = 0.9;
var name: String = "David";
var y: Integer = 0;
var flag: Boolean = true;
var numbers: Number = [1,2,3,4,5];


It is not mandatory to declare a variable type in its declaration. Thus, we can write the above lines as follows:


var x = 0.9;
var name = "David";
var y = 0;
var flag = true;
var numbers = [1,2,3,4,5];


Java operators == and ! have their equivalent in JavaFX:



(5 == 5 and 6 == 6) // => returns true
if (codebase == "" or codebase.startsWith ( "file:"))
not (5 == 4) // => true

Array handling is very intuitive:


def days = [ "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Sat", "Sun"];
println (days [0]) // Monday
println (days [1]) // Tuesday
println (days [2]) // Wednesday
println (days [3]) // Thursday
println (days [4]) // Friday
println (days [5]) // Saturday
println (days [6]) // Sunday

x = [1,2,3];
insert 10 as first into x ; // => [10,1,2,3]
insert 6 after x[. == 2]; // => [10,1,2,6,3]

To determine the size of the sequence use the sizeof keyword:



println ( "{sizeof days}"); // => 7

We can reverse a sequence:
var nums = [1 .. 5];
reverse nums; // => [5, 4, 3, 2, 1]


Unlike Java, JavaFX supports blocks. Blocks (also called closures) are very popular in scripting languages such as Smalltalk or Ruby, to perform a select on an array with a very compact syntax. Here is an example:

var list = [1,2,7,3,30,15,14,6,4];
var less_than_10 = list [n | n <10]>
println ( "Result: (menores_de_10)") => 1 2 7 3 6 4
var even = list [n | n mod 2 == 0];
println ( "Even: (even)") / / => 2 30 14 6 4


You can write an equivalent expression:

for (i in lista){ if (i <> 1 2 7 3 6 4
To create a class that models a postal address (with the attributes Street, City, State, ZipCode and a method print() to print a representation of the object) type:


Instantiating an object of class PostalAddress is as simple as:



var postalAddress = PostalAddress {
street: "Loop street "
city: "Los Angeles"
state: "California"
zipCode: "28042"
)


Unlike Java, JavaFX functions are first class entities. What does this mean? Very simple, with Java FX we can do things that were previously impossible in Java like passing a function as a parameter to another function . Here is an example:


function addN(n: Number): function(:Number): Number {
function(x: Number): Number { x + n }
}
var addTen = addN(10);
println(addTen(3)); // => 13.0


Let's study the code above: Attention to the signature of the addN () function . This function accepts a parameter of type Number and returns a function with signature
function (: Number).
In the next line, the function resulting from addN (10) is assigned to the variable addTen. addTen variable is a function that can be invoked like any other function. Later in the sample code we'll use this feature of JavaFX.


Time to put your feet up

In the light of the main features of the language we can write an example application. We want an application that informs the user of sunrise and sunset time in our city. The final application looks like this:


Let's see step by step how to build the application. First we need the data with sunrise and sunset times.
To obtain these data we will use a Web Service from Yahoo: Yahoo Weather Web Service. A client can launch a GET request against the service and get a XML like the following figure:


Figure 4. XML reponsse from Yahoo


From this response we are interested in only two figures. For the sunrise and sunset time, look for the node <(marked in bold) and get the attributes of sunrise and sunset. Java FX can easily perform this task with the class javafx.io.http.HttpRequest , who modeled a request and a parser javafx.data.pull.PullParser. To be able to customize the application to where we simply adapt the GET request. This request contains two parts, a base URL:

http://weather.yahooapis.com/forecastrss?

and two parameters:

p = SPXX0050 to indicate the location (in this case Barajas) and
u = c where we want to show the temperature units in Celsius degrees

In our case (Barajas), the GET request is as follows:
http://weather.yahooapis.com/forecastrss?p=SPXX0050&u=c






Note. To obtain the location code corresponding to the city where you live can be found on page Yahoo Weather. Here we introduce the name of our city in the search box. On the resulting page, the final part of the URL for the code we need. For example if we want the code for Sabadell city:



Click the GO button and we get the following page:



Therefore, the code for this location is
p = SPXX0066.



Thus, we created a new JavaFX class that we call Main.fx. First we declare a String :

var url = "http://weather.yahooapis.com/forecastrss?p=SPXX0050&u=c";

We also declare other variables we'll use later:

  def sceneWidth = 425;
def sceneHeight = 300;
var amanecer: String; //sunrise time
var ocaso: String; // sunset time

sceneWidht and sceneHeight variables are defined as constants (def) . The width and height of the application depends on the number of pixels of the bitmap graphics and will not change during execution. On the other hand sunrise and sunset will be modified during the life of the application, and therefore must use var.
We also declare an instance of HttpRequest that models the Yahoo Web service:


HttpRequest {
location: url
onDone: function() {
print ("done");
// Para simular un web service lento
Thread.sleep(1000);
resultado = " Amanecer: {amanecer} \n Ocaso: {ocaso}" ;
}
onInput: function(input) {
try {
PullParser {
input: input
onEvent: function(event) {
if ((event.type == PullParser.START_ELEMENT) and (event.qname.prefix == "yweather")) {
if (event.qname.name == "astronomy") {
amanecer = event.getAttributeValue(QName{name: "sunrise"
});
println("amanecer = {amanecer}");
ocaso = event.getAttributeValue(QName{name: "sunset"
});
println(" ocaso = {ocaso}");
}
}
}
}.parse()
} finally {
input.close();
}
}
}


Note that the HttpRequest class has the callback method onInput() will be activated once the client receives a response from the web service. Since the web service returns an XML, use the class PullParser to parse this response. To parse the response, find the node "yweater" and once found retrieve attribute values sunrise and sunset. This way we obtain the values desired. It is important to note that the class PullParser, the method is a callback function onEvent When you initialize the class PullParser at callbalck onEvent we assign a function to detect events parsing (starting XML node, end node XML). The definition of the graphical elements is easy. So to set the upper rectangle wrote:


var topRectangle: Rectangle = Rectangle {
translateX: 0
translateY: 10
width: sceneWidth - 2
height: 60
stroke: Color.DARKBLUE
strokeWidth: 1
arcWidth: 32
arcHeight: 32
fill: LinearGradient {
endY: 0
stops: [
Stop {
offset: 0
color: Color.DARKBLUE
}
Stop {
offset: 1
color: Color.LIGHTBLUE
}
]
}
}
To get a fill with a linear gradient, we use the class LinearGradient. The horizontal gradient begins with a dark blue and ends in a light blue.
Finally, we models all the graphical elements using the following code:


Stage {
title: " Amanecer y Ocaso en Barajas "
width: sceneWidth
height: sceneHeight
style: StageStyle.TRANSPARENT
scene: Scene {
width: sceneWidth
height: sceneHeight
content: Group {
content: bind [ topRectangle, text, rightRectangle, textResult, bottomRectangle, solView ]
clip: Rectangle {
width: sceneWidth
height: sceneHeight
arcWidth: 32
arcHeight: 32
}
}
fill: Color.TRANSPARENT
}
}
You can see the complete code of the application. You can also run the application by clicking the next link

JavaFXDeployement

All projects about data can be displayed in three ways:
  1. As an application (Standalone)
  2. - As a WebStart applet integrated within the browser (Web Start Execution)
  3. - As an application for a cell phone compatible data centers (Run in Mobile Emulator)
To choose one of three deployments are going to project properties and select the Run tab, Model Execution (Execution Standart, Run or Run in Browser in Mobile emulator).

Figure. Deployment of a JavaFX application

If you choose the wireless deployment you will have to use the emulator included in the platform (the first JavaFX phoneswill be the ones from LG and Sony-Ericsson in June 2009):

Figure. JavaFX emulator for mobile phone

Conclusions

Java FX Script is a declarative language, statically typed, object oriented and functional. Is designed specifically for writing graphical applications. The development kit provides a comprehensive multimedia library. The war to attract advanced users of ActionScript 3 (Adobe Flash) has begun, but this time Sun has a good arsenal.

Resources

JavaFX samples gallery
JavaFX 1.2 documentation