Understanding JavaFX - Small Navigation Code

So finally I am able to write a small code with the new Java FX API and Builder provided in NB 6.1. I have also seen one bug got fixed (maybe initially it was handled on a different way). Initially when we make any FX project in Netbeans, it basically store the \*.fx code into classes folder as well. There is no way one can find the .class file of the .fx file, which is not a problem now.

I have written one small navigation code of map from key control. Which moves the map left, right, up and down from the corresponding key. And the most part of the code line is to handle the boundary condition like the image should not move left when it is already in left most region and so on. Thanks to Vikram for helping me out in writing boundary condition, this is always confusing for me :-D. Here is the small code:

import javafx.application.Frame;
import javafx.application.Stage;
import javafx.scene.paint.Color;
import javafx.input.KeyEvent;
import javafx.input.KeyCode;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.input.MouseEvent;
import javafx.scene.transform.Translate;
import java.lang.\*;
import javafx.scene.geometry.Line;

var x1 : Number = 0;
var y1 : Number = 0;
//var myImage = Image { url: "{__DIR__}/./earth-map-big.jpg" };
var myImage = Image { url: "http://arstechnica.com/reviews/4q00/macosx-pb1/images/earth-map-big.jpg" };
var line: Line;

Frame {
    title: "MyApplication"
    width: 500
    height: 500
    resizable: false
 
    closeAction: function() { 
        java.lang.System.exit( 0 ); 
    }
    visible: true
    stage: Stage {
        fill:Color.BLACK
        content: [
            ImageView {
                image : myImage
                transform : [ 
                    Translate { x : bind x1, y : bind y1 }
                ]
                onKeyPressed: function( e: KeyEvent ):Void {
                    System.out.println(x1 + " " + y1);
                   if(
                    e.getKeyText() == "Left")
                    {
                        if(x1 < 0) {
                            System.out.println(x1);
                            x1+=50;
                        }
                    }
                    if(
                    e.getKeyText() == "Right")
                    {
                        if(Math.abs(x1  -  500) < myImage.width) {
                            System.out.println(x1);
                            x1-=50;
                        }
                    }
                    if(
                    e.getKeyText() == "Down")
                    {
                        if(Math.abs(y1  -  500) < myImage.height) {
                            System.out.println(y1);
                            y1-=50;
                        }
                    }
                    if(e.getKeyText() == "Up")
                    {
                        if(y1 < 0) {
                            System.out.println(y1);
                            y1+=50;
                        }
                    }
                }
                opacity:1  
            }
        ]
   }
} 

I am loading the image from URL itself, so it will take sometime(because Image size is 3200 X 1600). Rest all is mathematics :-). Still lot more fancy job to do !

Comments:

Nice stuff

Posted by Angad Singh on July 20, 2008 at 06:32 AM IST #

Thanks ! Learning :)

Posted by Vaibhav on July 20, 2008 at 04:36 PM IST #

I am glad to talk with you and you give me great help! Thanks for that, I am wonderring if i can contact you via email when i meet problems?

Posted by wow account on August 27, 2009 at 04:35 AM IST #

http://www.jsjyyb.cn

Posted by 涡街流量计 on September 28, 2009 at 04:11 AM IST #

http://www.shanghaimassages.net

Posted by shanghai massage on September 28, 2009 at 04:12 AM IST #

It was a very nice idea! Just wanna say thank you for the information you have shared. Just continue writing this kind of post. I will be your loyal reader. Thanks again.

Posted by Christian Louboutin Boots on October 28, 2009 at 11:34 PM IST #

christian louboutin discount thanks

Posted by christian louboutin discount on October 30, 2009 at 01:10 AM IST #

I have received several similar emails like this one.

Posted by link of london on November 06, 2009 at 10:33 PM IST #

I really believe that these social networks will have a huge impact on what we can accomplish as groups, it'll help us be very organized and communicate.

Posted by tiffanys on November 11, 2009 at 12:46 AM IST #

I really believe that these social networks will have a huge impact on what we can accomplish as groups, it'll help us be very organized and communicate.

Posted by christian louboutin on November 13, 2009 at 04:48 AM IST #

I think I will try to recommend this post to my friends and family, cuz it’s really helpful.

Posted by ed hardy sunglasses on November 16, 2009 at 10:38 PM IST #

Thanks for your useful info, I think it's a good topic.

Posted by air jordan shoes on December 04, 2009 at 12:00 AM IST #

Keep up the good work bro.Your article is really great and I truly enjoyed reading it.Waiting for some more great articles like this from you in the coming days.

Posted by ed hardy on December 10, 2009 at 05:21 AM IST #

