Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

An Apollo 8 Holiday Wish Echoed in JavaFX

DZone's Guide to

An Apollo 8 Holiday Wish Echoed in JavaFX

· Java Zone
Free Resource

Build vs Buy a Data Quality Solution: Which is Best for You? Gain insights on a hybrid approach. Download white paper now!

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. 

By the way, this will be the first example (a sort of Hello World/Earth program) in our upcoming Pro JavaFX book.  

Click the Java Web Start link below the "Earthrise at Christmas" picture to start the program:

HelloEarthRise-ss

 

Webstart.small2

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!

Build vs Buy a Data Quality Solution: Which is Best for You? Maintaining high quality data is essential for operational efficiency, meaningful analytics and good long-term customer relationships. But, when dealing with multiple sources of data, data quality becomes complex, so you need to know when you should build a custom data quality tools effort over canned solutions. Download our whitepaper for more insights into a hybrid approach.

Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}