Javafx application FAQs

Source: Internet
Author: User
FAQs

What is javafx?

"Javafx
Scripts are declarative and static programming languages. It has the first-class
Functions), declarative syntax, list-comprehensions, and dependency-Based Incremental evaluation (incremental)
Dependency-based
Evaluation) and other features ." The javafx script provides declarative and non-Intermediate Program Logic syntaxes for a variety of operations, including creating 2D animations, setting attributes, or declaring
The binding dependency between the mode and view object.

What kind of function can be called "first-class functions "?

In
In programming languages, we often call functions that take functions as first-class objects
Functions ). Specifically, the programming language supports constructing new functions during program execution, storing them in the data structure as input parameters of other functions, and returning
Return them as function values. This concept does not cover external functions or programs of any language or program, such as creating a function by calling a compiler or an eval function.
Here is a simple example of a first-class function: map or mapcar function, which uses a function and a list as parameters, then, the list formed by applying the function to each member in the list is returned.

What does "declarative Syntax" mean?

Unlike most programming languages that rely on programs and explicit Code to update the relationship between variables or attributes, declarative languages allow the value to be declared as another method.
An example of javafx:

var a : Number = bind model.attrib/2;

Whenever the value of Model. attrib changes, the value of a is automatically and transparently updated, and no program is called during the update. This is particularly useful for binding dependencies between mode and view objects and controlling GUI behavior.

What does "list-comprehensions" mean?

We often translate "list-comprehensions" into "list Derivation ". List derivation supports creating and maintaining lists in multiple ways at the language level.
Some examples in javafx:

var nums = [1,2,3,4]; 
var nums2 = [1..4]; //same as above
var numsGreaterThanTwo = nums[. > 2];
var numsLessThanFour = select n from n in nums where n < 4;

What is "incremental dependency-based evaluation "?

"Incremental
Dependency-based
Incremental Evaluation Based on dependency ". In javafx, attribute values can be declared as expressions that depend on (bound to) other attributes. In this way, when
When the referenced attribute values change, all attributes dependent on this attribute change their values directly or indirectly. This process does not need to call any intermediate program logic. This is similar to workbooks in Excel.
Using equations is similar.
This is useful for GUI development that requires dynamic maintenance mode and view attributes and often requires complex program logic.

"Operation" vs "function )"

The difference between a function and an operation is that a function can repeatedly evaluate values, bind return values, bind parameters, bind variables/attributes, and implicitly bind local variables.
For further instructions, see the following javafx code snippet:

Class Foo (
   attribute zap;
   function bar(x) { x + zap }
}
var afoo = Foo { zap: 14 }
var zing = 1;
var snap = afoo.bar(zing);
bind dyn = afoo.bar(zing);

We can clearly see that no matter how Zing and zap change, snap will not change. However, dyn changes with Zing and zap. Because the Zing and zap values change, an incremental evaluation process occurs: The program passes the changed values to all functions dependent on them and recalculates the values.

What is the javafx authorization mode?

Javafx
Developers agree to allow users to publish their own applications and firmly believe in the power of open source and community. However, the current javafx version is released under evaluation authorization, so it cannot be released again. Of course you can publish
Javafx-based applications compiled by myself cannot be bundled and released together with javafx. Users must download the javafx binary code at the openjfx project site.
Library. In addition, because the early javafx code is still under evaluation authorization, it cannot be used for commercial purposes. After Sun completes the commercial development of javafx, I believe this will
To change.

Does sun specify the time line for publishing javafx commercial products?

Sorry, there is no accurate time agreement, but it will be formulated immediately.

Is javafx runtime as open-source as javafx script?

Yes, javafx Runtime is about to open source code.

In javafx and... Between

Comparison with F3:F3 is the abbreviation of Form follows function, which is the former name of javafx platform.

Comparison with Java:Javafx is a scripting language compatible with JSR-223. It can use Java classes and be called from Java classes.

Compared with scriting engine provided by Java 6.0:Java
The scriting engine provided by 6.0 provides a runtime platform for JSR-223-compatible scripting languages, javafx can be used in Java
6.0 run on the scriting engine provided. While javafx does not depend on Java
6.0, which can be executed in any script engine compatible with the JSR-223, such as javax. Script. scriptengine.