<a href="http://www.ourshoesbox.com">christian louboutin</a>
<a href="http://www.ourshoesbox.com">boots</a>
<a href="http://www.ourshoesbox.com">high heels</a>
<a href="http://www.ourshoesbox.com">womens boots</a>
<a href="http://www.ourshoesbox.com">heels</a>
<a href="http://www.ourshoesbox.com">women's shoes</a>
<a href="http://www.ourshoesbox.com">knee boots</a>
<a href="http://www.ourshoesbox.com">women's boots</a>

Posted by lign on December 19, 2009 at 02:22 AM IST #

<p>&nbsp;&nbsp; Christmas is coming, not have prepare the gifts for your friends? <a href="http://www.christianlouboutinshoesdirect.com">Christian Louboutin</a> Shoes will be the nice presents. <a href="http://www.christianlouboutinshoesdirect.com/christian-louboutin-boots-c-7.html">Christian Louboutin boots</a> is your best choice, because <a href="http://www.christianlouboutinshoesstore.com/">Christian&nbsp; Shoes</a> have so many beautiful kinds of producsts. Like Christian <a href="http://www.christianlouboutinshoesmart.com/index.php">Louboutin Shoes</a> for your love. Christian Louboutin Boots for your best friends, and Christian <a href="http://www.christianlouboutinshoesdirect.com/christian-louboutin-shoes-c-8.html">Louboutin Shoes</a> for your family members. So now go to the online-store for your <a href="http://www.christianlouboutinshoesdirect.com">cheap Christian Louboutin Shoes</a></p>

Posted by Christian Louboutin on December 25, 2009 at 01:02 AM IST #

Just one question: how to add you blog into my rrs reader, thanks so much.

Posted by christian louboutin on January 03, 2010 at 12:45 AM IST #

Just one question: how to add your blog into my rrs reader, thanks so much.

Posted by christian louboutin on January 03, 2010 at 04:12 AM IST #

iam a fan of <a href=" http://www.christianlouboutin-mall.com" title="christian louboutin">christian louboutin</a> shoes iam crazy for them but the price is too high to afford i save up for a while my friend recommed www.christianlouboutin-mall.com to me as she have bought a pair from the guys do anyone have shopped with them and how do you think about it? also recently i have heard that <a href="http://www.cheap-mbt-shoes.com/" title="mbt shoes">mbt shoes</a> is hot do anyone buy them?

Posted by christian louboutin sale 75% on January 05, 2010 at 12:51 AM IST #

<a href="http://www.christianlouboutinshoesdirect.com">christian louboutin shoes</a>-The original <a href="http://www.christianlouboutinshoesdirect.com">louboutin boots</a>, first developed over forty years ago. Another original <a href="http://www.christianlouboutinshoesdirect.com">christian louboutin</a> is the <a href="http://www.christianlouboutinshoesdirect.com">christian louboutin boots</a>.

Posted by christian louboutin on January 07, 2010 at 04:38 AM IST #

oh.you are very great.I agre with you

Posted by christian louboutin shoes on January 08, 2010 at 01:37 AM IST #

This is great news. Best of luck for the future and keep up the good work.

Posted by China Wholesale on January 09, 2010 at 04:38 AM IST #

Thank you.Hot Shoes Cheap Jordan shoes michael jordan shoes and are on sale-Free shipping.

Posted by michael jordan shoes on January 10, 2010 at 11:10 PM IST #

I have enjoyed reading, I will make sure and bookmark this page and be back to follow you.

Posted by burton james furniture on January 22, 2010 at 06:40 PM IST #

This is great news. Best of luck for the future and keep up the good work.

Posted by christain louboutin on January 24, 2010 at 06:16 AM IST #

Thanks for your sharing things! They’re gorgeous! We’re getting ready to launch our new online Christian Louboutin for smaller busted women, so I can definately appreciate all the hard work you’ve put into expanding your business! I know it’s quite a fete!!! Congratulations! Looking forward to seeing your shoes at more events and websites!

Posted by Christian Louboutin shoes on January 25, 2010 at 10:10 AM IST #

[a/]http://www.linksoflondonhut.co.uk/[a]links of london jewellery[/a] is loved by most fashionable ladies all over the world, they all choose some other [a/]http://www.linksoflondonhut.co.uk/Linksoflondon_Category_5.html[a]links of london bangles[/a] also with some [a/]http://www.linksoflondonhut.co.uk/Linksoflondon_Category_2.html"[a]links of london charms[/a].

Posted by links of london jewellery on February 06, 2010 at 05:16 AM IST #

I think in the end, Sun will do http://www.hangxiang.cn/ the right thing in this dispute. I would bet that ASF will eventually be allowed http://www.suntasksolar.com/ to get the TCK without the "Field of Use" restriction.

Posted by Solar lighting on March 03, 2011 at 11:36 PM IST #

Post a Comment:
Comments are closed for this entry.
About

Hi, I am Vaibhav Choudhary working in Sun. This blog is all about simple concept of Java and JavaFX.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today