I'd like to use a JavaFX program to echo the same holiday wish that the astronauts on the Apollo 8 mission extended 40 years ago. The program, as you'll see in the listing shortly, obtains the magnificant image below from the NASA website, so you'll be asked to confirm that you want to allow that. Click the Java Web Start link below the "Earthrise at Christmas" picture to start the program:
By the way, this will be the first example (a sort of Hello World/Earth program) in our upcoming Pro JavaFX book. Take a look at the source code for the program below to understand how it works:
/*
* HelloEarthRiseMain.fx - A JavaFX Script "Hello World" style example
*
* Developed 2008 by James L. Weaver jim.weaver [at] javafxpert.com
* as a JavaFX Script SDK 1.0 example for the Pro JavaFX book.
*/
package projavafx.helloearthrise.ui;
import javafx.animation.transition.*;
import javafx.animation.*;
import javafx.stage.Stage;
import javafx.scene.*;
import javafx.scene.effect.*;
import javafx.scene.image.*;
import javafx.scene.paint.*;
import javafx.scene.shape.*;
import javafx.scene.text.*;
import javafx.scene.transform.*;
var textRef:Text;
// Provides the animated scrolling behavior for the text
var transTransition = TranslateTransition {
duration: 60s
node: bind textRef
toY: -600
interpolate: Interpolator.LINEAR
repeatCount: Timeline.INDEFINITE
}
Stage {
title: "Hello Earthrise"
scene: Scene {
content: [
ImageView {
image: Image {
url: "http://www.nasa.gov/images/content/54427main_MM_image_feature_102_jw4.jpg"
}
},
Group {
transforms: bind Translate.translate(50, 180)
content: [
textRef = Text {
translateY: 100
textOrigin: TextOrigin.TOP
textAlignment: TextAlignment.JUSTIFY
wrappingWidth: 410
// Note that this syntax creates one long string of text
content: "Earthrise at Christmas: "
"[Forty] years ago this Christmas, a turbulent world "
"looked to the heavens for a unique view of our home "
"planet. This photo of Earthrise over the lunar horizon "
"was taken by the Apollo 8 crew in December 1968, showing "
"Earth for the first time as it appears from deep space. "
"Astronauts Frank Borman, Jim Lovell and William Anders "
"had become the first humans to leave Earth orbit, "
"entering lunar orbit on Christmas Eve. In a historic live "
"broadcast that night, the crew took turns reading from "
"the Book of Genesis, closing with a holiday wish from "
"Commander Borman: \"We close with good night, good luck, "
"a Merry Christmas, and God bless all of you -- all of "
"you on the good Earth.\""
// The approximate color used in the scrolling Star Wars intro
fill: Color.rgb(187, 195, 107)
font: Font {
name: "Arial Bold"
size: 24
}
}
]
clip: Group {
content: [
Rectangle {
width: 410
height: 85
}
]
}
}
]
}
}
// Start the text animation
transTransition.play();
As always, if you have any questions, please leave a comment.
Happy Holidays/Merry Christmas!
Jim Weaver
JavaFXpert.com
The image is not loading inside netbeans , even if I run application in browser , however it runs fine through webstart by asking permission to connect, I am running this example as given in your book, is there any fix to avoid this
Posted by: Account Deleted | April 05, 2009 at 07:24 PM
Very cool. I had to get through a lot of security prompts before it would run though. Any way to condense those into just one, or maybe two prompts?
Posted by: Seth | December 19, 2008 at 01:22 PM
Dean,
That typo is courtesy of my blogging software. The line should be:
fill: Color.rgb(187, 195, 107)
Thanks,
Jim Weaver
Posted by: James Weaver | December 19, 2008 at 11:23 AM
Jim,
There is a typo here, I think. The line:
fill: Color.#bbc36b
doesn't compile. Did you mean:
fill: Color.web( "#bbc36b" )
Dean
Posted by: Dean Iverson | December 19, 2008 at 10:28 AM