Comparison with SVG:SVG
It is not a programming language; it is a data description language. Its XML syntax is terrible for programming languages. However, the interaction and compatibility of SVG are satisfactory. Currently, javafx Development Group
The team did not plan to directly use SVG. Because SVG and javafx both source from the old PostScript and java2d vector graphics modes, to some extent, we already
SVG is used in javafx, but some notable incompatibility still exists.
Chris Oliver has compiled the SVG-to-F3 converter.

Comparison with swing:Javafx is a new way to write swing applications without having to understand the swing framework and Java language.

Comparison with javascript:The only difference between javafx and JavaScript is that they are all JSR-223-compatible scripting languages.

Comparison with Ajax:Ajax is a Web browser technology that uses JavaScript and asynchronous updates. Its relationship with javafx: both are UI-related technologies. But they are completely different in language and environment.

Relationship with savaje OS:Sun is planning to use the saveje mobile system they purchased and the JVM to release javafx Mobile, which can run the javafx script on mobile devices and will become a strong competitor of Windows Mobile and Flash Lite.

Can I use javafx to write Java3D applications? Is it compatible with libraries such as the X3D standard and xj3d standard?

It cannot be used for no reason. Javafx can interoperate with any third-party code library without any special syntax. Currently, the javafx development team is developing a function supporting Java3D.

