"A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, fight efficiently, die gallantly. Specialization is for insects." (Robert A. Heinlein)

Wednesday, 17 June 2009

JavaFx on EEEBuntu

The newly released version of Sun's JavaFx also comes with a Linux version. Even it's still a beta version I decided  to try it on the EEEPC 900
Why JavaFx on EEEPC?
I know that EEEPC is not the best choice for programming because of the small keyboard, the small screen and so on ... but the high portability of EEEPCgives you an ever-ready programming environment good for little experiments and for just having some fun programming.
Java SDK update
I first downloaded from Sun site the latest Jdk version, JavaFx requires at least 1.6.14 version while the currently installed version on EEEPC was 1.6.10.
I extracted Jdk files by executing its installation file
chmod a+x jdk-6u14-linux-i586.bin sudo mv jdk-6u14-linux-i586.bin /opt
sudo /opt/jdk-6u14-linux-i586.bin
then I configured the newly installed Java as default virtual machine by first adding it to the udate alternatives list (the whole command goes in a single line)
sudo update-alternatives --install /usr/bin/java java
      /opt/jdk1.6.0_14/bin/java 30
I at last selected the just installed Jdk as the default one using the command
 sudo update-alternatives --config java

Netbeans Configuration
I then configured Netbeans by editing its configuration file and replacing old JDK path with the new one
sudo gedit /opt/netbeans-6.5/etc/netbeans.conf
...
# Default location of JDK, can be overridden by using --jdkhome <dir>:
netbeans_jdkhome="/opt/jdk1.6.0_14/"
...
I finally launched Netbeans to verify it was working with the correct Jdk.
Installing JavaFx Plugins
After verifying Netbeans was working proprly and letting it download the lastest updates selected from Netbeans plugins window the three JavaFx plugins.

After plugins installation completed, and Netbeans IDE restarted, I've been able to start a new JavaFx project. Here is my first JavaFx script
 /*
* Main.fx
 *
 * Created on 16-giu-2009, 7.34.18
 */
package demofx;

import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.text.Text;
import javafx.scene.text.Font;
import javafx.scene.paint.LinearGradient;
import javafx.scene.paint.Stop;
import javafx.scene.paint.Color;

/**
 * @author maxx
 */

Stage {
    title: "Application title"
    width: 350
    height: 100
    scene: Scene {
        fill:LinearGradient {
                startX : 0.0
                startY : 0.0
                endX : 1.0
                endY : 0.0
                stops: [
                    Stop {
                        color : Color.BISQUE
                        offset: 0.0
                    },
                    Stop {
                        color : Color.BLUE
                        offset: 1.0
                    },
                ]
            }
        content: [
            Text {
                font : Font {
                    size : 56
                    embolden: true
                }
                x: 10
                y: 50
                content: "Hello World"
                fill: Color.BLACK
            }
            Text {
                font : Font {
                    size : 56
                    embolden: true
                }
                x: 15
                y: 55
                content: "Hello World"
                fill: Color.BLACK
                opacity: 0.5
            }
        ]
    }
}
(syntax highlighted by Code2HTML, v. 0.9.1) 
 and here is the result (just another "hello world" program).