发布新日志

  • 零碎知识总结

    2009-07-31 11:12:14

    一. 检查jar文件是否被signed:

    cd 到jarfile所在的目录内,如C:\Program Files\JavaFX\javafx-sdk1.2\bin内。

     然后输入命令jarsigner -verify jarfile, 就会显示jar文件是否被signed。如:jarsigner -verify jmc.jar

    二. javafxpackager using specific keystore

    举例说明:

    1. Install JavaFX SDK

    2. goto %JAVAFX_HOME%\samples

    3. copy one sample archive (for example DisplayShelf) to a location where you can expand, say for example \\FxSamples

    4. cd \\FxSamples\DisplayShelf

    5. Generate an FxKeyStore keystore using the following command:

      keytool -genkey -dname "cn=FX packager,ou=CSG,o=SMI,c=US" -alias FxKey -keypass abc123 -keystore FxKeyStore -storepass xyz789 -validity 365  

      Make sure you have JDK\bin in your path.

    6. package the DisplayShelf sample application using a command like:

      javafxpackager -src src -appClass displayshelf.Main -keyStore FxKeystore -keystorepassword xyz789 -keyalias FxKey -keyaliaspassword abc123 -sign

    7. javafxpackager should produce under the dist directory a jar along with a corresponding applet (in an html file) and a jnlp file.

    Expected :

    1. Loading the html or the jnlp file should start the applet/web start.
    2. Verify that the loaded application is signed. The applets and jnlp should prompt the security dialog with the specific signing details.
    3. Make sure there is no exception  shown in java Console while loading an applet or webstart application.
  • javaFX 相关软件下载

    2009-06-16 18:14:00

    http://java.sun.com/javafx/downloads/
    这个是官方网站,相关的NetBeans IDE for JavaFx、JavaFX SDK、JavaFX Production Suite 都可以在这下载到。
  • JavaFX Script 编程语言

    2009-06-16 17:49:29

    http://developers.sun.com.cn/javafx/1/tutorials/core/index.html
    在这个网址是javafx script的教程,学习javafx的好地方。
  • javafx教程(转)

    2009-06-09 17:28:37

    JavaFX教程

    ************文中的例子是以Netbean6.1来演示的,还有你必须在Netbeas中安装JavaFX SDK 。
    Chapter   1:数据类型

        1.1 基本类型

        JavaFX语言提供四种基本类型:String(字符串)、Boolean(布尔)、Number(数值)和Integer(整数)。这些类型相当于Java   的如下类型:

          JavaFX                   Java

             String                   java.lang.String
             Boolean                java.lang.Boolean
             Number                java.lang.Number
             Interger                byte,short,int,long,BigInteger

    Example:

       var   s:String="Hello"   ;
                   
                    s.toUpperCase();   //   "HELLO"
                   
                    s.substring(1) ; //   "ello"
    同时还要说明一点,JavaFX的字符串可以用双引号,也可以用单引号。
           var s = 'Hello';
       与   var s=   "Hello";   是等价的。

    -------------------------------------------------------------------------------------------------------------------------
    注意:JavaFX中字符串的连接与java不同,JavaFX不支持+连接字符串。连接方式如下:
       方法一:
                 var   s:String ="Hello";
                       var   s1="{s} World";

          方法二:
       JavaFX提供了concat()方法连接两个字符串
          var s1= "Hello".concat(" World");
    -----------------------------------------------------------------------------------------------------------------------       
                var n:Number=12.5 ;

                    n.intValue();     //    12
                (12.5).intValue(); //     12
             
              var b:Boolean = true;
                b intstanceof Boolean; // true

    下面我们用个Demo 来体验一下这些基本类型的使用吧!

    在Netbeans 6.1中文件->新建项目->样例->JavaFX   展开节点 在Best Practice中任选一个例子。我这里是选的是transform中的Rotate。在源包的transform中打开Rotate.fx文件。可以看到下面这样的代码。
       package transform;

    import javafx.gui.*;
    import javafx.animation.*;

    import java.lang.Math;
    import java.util.Random;

    var angle : Number = 0.0;
    var jitter : Number = 0.0;

    var random : Random = new Random();

    var ticker : Timeline = Timeline {
    repeatCount: Timeline.INDEFINITE
    keyFrames : 
           KeyFrame. {
             time : 20ms
             action : function(): Void {
                angle += jitter;
             }
    }
    };

    var jitterTimeline : Timeline = Timeline {
    repeatCount: Timeline.INDEFINITE
    keyFrames :
           KeyFrame. {
             time : 1s
             action : function(): Void {
                jitter = random.nextDouble() * 12 - 6;
             }
    }
    };

    Frame. { 
    content : Canvas {
           background : Color.GRAY
           content : Rectangle {
             transform. [ 
                javafx.gui.Rotate { angle : bind angle, x : 100, y : 100 }, 
                javafx.gui.Translate { x : 43, y : 43 } 
             ]
             width : 114, height : 114
             fill : Color.WHITE
           }
    }

    visible : true
    title : "Rotate"
    width : 200
    height : 232
    closeAction : function() { java.lang.System.exit( 0 ); }
    }

    ticker.start();
    jitterTimeline.start();
          
    可以先运行一下看看是什么样的东西。

    好了,我们可以看到一个以Rotate为标题的窗体里有一个白色的正方形在转动。

    接下来我们就在这个程序代码中作一点添加和修改,来体验一下我们上面讲到的基本类型的用法。

    首先在var jitter : Number = 0.0;后面加上     var s : String = "Hello";这一句,然后装下面的
    title :"Rotate" 换成 title :s 。运行一下,可以看到窗体的标题变成了“Hello”,接着把s 换成
    s.toUpperCase()   可以看到标题变成“HELLO”。同样s.substing(1) 标题变成 “ello”。

    下面来试一下Number 类型。

    同样在var s : String = "Hello";下面加上var n : Number = 12.5;

    然后我会找到下面这段代码:
    var jitterTimeline : Timeline = Timeline {
    repeatCount: Timeline.INDEFINITE
    keyFrames :
           KeyFrame. {
             time : 1s
             action : function(): Void {
                jitter = random.nextDouble() * 12 - 6;
             }
    }
    };
    装里的那个12换成n.intValue()或(12.5).intValue()可以看到效果和前面的一样。

    同样你可以通过你自己申明的类型来替换里的变量来体会一下吧。


    ----------------------------------------------------------------------------------------------------------------------
    1.2   数组

        在JavaFX中最常用的数据结构就是数组,它在JavaFX中通过方括弧和逗号来声明:

       如:   var week_days=["Mon","Tue","Wen","Thu","Fri"];

       数组代表了一组顺序的对象.JavaFX中的数组本身不是对象,而且不能嵌套.创建嵌套数组
    的表达式如下:

    var days = [week_days,["Sat","Sun"]];

    会被自动扁平化,例如:

    days==["Mon","Tue","Wen","Thu","Fri","Sat","Sun"];//return true

    数组的大小可以通过JavaFX的sizeof操作符确定:

    var n = sizeof days;//n = 7

    对于数组成员形成数列(arithmetic series )的数组,JavaFX提供了一种简写符号:".."。
    下面提供了定义阶乘和奇数求和函数的示例,其中“result”的数值是1至100中的奇数
    的和:

    function fac(n)   {return product([1..n]);}

    var result = sum([1,3..100]);

    数组中的所有元素必须是同一种类型。

    数组可以像在Java中那样通过索引访问:

       
       var wendesday = days[2];

    JavaFX中的[]操作符还可以用来表示选择(类似XPath的用法)。在这种情况下,[]中包含的
    表达式应是一个布尔表达式。此表达式可以返回一个新的数组,此数组中只包含满足[]
    中断言(prddicate)的成员。

    在[]操作符包含的断言中通过操作符访问上下文对象。例如:

       var nums = [1,2,3,4];
       var numsGreaterThanTwo = nums[.>2];//   [3,4]

    另一种方法,也可以将变量声明为上下方对象。例如,这种方式与上面的方式等价:

       numsGreaterThanTwo = nums[n|n>2];

    JavaFX中的indexof操作符返回对象在数组中的顺序位置。

    下面list的car和cdr可以用选择表达式来表示:

    function car(list) {return list[indexof .==0];}

    function cdr(list)   {return list[indexof .>0];}

    当然,car可以用更简单、高效的方式表示:

    function car(list) {return list[0];}

    Example:

       var list = [1..10];
       car(list);// 1
       cdr(list);// [2,3,4,5,6,7,8,9,10]

    JavaFX中的空数组[]与null等价,Example:

    [] ==null;//true

    sizeof null // 0

    -------------------------------------------------------------------------------------------------------------------------------------------
    1.2-2 数组的插入

       除了赋值操作“=”之外,JavaFX 还提供数据修改操作符“insert ” 和 ”delete“。
       
        具体的方法如下:
        insert语句
        可以用下面方式中的任意一种进行声明:

        insert Expression1 [as first | as last] into Expression2
       
       insert Expression1 before Expression2

       insert Expression1 after Expression2

       insert语句将表达式1求值后的返回结果插入到下面表达式中所描述的位置:
        into 表达式2必须指向一个属性或者变量。如果表达式2指向一个单值属性,那么插入的效果等同于赋值操作。
        如果指定了as first,那么插入位置就在表达式2所表示的列表的第一个元素的前面。如果指定了as last,那么插入位置就在表达式2所表示的列表的最后一个元素的后面。如果没有明确地指定as first或者as last,则默认为as last。

      
    Example:
       
        var x=[1,2,3];

        insert 10 after x[.== 10]; //yields     [1,2,3,10]

        insert 12 before x[1];        //yields    [1,12,2,3,10]

        insert 13 after x[.==2];     // yields     [1,12,2,13,3]


    delete语句
          
    delete语句可以使用下面形式中的一种:

    delete variable

    delete variable[predicate]

    delete variable[predicate]

    delete Expression.attribute[predicate]

       前两种形式将删除变量或者属性中的所有元素,它们等价于将变量或者属性赋值为[]或者null,后两种形式仅删除满足断言的元素。


    Example:
      
    var x = [1,2,3];
       
        insert 10 after x[.== 10]; //yields     [1,2,3,10]

        insert 12 before x[1];        //yields    [1,12,2,3,10]
      
        delete x[.== 12];          //yields    [1,2,3,10]

        delete x[.>= 3];          //yields       [1,2]

        insert 5 after x[.== 1]; //yields       [1,5,2]

        insert 13 after first into x; //yields       [13,1,5,2]

        delete x;                      //yields       []
  • JavaFX 1.1 Production Suite

    2009-06-01 16:56:53

    Getting Started With JavaFX 1.1 Production Suite

    This tutorial shows designers how to use some of the tools in JavaFX 1.1 Production Suite to export JavaFX graphics from Adobe Illustrator CS3 or Adobe Photoshop CS3, and to view them with JavaFX Graphics Viewer.

    JavaFX Production Suite is a set of tools that enable designers to hand off visual assets to developers for use in JavaFX applications with expressive content. Designers can produce a rough sketch with the basic graphic objects, which developers can use in their applications while waiting for the final artwork. Graphic objects such as layers and effects are preserved in the conversion to JavaFX. Developers can manipulate graphic objects individually, which means that a single graphic can be often be used for an entire JavaFX application. As the visual design evolves, developers can drop new versions of the artwork into their application.

    The following tutorial uses one of the samples included with JavaFX, called the 15 Puzzle, to show you how to export JavaFX Graphics from Adobe Photoshop CS3 or Adobe Illustrator CS3, and also how to view the graphics using JavaFX Graphics Viewer, another tool included with Production Suite. In JavaFX Graphics Viewer, you can preview how the graphic will look when deployed to either desktop or mobile applications.

    Tutorial: Export and View Your First JavaFX Graphic

    When you export a graphic from Adobe Illustrator or Adobe Photoshop to JavaFX, a file with an FXZ extension is created. FXZ is a compressed file using zip compression and file format. It always contains an FXD file, which is a text description of the graphic. In addition, it might contain embedded assets, such as image files or TrueType fonts. The FXZ file is used as a source file by JavaFX developers.

    Designers can view FXZ files using JavaFX Graphics Viewer, included with Production Suite. Developers can use the NetBeans IDE 6.5 for JavaFX 1.1 to view the graphic, the source description, and archive information about the file.

    In this tutorial, you will export a file from Adobe Photoshop or Adobe Illustrator to an FXZ-format file and then view the result.

    Launch Adobe Illustrator or Adobe Photoshop CS3

    Open Adobe Illustrator or Adobe Photoshop CS3.

    Open the 15-Puzzle Sample Graphic

    1. Open one of the 15-puzzle sample graphics.

      • If you are using Adobe Photoshop CS3, open fifteen.psd, shown in Figure 2.

        This file is also located in the art/ps directory after you unzip the sample, located in the/Samples/puzzle15 folder of the Production Suite installation.

      • If you are using Adobe Illustrator, open fifteen.ai, shown in Figure 3.

        This file is also located in the art/ai directory after you unzip the sample, located in the/Samples/puzzle15 folder of the Production Suite installation.

    2. Make a note of the names of the graphic objects in the graphic, particularly those with a jfx: prefix. 

      The names of the graphic objects that are prefixed with jfx: are the ones that will be manipulated as objects in the JavaFX application. Note that these graphics objects have the same names in both the Adobe Illustrator and Adobe Photoshop artwork. Even though the graphics look very different, as long as their names are the same, they can be used interchangeably in the application.

      The 15 Puzzle in Adobe PhotoshopFigure 2: The 15 Puzzle in Adobe Photoshop

      The 15 Puzzle in Adobe IllustratorFigure 3: The 15 Puzzle in Adobe Illustrator

    3. Select one of the following two procedures, depending on whether you are using Adobe Photoshop or Adobe Illustrator.

    Export from Adobe Photoshop CS3 to JavaFX File Format

    1. Choose File > Automate > Save for JavaFX.

      The Export Options screen opens. This might take some time, depending on the size of the graphic.

      Adobe Photoshop JavaFX Export Options Dialog BoxFigure 4: Adobe Photoshop JavaFX Export Options Dialog Box

    2. To display a preview of the JavaFX graphic, select Show Preview. You can also choose any of the following options. 

      OptionResult
      Select Fit on ScreenSize the JavaFX preview so the entire graphic displays in the window. Does not affect how the graphic is saved.
      Select a percentage of magnificationEnlarges or shrinks the preview. Does not affect how the graphic is saved.
      Note: The Fit on Screen checkbox must be cleared to enable magnification.
      Select Desktop or Mobile previewPreview the graphic as it will appear in a desktop or mobile application. Does not affect how the graphic is saved.
      Select whether or not to export effectsPreview the graphic as it will appear depending on whether or not effects will be saved.
      You can also preview the file size and the number of JavaFX nodes that the graphic will contain when saved. These statistics become especially important when deploying to mobile applications.

    3. Click Save, choose a location for the JavaFX graphic, and click Save again.

    Export from Adobe Illustrator CS3 to JavaFX File Format

    1. Choose File > Save for JavaFX.

      The Export Options screen opens. This might take some time, depending on the size of the graphic.

    2. To display a preview of the FXZ graphic, select Show Preview. You can also choose either of the following options. 

      OptionResult
      Select Fit on ScreenSize the FXZ preview so the entire graphic displays in the window. Does not affect how the graphic is saved.
      Select a percentage of magnificationEnlarges or shrinks the preview. Does not affect how the graphic is saved.
      Note: The Fit on Screen checkbox must be cleared to enable magnification.
      Select Desktop or Mobile previewPreview the graphic as it will appear in a desktop or mobile application. Does not affect how the graphic is saved.
      Select an option for how effects will be savedPreview the graphic as it will appear depending on the choice of how effects will be saved. For more information on the choices, see the Production Suite online help.
      You can also preview the file size and the number of JavaFX nodes that the graphic will contain when saved. These statistics become especially important when deploying to mobile applications.

    3. Click Save, choose a location for the JavaFX graphic, and click Save again.

    If you accept the default file name, the JavaFX graphic is saved as fifteen.fxz.

    Open the File in JavaFX Graphics Viewer

    Figure 5 shows how a JavaFX graphic can be displayed in JavaFX Graphics Viewer.

    JavaFX Graphic for 15 Puzzle Displayed  in JavaFX Graphics ViewerFigure 5: JavaFX Graphic for 15 Puzzle Displayed in JavaFX Graphics Viewer

    Open the JavaFX graphic that you created in JavaFX Graphics Viewer in any of the following ways:

    • Double-click fifteen.fxz

    • Right-click fifteen.fxz (or Control-click on Mac), then select Open With > Viewer.

    • Navigate to the JavaFX Production Suite installation directory and do one of the following: 

      • On Windows: Double-click the Viewer folder, then double-click Viewer.exe.
      • On Mac: Double-click Viewer.

      Click File > Open and navigate to fifteen.fxz.

    • (Windows only) From the Start menu, click All Programs > JavaFX Production Suite > JavaFX Graphics Viewer, then click File > Open and na
  • Getting Started with JavaFX Script

    2009-06-01 14:07:35


    Ready to explore the JavaFX Script. programming language? Great! This lesson describes the software that must be installed on your system before you can begin. It also provides NetBeans IDE and command line instructions for compiling and running your first application.
     
    Contents
     
    Step 1: Download and install the JDK
    Step 2: Choose a Development Environment
    Step 3 : Download and Install the JavaFX Compiler and Runtime
     

    The JavaFX Script. programming language is based on the Java Platform, and as such, requires JDK 5 or JDK 6 (6 is faster) to be installed on your system. If you have not done so already, download and install JDK 6 or JDK 5 now, before proceeding with this tutorial.

    When it comes to choosing a development environment, you have two broad categories of choices: use an Integrated Development Environment (IDE), or use a plain text editor. This choice is entirely a matter of personal taste, but the following summary might help you to make an informed decision.

    Generally speaking:

    • An IDE provides a complete development environment all in one place. You download one piece of software, or perhaps a plug-in to that software, which provides everything you need to compile/run/debug your application. IDEs present the most commonly used functions as Graphical User Interface (GUI) elements, and offer many useful features, such as automatic code completion and custom source code views. An IDE also gives you immediate feedback on errors and highlights code so that it is easier to understand. The officially supported IDE for the JavaFX Script. programming language is NetBeans IDE 6.5.1. The NetBeans IDE website provides instructions for downloading, installing, and configuring the IDE.

    • A text editor provides simplicity and familiarity. Experienced programmers often rely on their text editor of choice, preferring to work in that environment whenever possible (some editors, like vi, have a rich set of built-in keystroke commands that some programmers simply cannot live without!) If you already have a preferred editor, rest assured that you can download the sample code for each lesson as .fx source files for use in your editor of choice.

    The JavaFX Script. programming language is a compiled language, which means that any source code you write must first be converted into Java bytecode — the language of the Java Virtual Machine — before it can run on your system. This is true regardless of your development environment (be it command line or IDE). After installing the JDK and choosing a development environment, you will need to download and install the JavaFX Script. compiler and runtime. The easiest way to obtain this software is to download the entire JavaFX SDK, which gives you the NetBeans IDE (optional), compiler, runtime, and a number of other tools.

    Another way is to simply download the latest compiler binary from the openjfx project website. The compiler itself is written in the Java programming language; installing the precompiled binary therefore becomes a matter of extracting the downloaded file and adding the javafxc and javafx tools to your path. The complete set of instructions for this approach can be found on the PlanetJFX Wiki.

    Finally — if you want to live on the bleeding edge — you can join the OpenJFX Compiler Project, create your own copy of the compiler workspace, and build everything yourself from the compiler source files. (If you choose this approach, you will also need the 1.7.0 version of Apache Ant, plus a recent copy of Mercurial).

    If you have chosen NetBeans IDE 6.5.1 as your development environment, you can use the following instructions to create a project for your first script. a simple calculator.

    Step 1: Create a New Project

    Launch the NetBeans IDE 6.5.1 and choose File | New Project.

    When the new project wizard appears, choose JavaFX as the category and press Next to continue.

    This image has been scaled down to fit your screen. Click to enlarge.
     

    Step 2: Choose a Project Name and Location

    Next, type "Calculator" as the project name. The NetBeans IDE will provide a default location on your system for this project. You can keep this suggestion, or specify a new one. Make sure that "Empty Project" and "Set as Main Project" are selected, but do not check the "Create Main File" checkbox. Press the "Finish" button when done.

    This image has been scaled down to fit your screen. Click to enlarge.
     

    Step 3: Add a Source File to the Project

    The left side of the IDE contains a file browser window as shown below. You can see that the Calculator project exists, but currently has no source files:

     

    To add a source file to the project, choose File | New File. Select JavaFX as the category and Empty JavaFX File as the file type:

    This image has been scaled down to fit your screen. Click to enlarge.
     

    Next, type "Calculator" as the file name, but leave the package selection empty. You will see a package warning at the bottom of the screen, but ignore this for now; throughout most of this tutorial, we will be placing code into the default package. Press the "Finish" button when done.

    This image has been scaled down to fit your screen. Click to enlarge.
     

    Step 4: Paste Source Code, Compile, and Run the Application!

    The file browser now shows Caclulator.fx as part of the the default package. The source code editor (right hand pane) now contains some default code, which you can safely erase:

    This image has been scaled down to fit your screen. Click to enlarge.
     

    In its place, paste in the contents of calculator.fx. Certain keywords are now highlighted, showing that the editor now recognizes the syntax of the JavaFX Script. programming language:

    This image has been scaled down to fit your screen. Click to enlarge.
     

    Now look for these buttons along the top of the screen:

    This image has been scaled down to fit your screen. Click to enlarge.
     

    Press the green button in the center to compile and run the application:

    This image has been scaled down to fit your screen. Click to enlarge.
     

    You should see output similar to the above. If so, then congratulations, your project works!

    If you will be working from the command line only, save calculator.fx to a directory of your choice. Assuming that the JDK and JavaFX SDK are already installed and in your path, you should be able to compile this program with the following command:

    javafxc calculator.fx
    
     

    After compilation, you will find that the corresponding Java bytecode has been generated and placed into a file named calculator.class. You might also notice that another file, calculator$Intf.class has been created. This supporting file is needed to run the application — you can ignore it, but don't delete it.

    You can now run the compiled class in the Java Virtual Machine with the following command:

    javafx calculator
    
     

    The output is:

    100 + 2 = 102
    100 - 2 = 98
    100 * 2 = 200
    100 / 2 = 50
    
     

    This application may be small, but it introduces you to some important programming language constructs (discussed in the next lesson). Learning these constructs is your first step towards mastering the JavaFX Script. programming language.

    (If you want to learn more, please pay attention to http://java.sun.com/javafx/1/tutorials/core/

  • JavaFx

    2009-05-26 13:37:48

    http://developers.sun.com.cn/javafx/index.jsp
Open Toolbar