As Oracle says, JavaFX is the future - I hope soon as possible, cause I am really happy with what I am seeing.
Take a look at http://www.oracle.com/us/technologies/java/fx/overview/index.html
I decided to download this tool JavaFX Scene Builder 1.0 to help me out with the FXML .
http://www.oracle.com/technetwork/java/javafx/downloads/index.html
and build 2 fxml files:
LMLFrameFX.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?language javascript?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.chart.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.paint.*?>
<?scenebuilder-background-color 0xdfdfdfff?>
<AnchorPane id="AnchorPane"
maxHeight="-Infinity" maxWidth="-Infinity"
minHeight="-Infinity" minWidth="-Infinity"
prefHeight="400.0" prefWidth="600.0"
xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2"
fx:controller="FXController"
>
<children>
<Button layoutX="22.0" layoutY="355.0"
mnemonicParsing="false" prefHeight="31.0" prefWidth="158.0"
text="click here"
onAction="java.lang.System.out.println('You clicked me!');"
/>
<Button layoutX="222.0" layoutY="355.0"
mnemonicParsing="false" prefHeight="31.0" prefWidth="158.0"
text="click here"
/>
<Accordion expandedPane="$null" layoutX="331.0" layoutY="14.0" prefHeight="324.0" />
<Accordion layoutX="396.0" layoutY="22.0" prefHeight="378.0">
<expandedPane>
<TitledPane fx:id="x1" animated="false" text="untitled">
<content>
<AnchorPane id="Content" minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" />
</content>
</TitledPane>
</expandedPane>
<panes>
<TitledPane animated="false" text="untitled">
<content>
<AnchorPane id="Content" minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
<children>
<Slider layoutX="0.0" layoutY="33.0" orientation="VERTICAL" prefWidth="69.0" />
<Slider layoutX="69.0" layoutY="33.0" orientation="VERTICAL" prefWidth="69.0" />
<Slider layoutX="132.0" layoutY="33.0" orientation="VERTICAL" prefWidth="69.0" />
</children>
</AnchorPane>
</content>
</TitledPane>
<fx:reference source="x1" />
</panes>
</Accordion>
<MenuBar layoutX="0.0" layoutY="0.0"
opacity="0.6" prefWidth="600.0"
>
<menus>
<Menu mnemonicParsing="false" text="File">
<items>
<MenuItem mnemonicParsing="false" text="Close" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Help">
<items>
<MenuItem mnemonicParsing="false" text="About" />
</items>
</Menu>
</menus>
</MenuBar>
<BarChart layoutX="0.0" layoutY="33.0" prefHeight="300.0" prefWidth="396.0">
<xAxis>
<CategoryAxis side="BOTTOM" />
</xAxis>
<yAxis>
<NumberAxis side="LEFT" />
</yAxis>
</BarChart>
</children>
</AnchorPane>
TestFrameFX.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?language javascript?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.chart.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.paint.*?>
<?import javafx.scene.control.Label?>
<?scenebuilder-background-color 0xdfdfdfff?>
<StackPane prefHeight="150.0" prefWidth="200.0"
xmlns:fx="http://javafx.com/fxml"
fx:controller="FXController"
>
<children>
<Button fx:id="myButton" mnemonicParsing="false" text="Button" onAction="#handleButtonAction" />
</children>
</StackPane>
and 2 classes
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class FxmlLoaderLML extends Application {
public static void main(String[] args) {
Application.launch(FxmlLoaderLML.class, args);
//launch(args);
}
@Override
public void start(Stage stage) throws Exception {
System.out.println("resourse fxml:" + this.getClass().getResource("LMLFrameFX.fxml").getFile());
/* FRAME 1 LMLFrameFX.fxml */
Parent root = FXMLLoader.load( this.getClass().getResource("LMLFrameFX.fxml") );
stage.setTitle("FXML LOADER");
stage.setScene(new Scene(root, 600, 400));
stage.show();
/* FRAME 2 TestFrameFX.fxml*/
Parent root2 = FXMLLoader.load( this.getClass().getResource("TestFrameFX.fxml") );
Stage s2 = new Stage();
s2.setTitle("FXML LOADER");
s2.setScene(new Scene(root2, 300, 100));
s2.show();
}
}
import javafx.event.*;
public class FXController {
public void handleButtonAction(ActionEvent event) {
System.out.println("FXController says : clicked!");
}
}
Then I develop and test this simple "HelloWorldProject" on Eclipse 4.2.2 64bits , NetBeans 7.3.1 and calling strait from DOS Console using a little bat file like:
set classpath=..\JavaFXSceneBuilder1.1\runtime\jre\bin;..\JavaFXSceneBuilder1.1\runtime\jre\lib;..\javafx\bin;..\JavaFXSceneBuilder1.1\runtime\jre\lib\jfxrt.jar;
set path=%path%;%classpath%
java -cp %classpath% HelloWorld
but of course, the moderns IDE are easier
so let's see the Eclipse graphinterface here..
As you can see here, you must to use java 7
in my case
java version "1.7.0_25"
Java(TM) SE Runtime Environment (build 1.7.0_25-b17)
Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode)
Those are the links that help me out.
http://docs.oracle.com/javafx/2/get_started/FXMLExample.java.html
https://blogs.oracle.com/jmxetc/entry/connecting_scenebuilder_edited_fxml_to
http://docs.oracle.com/javafx/2/api/javafx/fxml/doc-files/introduction_to_fxml.html#fxml_annotation
http://docs.oracle.com/javafx/2/get_started/basic_deployment.htm
No comments:
Post a Comment