Aprendiendo javafx
Sep 17, 2007
Article
Learning JavaFX Script, Part 1: An Introduction to JavaFX Script for Java Programmers
By Robert Eckstein and the Authors of the JavaFX Programming Language Reference, July 2007
The JavaFX Script programming language (hereinafter referred to as JavaFX) is a declarative, statically typedscripting language from Sun Microsystems, Inc. As mentioned on the Open JavaFX (OpenJFX) web site, JavaFX technology has a wealth of features, including the ability to make direct calls to Java technology APIs. Because JavaFX Script is statically typed, it also has the same code structuring, reuse, and encapsulation features -- such as packages, classes, inheritance, and separate compilation anddeployment units -- that make it possible for your to create and maintain very large programs using Java technology. This series of three articles will help you get started with the JavaFX programming language. Part 1 of this series is an introduction to the JavaFX programming language, targeted to those who are already familiar with Java technology and the basics of scripting languages. Parts 2 and 3 ofthe series show how to use JavaFX technology to connect to a remote server using technologies such as Remote Method Invocation (RMI) and the Java API for XML Web Services (JAX-WS). The JavaFX Pad Application If you have a Java Runtime Environment (JRE) on your system, the easiest way to get started with JavaFX technology is to fire up the Java Web Start-enabled demonstration program, JavaFX Pad.Once you start the application, you should see a screen similar to what appears in Figure 1.
To access links, go to the website
Copyright (c) Sun Microsystems, Ltd.
1 of 41
Figure 1. The JavaFX Pad Application Running on Microsoft Windows Vista, JDK 6. JavaFX Pad starts with a default application already loaded, which it immediately executes. However, you can also cut and paste JavaFXsource code from this article over the sample, viewing any modifications. In addition, you can save and load the JavaFX source examples to your local disk. The JavaFX Pad application is a great way to see exactly what you're doing at runtime, modifying changes as you go, and instantaneously seeing the results. JavaFX Technology: A Statically Typed Language The JavaFX programming language is ascripting language with static typing. What exactly does this mean? Consider the following:
var myVariable = "Hello";
This declaration, similar to what you may find in JavaScript technology, creates a variable called myVariable and assigns it the string value Hello. However, after declaring the variable, let's try to assign it something other than a string:
myVariable = 12345;
Because the codedoes not use quotation marks around 12345, this variable is now being assigned an integer instead of a string. In JavaScript technology, dynamically retyping the variable will work fine. However, a statically typed language such as JavaFX will not allow this. This is because myVariable was initially declared as a String type, and the code later tries to reassign it as an integer. With JavaFX, avariable that is declared as a String must
To access links, go to the website
Copyright (c) Sun Microsystems, Ltd.
2 of 41
remain a String. In fact, if you enter those two lines of code into the JavaFX Pad demo, you'll immediately see an error at the bottom of the window, as shown in Figure 2.
Figure 2. Statically Typed Variables Cannot Change Type in JavaFX Technology. JavaFXTechnology: A Declarative Scripting Language JavaFX technology is also a declarative scripting language. But what exactly does declarative mean? To answer this question, consider this Hello World program from the OpenJFX web site:
To access links, go to the website
Copyright (c) Sun Microsystems, Ltd.
3 of 41
class HelloWorldModel { attribute saying: String; } var model = HelloWorldModel...
Regístrate para leer el documento completo.