JavaFx入门的一些事

来源:互联网 发布:淘宝介入怎么撤销 编辑:程序博客网 时间:2024/05/13 07:15

毕业设计想做一个客户端,但是天生畏惧C++,同时觉得java自带的swing有点丑,

所以挑了一个JavaFx学学,二话不说上网址:


1.工具

一些JavaFX的工具和插件

http://www.oracle.com/technetwork/cn/java/javafx/tools/index.html


 JavaFX Scene Builder1.1 的下载地址: 

http://www.oracle.com/technetwork/java/javase/downloads/javafxscenebuilder-1x-archive-2199384.html#javafx-scenebuilder-1.1-oth-JPR   


 JavaFX Scene Builder 2.0 下载地址

http://www.oracle.com/technetwork/java/javase/downloads/sb2download-2177776.html





2.入门

FXML入门

http://www.xuebuyuan.com/1902533.html

http://blog.csdn.net/pengpeng2395/article/details/7920968


 使用eclipse和JavaFX Scene Builder进行快速构建JavaFX应用程序

http://blog.csdn.net/wingfourever/article/details/7726724


使用 JavaFX 2.0 FXML 呈现企业级应用程序 UI

http://www.oracle.com/technetwork/cn/articles/java/expressfx-1665720-zhs.html


 JavaFx的第一次探索

http://bbs.jeefx.com/thread-14-1-1.html



3.文档

Efxclipse的文档

http://wiki.eclipse.org/Efxclipse/Tutorials


api等

http://docs.oracle.com/javase/8/javase-books.htm

http://docs.oracle.com/javase/8/javafx/api/toc.htm

常用组件

http://www.java2s.com/Code/Java/JavaFX/CatalogJavaFX.htm








代码1.在舞台上建立一个场景,场景以vbox为根

public class Main extends Application {Label label;Button btn = new Button("点击");@Overridepublic void start(Stage primaryStage) {VBox vbox1 = new VBox();label = new Label("呵呵");    btn.setOnAction(new javafx.event.EventHandler<ActionEvent>() {@Overridepublic void handle(ActionEvent event) {label.setText("变哈哈");}});        //vbox1.getChildren().add(label);    vbox1.getChildren().addAll(label,btn);    //场景以vobx1为根    Scene scene = new Scene(vbox1, 400, 400);//舞台使用这个场景    primaryStage.setScene(scene);primaryStage.show();}public static void main(String[] args) {launch(args);}}



代码2. 用Scene Builder拖好一个界面,保存为fxml文件,保存到类所在的包路径下,然后写代码加载该布局


public class Main extends Application {@Overridepublic void start(Stage primaryStage) throws Exception {    //加载fxml布局文件 (fxml放在Main类所在的同一个目录)Parent root = FXMLLoader.load( getClass().getResource("simpletab.fxml") );  //创建场景Scene scene = new Scene(root,800,600);scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());//舞台加载场景//primaryStage.setScene( SceneBuilder.create().root(root).build());primaryStage.setTitle("标题");primaryStage.setScene(scene);primaryStage.show();}public static void main(String[] args) {launch(Main.class,args);}}


其中的simpletab.fxml的代码是Scene Builder生成的
<?xml version="1.0" encoding="UTF-8"?><?import java.lang.*?><?import java.util.*?><?import javafx.scene.control.*?><?import javafx.scene.layout.*?><?import javafx.scene.paint.*?><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">  <children>    <TabPane minHeight="-1.0" minWidth="-1.0" prefHeight="200.0" prefWidth="200.0" tabClosingPolicy="UNAVAILABLE" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">      <tabs>        <Tab text="无标题选项卡 1">          <content>            <AnchorPane id="Content" minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" />          </content>        </Tab>        <Tab text="无标题选项卡 2">          <content>            <AnchorPane id="Content" minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" />          </content>        </Tab>        <Tab text="无标题选项卡">          <content>            <AnchorPane id="Content" minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" />          </content>        </Tab>      </tabs>    </TabPane>  </children></AnchorPane>



3.





0 0