Is javafx a rcp (rich client platform?

Yes. Javafx can be used not only for RCP development, but also for RIA (rich Internet applications) development.

Can I use javafx in Web applications?

Javafx can be used to compile front-end applications, web application views, or user interfaces. However, this requires JVM support.

Will javafx replace JSF and JSP in Java ee?

No, JSF
And JSP are used to compile pure Web applications (available for HTTP clients that support html), while javafx needs to be located in the client JVM. If you want to write rich client
Then you need to install JRE on the client. javafx can provide the same features as flash-based flex and. Net-based Silverlight. Common application scenarios
Is to develop applications running on the company's intranet.

Does javafx require a server?

Javafx is a scripting language that focuses on the GUI. It is mainly used for desktop applications and therefore does not require servers. If you plan to deploy JNLP (Java Web Start), you need a web server.

What are the conditions required to run javafx?

Either of the two conditions:
Java 5 or above, a compatible JSR-223 implementation, javafx code library;
Java 6 or above and javafx code base.

Is there a available javafx compiler?

Openfx compiler is a javafx compiler project and is currently open source code.
For details, visit: https://openjfx-compiler.dev.java.net/

Problems encountered during development

What are the inherent Data Types in javafx?

Inherent Data Types in javafx: String, Boolean, number, and integer.

Ing between javafx and Java types:

For more information, visit:
Https://openjfx.dev.java.net/JavaFX_Programming_Language.html#basic_types

How to connect two strings? The "+" operator does not work anymore !?

Unlike Java, javafx does not overload the "+" operator to use it for string connection:

import javafx.ui.*;
import javafx.ui.canvas.*;
        
Frame {
    content: Label {
        text: "Hello " + "World"
    }
    visible: true
}

If you try to run the above Code, we will see the following console output:

compile thread: Thread[AWT-EventQueue-0,6,main]
compile 2.031
file:/C:/workspace/F3/HelloWorld.fx:6: incompatible types: expected Number, found String in "Hello "
file:/C:/workspace/F3/HelloWorld.fx:6: incompatible types: expected Number, found String in "World"
file:/C:/workspace/F3/HelloWorld.fx:6: incompatible types: expected String, found Number in text: "Hello " + "World"

Implementation Method: modify the code

Java implementation method:

String s = "Your score is " + n + " out of " + total + ".";

The string expression operator {} of javafx concatenates strings:

var s:String = "Your score is {n} out of {total}.";

Implementation Method 2: Call the Concat () method

Javafx provides the Concat () method to connect two strings:

import javafx.ui.*;
import javafx.ui.canvas.*;
        
Frame {
    content: Label {
        text: "Hello ".concat("World")
    }
    visible: true
}

How do I convert a string to a number?

There is no direct method, but the following code can be used:

var value = new DecimalFormat("0").parse(someString);

How can I bind a textfield value to a numeric attribute?

BIND ::

var total = 10
TextField {
   value: bind total
   ...
}

You can also use format for formatting:

value: bind "{total format as <<#,##0>>}"

How to Set javafx for Java Web Start?

JNLP (Java Network Launch Protocol) is an XML-based protocol that can deploy Java and javafx applications on the network.
A JNLP example for deploying javafxpad is provided here.
For detailed examples, see: http://download.java.net/general/openjfx/demos/javafxpad.jnlp ).

<?xml version="1.0" encoding="utf-8"?>
<jnlp
        spec="1.5+"
        codebase="http://download.java.net/general/openjfx/demos"
        href="javafxpad.jnlp">
  <information>
    <title>JavaFX Demos:JavaFX Pad</title>
    <vendor>Sun Microsystems</vendor>
    <offline-allowed />
  </information>
  <security>
  <all-permissions/>  
  </security>
  
  <resources>
    <j2se version="1.5+" href="http://java.sun.com/products/autodl/j2se"
        java-vm-args="-Xss1M -Xmx256M"
        >
    </j2se>
    <jar href="javafxrt.jar" main="true"/>
    <jar href="Filters.jar"/>
    <jar href="swing-layout.jar"/>
    <jar href="javafxpad.jar"/>
  </resources>
  <application-desc main-class="net.java.javafx.FXShell">
  <argument>javafxpad.Main</argument>
  </application-desc>
</jnlp>

"Hello Web Start FX" Example

Environment requirements
• Java 5 JDK
•/Lib/javafxrt. jar and LIB/swing-layout.jar extracted from the javafx code package downloaded from the openjfx Project

"Hello Web Start jfx" program code

File Name: hellowebstart. FX

import javafx.ui.*;

Frame {
    title  : 'Hello Web Start JFX!'
    width  : 600
    height : 400
    
    content: Label {
        text: 'Hello Web Start JFX!'
        font: Font{size: 32}
    }
      
    visible: true
}

Create hellowebstartjfx. Jar

jar cvf HelloWebStartJFX.jar HelloWebStart.fx

Create hellowebstartjfx. JNLP

File Name: hellowebstartjfx. JNLP

<?xml version="1.0" encoding="utf-8"?>
<jnlp spec="1.5+"
      codebase="http://www.example.com/HelloWebStartJFX/"
      href="HelloWebStartJFX.jnlp">
  
    <information>
    <title>Hello Web Start JFX</title>
        <vendor>John Doe</vendor>
                <description>Web Start example for JavaFX Scripts</description>
        <offline-allowed/>
    </information>

    <security>
        <all-permissions/>
    </security>

    <resources>
        <j2se version="1.5+" href="http://java.sun.com/products/autodl/j2se">
        </j2se>

        <jar href="javafxrt.jar" main="true"/>
        <jar href="swing-layout.jar"/>
        <jar href="HelloWebStartJFX.jar"/>          
    </resources>
    
    <application-desc main-class="net.java.javafx.FXShell">
        <argument>HelloWebStart</argument>
    </application-desc>
</jnlp>

Create a signature key

keytool -genkey -alias jfx -dname "CN=John Doe, O=JFX Inc." -validity 9999 -keystore jfx.keystore -keypass keyPassword -storepass storePassword

Sign the JAR File

jarsigner -keystore jfx.keystore -verbose -keypass keyPassword -storepass storePassword HelloWebStartJFX.jar jfx
jarsigner -keystore jfx.keystore -verbose -keypass keyPassword -storepass storePassword javafxrt.jar jfx
jarsigner -keystore jfx.keystore -verbose -keypass keyPassword -storepass storePassword swing-layout.jar jfx

Connect to hellowebstartjfx. JNLP

File Name: index.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Hello Web Start JFX!</title>
    
  <body>  
      
    <p><a href="HelloWebStartJFX.jnlp">Java Web Start: Hello Web Start JFX!</a></p>
  </body>

Web server: Set the MIME type for. JNLP

Apache server: add the type to the HTTP. conf or. htaccess file:

application/x-java-jnlp-file JNLP

Copy files to the Web server

mkdir /www/www.example.com/docs/HelloWebStartJFX/
cp index.html HelloWebStartJFX.jnlp HelloWebStartJFX.jar javafxrt.jar swing-layout.jar /www/www.example.com/docs/HelloWebStartJFX/

Start Web Start

Use www.example.com/hellowebstartjfx/to start Web Start.

How can I reference a Java class with a "fully qualified name?

Fully Qualified Java class names must be enclosed in French quotes <>.

How to access internal classes and interfaces?

When accessing internal classes and interfaces, you can only use the internal class compilation name.
For example:
In Java, import java. util. Map. Entry is represented as import java. util. Map $ entry in javafx.

In javafx, you must note that when referencing internal classes, you must continue to use the outer $ inner syntax. For ease of use, you can also change the Import Statement:

import java.util.Map$Entry as Entry

In this way, you do not have to repeatedly use the outer $ inner form.
Can I use Java 5 enumeration (enumerations?
Of course. You can reference them as follows:

Import java. util. Management. memorytype; // import Enumeration

VaR value = heap: memorytype; // use the enumerated Value
// Heap is the enumerated value in memorytype.

VaR allvalues = memorytype. Values (); // create a javafx array containing all enumerated values

How can I easily customize swing components in javafx?

Here we provide some code to quickly encapsulate the swing component, which can be used in the javafx Component layer:

Swingwidget class definition:

File Name: swingwidget. FX

package a.b.c;

import javafx.ui.*;
import javax.swing.JComponent;

class SwingWidget extends Widget {
       attribute swingComponent: JComponent;
}

operation SwingWidget.createComponent():<<javax.swing.JComponent>> {
    return swingComponent;
}

Usage:

The following provides a simple example of using swingwidget. Note that the data provided in the tree list comes from the default tree model, rather than the javafx.
File Name: widgettest. FX

package a.b.c;

import javafx.ui.*;
import javafx.ui.canvas.*;
import java.lang.System;
import javax.swing.JTree;
import a.b.c.SwingWidget;

Frame {
       onClose: operation() {
               System.exit(0);
       }
       content: SwingWidget {
               swingComponent: new JTree()
       }
       visible: true
       title: "WTF, the Widget Test Framework"
}

Running interface:

Why cannot some of my. FX files be reloaded by the javafx pad?

Sorry to tell you That javafxpad currently has very limited functions. It cannot detect changes to external files. To make it "visible", You need to manually re-open the modified file in javafxpad.

How to reference other javafx files?

Javafx can reference static values, variables, and classes from the following three resources:
1. In the same file
2. Files in the same directory/package path
3. Files in other package paths

First, the first method is very simple. If you are referencing a class in the same file, you only need to use the class name (the class can be defined before or after the reference ). Variables can be referenced only after they are declared.

For the second method, it is obvious that you do not need to use the import statement for each. FX file in the same package path, but only need to provide the import statement with the same package path where they are located.

For example
If you have other internal classes or you need to introduce classes from different package paths, you need to use the Import Statement to import the. FX file, instead
A specific class in this file. For example, if mediatable. FX contains two classes: mediatablecolumn and mediatablerow
The importing mediatable statement is required to import these two classes.

You can also use the import * statement like Java. But this method reduces the readability of the code, so it is not recommended to everyone.

Does the javafx script provide magic constants like _ line _ (MAGIC constants?

Magic constant

• _ DIR _ -- return the URL of the directory containing the current FX source file. If the current file is loaded from the jar file, the returned value may be the URL of the JAR file.
• _ File _ -- returns the URL of the current source file.
• _ Line _ -- returns the current row in the current source file.
• _ ARCHIVE _ -- return the URL of the JAR file containing the current file.

Example

import javafx.ui.*;
                
Frame {
    title  : 'Magic Constants'
    width  : 700
    height : 400
    content: Label {text: "                           <dt>__DOCBASE__</dt><dd>{__DOCBASE__}</dd>
                           <dt>__DIR__</dt>    <dd>{__DIR__}</dd>
                           <dt>__FILE__</dt>   <dd>{__FILE__}</dd>
                           <dt>__LINE__</dt>   <dd>{__LINE__}</dd>
                           <dt>__ARCHIVE__</dt><dd>{__ARCHIVE__}</dd>
                           </dl>      
    visible: true
}// Frame

More information

• "Magic constants" written by Christopher Oliver"

What are reserved words in javafx?

After
And
As
Assert
Attribute
Before
Bind
Break
By
Catch
Class
Continue
Delete
Distinct
Do
Dur
Easeboth
Easein
Easeout
Else
Endif
Extends
False
Finally
First
For
Foreach
Format
FPS
From
Function
If
Import
In
Index
Indexof
Insert
Instanceof
Into
Inverse
Last
Later
Lazy
Linear
Motion
Nodebug
New
Not
Null
On
Operation
Or
Order
Package
Private
Protected
Public
Readonly
Return
Reverse
Select
Sizeof
Super
Then
This
Throw (note that it is not throws)
Trigger
True
Try
Typeof
Unitinterval
Valueof
VaR
Where
While
XOR

From: http://www.matrix.org.cn/resource/article/2007-09-24/e50bf5af-6a56-11dc-91f8-0da64dffe568.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.