Saturday Dec 06, 2008

Mobile + Desktop JavaFX !

Just want to put the attention on one important point regarding the coding in JavaFX. Everyone who is using JavaFX has to understand that this technology is supported on Mobile, Desktop and TV(tomorrow it will be). So, its important as a developer to write Generic Applications which run across the platform. In such cases you need to know how to adjust some silly things in the code, like so desktop it can be a big font whereas you need to reduce font size for mobile or same case with images. 

Here is one sample code, which can show you how to do :

package sample11;

import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.text.Text;
import javafx.scene.text.Font;

var mobile = FX.getProperty("javafx.me.profiles");
var isMobile = (mobile != null);
var s = 24;
var content = "Default";
if(isMobile == true) {
    s = 10;
    content = "Content in Mobile"
}
else { 
    s = 20;
    content = "Content on Desktop"
}

Stage {
    title: "Checking the Font"
    width: 350
    height: 280
    scene: Scene {
        content: Text {
            font : bind Font {
                size : s
            }
            x: 10, y: 30
            content: bind content
        }

    }
}

Run it on Desktop and on Mobile and see the different output.

(How to run on Mobile ? ---> Netbeans6.5 -> YourProject -> Right Click ->Properties -> Run -> Run as Mobile Emulator)

This feature has been nicely used in this sample :  InterestingPhotos.

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