Monday, November 5, 2007

Introducing JavaFX: Sun’s new family of Java-based products

Introducing JavaFX: Sun’s new family of Java-based products
Author: Peter Mikhalenko


JavaFX is a new family of products and technologies from Sun Microsystems that you can use to create Rich Internet Applications (RIAs). JavaFX currently consists of JavaFX Script and JavaFX Mobile; other JavaFX products are planned for release in the future.
JavaFX is anticipated to compete in the space already occupied by
Adobe AIR and Microsoft’s Silverlight technologies. In a nutshell, Adobe AIR enables Flex and DHTML developers to build applications for the desktop; Silverlight allows developers to build rich media applications that run in the browser; and JavaFX Script lets developers build rich UIs for Java applications.

JavaFX products
JavaFX Mobile is a complete mobile operating and application environment built around Java and Linux. JavaFX Script is a highly productive scripting language for content developers to create rich media and content for deployment on Java technology. JavaFX Script is the core of the JavaFX family, and it’s the most interesting part of the product set. (Sun thinks that developers will shorten JavaFX Script to JavaFX in conversations, as long as JavaFX Script is the core in the JavaFX product family.)

JavaFX Script is intended to simplify the creation of rich UIs for Java clients. JavaFX Script is implemented in Java, and it uses Java APIs for 2D and 3D graphics as well as UI controls. JavaFX Script supports a declarative syntax for UI definition that is somewhat similar to the ones used by Microsoft in XAML and Adobe in MXML, yet it’s not XML-based. In fact, it’s a real programming language — not just a markup tool — so you can write an entire application in JavaFX Script.

If you want to write JavaFX applications directly from the IDE, the best way to do that is to download and install JDK 6.1 with NetBeans 5.5.1 or 6.0 and then install the JavaFX Script plug-in for NetBeans 5.5.1 or the JavaFX Script plug-in for NetBeans 6.0. There is also a JavaFX plug-in for Eclipse.

There is a separate initiative called OpenJFX Compiler, which focuses on creating a JavaFX compiler to translate JavaFX scripts directly into JVM class files (bytecode) without any intermediate steps. It is still in the very early stages of design and implementation.

Hello World application
This is the typical “Hello World” application:


import javafx.ui.*;
Frame { title: "Hello World JavaFX"
width: 300
height: 100
content: Box {
content:
[Label {
text: "Hello World"
toolTipText: "Tool tip"
font: Font {
size: 18
}
border: EmptyBorder {
top: 10
left: 10
}
background: Color {
blue: 255
green: 255
red: 255
}
}]
}
visible: true
}
View the code online.

In order to run this application in NetBeans 5.5, you need to follow these steps:
1. Launch NetBeans 5.5.
2. From the main menu, go to File New Project.
3. In the New Project window, select the General category, select Java Application project, and click Next.
4. In the New Java Application window, type FXExample in the Project Name text field.
5. In the same window, use the Browse button to select the location of the project.
6. Uncheck the Set As Main Project and Create Main Class check boxes and click Finish.
7. Right-click on the FXExample Source Packages and select New - File/Folder.
8. In the New File window, select the Other category, select the JavaFX File file type, and click Next.
9. In the New JavaFX File window, type “HelloWorld” for the File Name, type “src” for the Folder, and click Finish.
10. Copy the code from Listing 1 and paste it in HelloWorld.fx.
11. Right-click FXExample project and select Properties.
12. In the Project Properties - FXExample, select the Run node from the Categories pane.
13. In the Arguments text field, type “Hello World” and click OK.
14. Right-click FXExample project and select the Run Project option.
If everything works, you should see the Hello World application running (see Figure A).
Figure A


To read the complete article click on the link: http://blogs.techrepublic.com.com/programming-and-development/?p=539&tag=nl.e138

No comments: