Jim has posted 66 posts at DZone. You can read more from them at their website. View Full User Profile

An Apollo 8 Holiday Wish Echoed in JavaFX

12.20.2008
| 4494 views |
  • submit to reddit

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!

Published at DZone with permission of its author, Jim Weaver.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Tags:

Comments

Mikael Grev replied on Sun, 2008/12/21 - 1:29pm

On Mac about a letter on the right side is cut off.

Cheers,
Mikael Grev

Jim Weaver replied on Sun, 2008/12/21 - 8:29pm in response to: Mikael Grev

On Mac about a letter on the right side is cut off.

Mikael,

Would you (or any Mac user) mind trying again?  I decreased the wrapping width and increased the clip width.  I'll update the code in the article if it's corrected.

Thanks,

Jim Weaver

Romen Law replied on Mon, 2008/12/22 - 1:09am

(I appolagise if this appears multiple times, couldn't seem to post it)

 My xmas card using JavaFX 1.0

http://romenlaw.blogspot.com/2008/12/merry-christmas-javafx-10.html

cheers

romen

Mikael Grev replied on Mon, 2008/12/22 - 3:28am in response to: Jim Weaver

Jim,

It looks good now.

Cheers,
Mikael

Cristin Aderson replied on Mon, 2014/08/25 - 2:17am

christian christmas wishes

Christmas should be a time of love, no doubt. Some say it is. Some even suggest that life would be heaven if only we kept our Christmas spirit throughout the year.

christian christmas messages

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.