美化多系统启动选择菜单burg:在deepin 2013&& ubuntu14.04 上安装测试过,完全可用。

时间:2014-04-27 22:48:45   收藏:0   阅读:458

一、特性一览

javafx8发布有一段时间了,今天闲来看看。javafx主要致力于富客户端开发,以弥补swing的缺陷,主要提供图形库与media库,支持audio,vedio,graphics,animation,3D等,同时采用现代化的css方式支持界面设计。同时又采用XUI方式以XML方式设计UI界面,达到显示与逻辑的分离。与android这方面确实有点相似性。

javafx体系结构:

mamicode.com,码迷

javafx特性

二、体系结构

javafx Sene Graph

javafx采用SceneGraph作为application的入口及用户接口,用户向用户展示界面,处理用户交互如input和render渲染。SceneGraph采取tree node的形式组织界面。
每一个node拥有id,style,bound.每个节点还拥有
Effects, such as blurs and shadows
Opacity Transforms Event handlers (such as mouse, key and input method)An application-specific state
scene graph包含
  • Nodes: Shapes (2-D and 3-D), images, media, embedded web browser, text, UI controls, charts, groups, and containers 
  • State: Transforms (positioning and orientation of nodes), visual effects, and other visual state of the content
  •  Effects: Simple objects that change the appearance of scene graph nodes, such as blurs, shadows, and color adjustment
可见scene graph是将layout与ui控件及容器都作为node节点。

Glass Windowing Toolkit

Glass Windowing Toolkit是一个平台相关的工具库,是比较底层的,它负责管理 windows, timers, and surfaces。同时它还负责event queue,这个Even queue不同与Swing总的EDT,javafx中event queue是在javafx application thread中而非在单独的线程中。
关于线程需要注意几点:
  • javafx application thread:javafx的主线程。它不同于Swing中的EDT要注意着一点。同时在scene graph中只要子元素子node没有被挂载到root根节点我们就可以在单独的线程中绘制node,然后再在javafx application thread中将这些绘制好的子node挂载到root下,这样就可以提高绘制效率。
  • Prism render thread:渲染线程是一个底层对于程序员透明的一个线程负责渲染,同时优化了再多核处理器下的工作能力,可以执行并发渲染。
  • Media Thread:多媒体线程是一个单独的后台线程,通过application thread可以与scene graph同步。
Puls
Puls是一个与Glass Window Toolkit相关的事件调度器,用于同步scene graph中元素的状态与prism的渲染。
而Glass Window Toolkit负责管理Puls

Media and Imaging

Media:javafx支持的格式MP3,FLV,WAV等。
三个主要组件Media,MediaPlayer, MediaView

Web Component:

javafx WebEngine基于webkit,提供了完整的浏览器功能。同时支持:CSS,HTML5.JavaScript,SVG,DOM等
主要能力:
  • 1.冲本地或远程url加载渲染html页面
  • 2.历史查看与前进后退
  • 3.刷新,reload
  • 4.web组件效果
  • 5.编辑HTML内容,执行js脚本,处理events,操作dom
  • 主要类:WebEngine, WebView(WebView是一个node,同时它封装了WebEngine。)

CSS

javafx中CSS可以应用于任意node节点。运行程序动态异步地改变组件的外观 javafx内置的样式以"-fx-"开头

Control

Control即javafx中的UI控件

Layout

javafx中layout也是作为scene graph中的Node而存在的,主要有如下几类: BorderPane HBox,VBox StackPane GridPane FlowPane TilePane(对,你没看错,是TilePane而非TitlePane):TilePane使子node以一致性地大小排列 AnchorPane:The AnchorPane class enables developers to create anchor nodes to the top, bottom, left side, or center of the layout.

 2D and 3D

2D包:javafx.scene.tranform,主要基于x-y坐标 Translate,Scale,shear,rotate,以及affine – Perform a linear mapping from 2-D/3-D coordinates to other 2-D/3-D coordinates while preserving the ‘straight‘ and ‘parallel‘ properties of the lines. This class should be used with Translate, Scale, Rotate, or Shear transform classes instead of being used directly.

Visual Effect

Visual Effect基于image-pixed。主要类:DropShadowReflectionLighting  


 三、HelloWord解析

 

package helloworld;
 
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
 
public class HelloWorld extends Application {
    
    @Override
    public void start(Stage primaryStage) {
        Button btn = new Button();
        btn.setText("Say ‘Hello World‘");
        btn.setOnAction(new EventHandler<ActionEvent>() {
 
            @Override
            public void handle(ActionEvent event) {
                System.out.println("Hello World!");
            }
        });
        
        StackPane root = new StackPane();
        root.getChildren().add(btn);

 Scene scene new Scene(root, 300, 250);

        primaryStage.setTitle("Hello World!");
        primaryStage.setScene(scene);
        primaryStage.show();
    }
 public static void main(String[] args) {
        launch(args);
    }
}

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!