Image of the Day - NASA + JavaFX

In last blog entry, we talked to have some blogs on Web Service to show how things go. Here is one of the simplest.

JavaFX is moving towards it's next release and work is ON. One of my friends came to my desk and he saw some animation of weather going here and there. He asked me " Is it some scientific data, data from NASA or something like that, if not what is this animation all about". Meantime, I checked the RSS feeds/WebService by NASA and I use one here to get something called "Image of the Day".

Its a big size image and so decide to showcase fullscreen example as well. Here goes the small code :


package nasaimage;

import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.image.ImageView;
import javafx.scene.image.Image;
import javafx.scene.input.MouseEvent;
import javafx.scene.Node;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.scene.text.TextAlignment;

 \* @author Vaibhav

var s: Stage;
public var vText: Boolean = true;
var ly: LocationY = LocationY{};
var im = ImageView {
    fitHeight: bind s.height
    fitWidth: bind s.width
    image: bind Image {
        url: ly.urlImage

var rect = Rectangle {
   blocksMouse: true
   x: bind s.width - 25
   y: 20
   arcHeight: 4
   arcWidth: 4
   width: 20,
   height: 20
   stroke: Color.GRAY
   strokeWidth: 2
   onMouseClicked: function( e: MouseEvent ):Void {
/\* close button 'x' in title bar \*/
var close = Text {
   fill: Color.WHITE
   font: Font {
       name: "Arial Bold"
       size: 18
   x: bind s.width - 20
   y: 35
   content: "x"

var loadingText = Text {
   visible: bind vText
   fill: Color.BLACK
   font: Font {
       name: "Arial Bold"
       size: 20
   x: 20
   y: 20
   content: "Loading Image from NASA WebService..."

function run() {
s = Stage {
    title: "Nasa Image"
    width: 300
    height: 300
    fullScreen: true   
    scene: Scene {
        content: [
            loadingText,im, rect, close


package nasaimage;

import java.lang.Exception;

 \* @author Vaibhav

public class LocationY {
    public var urlImage:String;
    var url = bind "";
    var p: PullParser;
    var h: HttpRequest;
    init {
        if (url.length() > 0) {
            h = HttpRequest {
                location: url
                onException: function(exception: Exception) {
                    print("Please check the internet connectivity or Data Input");
                onInput: function(input) {
                    p = PullParser {
                        input: input
                        onEvent: function(event) {
                            if ((event.type == PullParser.END_ELEMENT)) /\* and ( == "current_conditions")) \*/{
                                if ( == "enclosure") {
                                    urlImage = event.getAttributeValue(QName{name:"url"});
                onDone: function() {
                Main.vText = false;

Don't ask me why I am using LocationY.fx as filename. Sometime back, I made my first webservice with name LocationY and from that time, I am copying the same file.

Last day Photo was more awesome than this. I guess it was something related with stars :). As talked in the prev. blog about the use of OnDone() method, here it is. Before loading of image, you will see a text   'Loading Image from NASA WebService...'. This text vanishes when image get loaded because we have called its visible: false in OnDone() method of HTTP.

I hope you love this short code and start of webservices. Thanks to NASA website to provide this RSS feed :).


Thanks for the post! Just a correction: the last statement of LocationY.fx should be "h.enqueue();" instead of "h.start();"

Posted by Stanislas Rusinsky on May 12, 2009 at 07:37 AM IST #

h.start() ???

it won't compile without h.enqueue() - what version are you using?

I can't get it to run, but hat is probably the firewall at work?


Posted by jimbo9 on May 12, 2009 at 07:48 AM IST #

ah sorry .. actually this is a change in FX 1.1 and 1.2. So, I was using 1.2. Mistake from my side, it is h.enqueue() only. When you go to 1.2 it is h.start().

thanks for correction.

Posted by Vaibhav Choudhary on May 12, 2009 at 08:09 AM IST #

Hi Vaibhav,
Good work. I am very new to this javaFX world. can you develop web application as you develop in j2ee ? if yes could you give a demo on it? Thanks in advance

Posted by Rajesh on May 14, 2009 at 12:06 PM IST #

thanks ! JavaFX is a client technology, so it is more analogous to applet rather than j2ee. Yes, you can embed it anything anywhere :). I will try to write a demo for it.

Posted by Vaibhav on May 15, 2009 at 03:09 PM IST #

Hi again,
Thanks alot. Can I develop websites using javaFX technology because I am more concerned in developing websites and I didnt find any way to run javaFX in server. So could you please help me regarding this?

Posted by Rajesh on May 18, 2009 at 02:14 AM IST #

If I can develop website is it the right way to develop website using javaFX.Please tell me in details.

Posted by Rajesh on May 19, 2009 at 02:59 AM IST #

yes, website development will be in JSP or any technology but content show will be in JavaFX :). I am trying to make some example which can help us out !

It is the same way, for content representation we use flash in website.

Posted by Vaibhav Choudhary on May 22, 2009 at 07:59 AM IST #

when I tried to run jnlp file of ur tutorial it gives me error saying unable to validate certificate what could be the problem?

Posted by Rajesh on May 25, 2009 at 07:30 AM IST #

oh this is a strange problem. can you give me the complete log of that file !

Posted by Vaibhav Choudhary on May 25, 2009 at 07:58 AM IST #

thanks you very very much.thanks you very very much.

Posted by mp3 indir on November 25, 2009 at 08:35 AM IST #

Post a Comment:
  • HTML Syntax: NOT allowed

Vaibhav Hi, I am Vaibhav Choudhary working in Oracle with JDK team. This blog is all about simple concept of Java, JVM and JavaFX.


« February 2016