29

JavaFXで開く新世代GUI

Embed Size (px)

DESCRIPTION

第2回 岡山Javaユーザ会 勉強会 #okajug発表資料 「JavaFXで開く新世代GUI」

Citation preview

Page 1: JavaFXで開く新世代GUI
Page 2: JavaFXで開く新世代GUI
Page 3: JavaFXで開く新世代GUI
Page 4: JavaFXで開く新世代GUI

Structure

Page 5: JavaFXで開く新世代GUI

Structure

SceneGraph

Page 6: JavaFXで開く新世代GUI

GUI = TreeGUI = Tree

Page 7: JavaFXで開く新世代GUI

StageStage

StageStageSceneScene

SceneScene

VBoxVBox

VBoxVBox

HBoxHBox

HBoxHBox

TableViewTableView

TableViewTableView

LabelLabelTextBoxTextBoxButtonButton

Page 8: JavaFXで開く新世代GUI

public class Hello extends Application { @Override public void start(Stage stage) { // コンテナ Group container = new Group(); // シーングラフのルート要素を生成し、コンテナを貼る Scene scene = new Scene(container, 100, 20); stage.setScene(scene);

// ラベルを生成しコンテナに貼る Label label = new Label("Hello, World!"); container.getChildren().add(label); stage.setVisible(true); } public static void main(String[] args) { Application.launch(args); }}

public class Hello extends Application { @Override public void start(Stage stage) { // コンテナ Group container = new Group(); // シーングラフのルート要素を生成し、コンテナを貼る Scene scene = new Scene(container, 100, 20); stage.setScene(scene);

// ラベルを生成しコンテナに貼る Label label = new Label("Hello, World!"); container.getChildren().add(label); stage.setVisible(true); } public static void main(String[] args) { Application.launch(args); }}

public class Hello extends Application { @Override public void start(Stage stage) { // コンテナ Group container = new Group(); // シーングラフのルート要素を生成し、コンテナを貼る Scene scene = new Scene(container, 100, 20); stage.setScene(scene);

// ラベルを生成しコンテナに貼る Label label = new Label("Hello, World!"); container.getChildren().add(label); stage.setVisible(true); } public static void main(String[] args) { Application.launch(args); }}

public class Hello extends Application { @Override public void start(Stage stage) { // コンテナ Group container = new Group(); // シーングラフのルート要素を生成し、コンテナを貼る Scene scene = new Scene(container, 100, 20); stage.setScene(scene);

// ラベルを生成しコンテナに貼る Label label = new Label("Hello, World!"); container.getChildren().add(label); stage.show(); } public static void main(String[] args) { Application.launch(args); }}

SceneGraph

Page 9: JavaFXで開く新世代GUI

XML Script

FXMLGroovyFXGroovyFXScalaFXScalaFXVisageVisage

Page 10: JavaFXで開く新世代GUI

<VBox xmlns:fx="http://javafx.com/fxml" fx:controller="contents.browser2" spacing="10" layoutY="10"> <children> <HBox spacing="10" style="-fx-alignment: center"> <children> <TextField fx:id="field" prefWidth="200" onAction="#handleAction" /> <Button text="Load" onAction="#handleAction" /> </children> </HBox> <WebView fx:id="view" /> </children></VBox>

<VBox xmlns:fx="http://javafx.com/fxml" fx:controller="contents.browser2" spacing="10" layoutY="10"> <children> <HBox spacing="10" style="-fx-alignment: center"> <children> <TextField fx:id="field" prefWidth="200" onAction="#handleAction" /> <Button text="Load" onAction="#handleAction" /> </children> </HBox> <WebView fx:id="view" /> </children></VBox>

<VBox xmlns:fx="http://javafx.com/fxml" fx:controller="contents.browser2" spacing="10" layoutY="10"> <children> <HBox spacing="10" style="-fx-alignment: center"> <children> <TextField fx:id="field" prefWidth="200" onAction="#handleAction" /> <Button text="Load" onAction="#handleAction" /> </children> </HBox> <WebView fx:id="view" /> </children></VBox>

Page 11: JavaFXで開く新世代GUI

<VBox xmlns:fx="http://javafx.com/fxml" fx:controller="contents.browser2" spacing="10" layoutY="10"> <children> <HBox spacing="10" style="-fx-alignment: center"> <children> <TextField fx:id="field" prefWidth="200" onAction="#handleAction" /> <Button text="Load" onAction="#handleAction" /> </children> </HBox> <WebView fx:id="view" /> </children></VBox>

<VBox xmlns:fx="http://javafx.com/fxml" fx:controller="contents.browser2" spacing="10" layoutY="10"> <children> <HBox spacing="10" style="-fx-alignment: center"> <children> <TextField fx:id="field" prefWidth="200" onAction="#handleAction" /> <Button text="Load" onAction="#handleAction" /> </children> </HBox> <WebView fx:id="view" /> </children></VBox>

<VBox xmlns:fx="http://javafx.com/fxml" fx:controller="contents.browser2" spacing="10" layoutY="10"> <children> <HBox spacing="10" style="-fx-alignment: center"> <children> <TextField fx:id="field" prefWidth="200" onAction="#handleAction" /> <Button text="Load" onAction="#handleAction" /> </children> </HBox> <WebView fx:id="view" /> </children></VBox>

Model

View

Controller

FXML

Java

Java

Page 12: JavaFXで開く新世代GUI

<VBox xmlns:fx="http://javafx.com/fxml" fx:controller="contents.browser2" spacing="10" layoutY="10"> <children> <HBox spacing="10" style="-fx-alignment: center"> <children> <TextField fx:id="field" prefWidth="200" onAction="#handleAction" /> <Button text="Load" onAction="#handleAction" /> </children> </HBox> <WebView fx:id="view" /> </children></VBox>

<VBox xmlns:fx="http://javafx.com/fxml" fx:controller="contents.browser2" spacing="10" layoutY="10"> <children> <HBox spacing="10" style="-fx-alignment: center"> <children> <TextField fx:id="field" prefWidth="200" onAction="#handleAction" /> <Button text="Load" onAction="#handleAction" /> </children> </HBox> <WebView fx:id="view" /> </children></VBox>

<VBox xmlns:fx="http://javafx.com/fxml" fx:controller="contents.browser2" spacing="10" layoutY="10"> <children> <HBox spacing="10" style="-fx-alignment: center"> <children> <TextField fx:id="field" prefWidth="200" onAction="#handleAction" /> <Button text="Load" onAction="#handleAction" /> </children> </HBox> <WebView fx:id="view" /> </children></VBox>

Model

View

Controller

FXML

Java

Java

public class browser2 { @FXML private TextField field; @FXML private WebView view; private WebEngine engine;

@FXML private void handleAction(ActionEvent event) { String url = field.getText(); engine.load(url); }}

public class browser2 { @FXML private TextField field; @FXML private WebView view; private WebEngine engine;

@FXML private void handleAction(ActionEvent event) { String url = field.getText(); engine.load(url); }}

<VBox xmlns:fx="http://javafx.com/fxml" fx:controller="contents.browser2" spacing="10" layoutY="10"> <children> <HBox spacing="10" style="-fx-alignment: center"> <children> <TextField fx:id="field" prefWidth="200" onAction="#handleAction" /> <Button text="Load" onAction="#handleAction" /> </children> </HBox> <WebView fx:id="view" /> </children></VBox>

Page 13: JavaFXで開く新世代GUI

Contents

Page 14: JavaFXで開く新世代GUI

Contents

Node

Control

Container Shape

Page 15: JavaFXで開く新世代GUI

Web/HTML Media

Page 16: JavaFXで開く新世代GUI

Web/HTML

Page 17: JavaFXで開く新世代GUI

Web/HTML

Page 18: JavaFXで開く新世代GUI

Web/HTMLMedia

Media media = new Media(url);MediaPlayer player = new MediaPlayer(media);MediaView view = new MediaView(player);

player.play();

Page 19: JavaFXで開く新世代GUI

Animation

自動補完

Page 20: JavaFXで開く新世代GUI

Animation

自動補完

Page 21: JavaFXで開く新世代GUI

Animation

Page 22: JavaFXで開く新世代GUI

Animation

Page 23: JavaFXで開く新世代GUI

Effect

Node image = ...;GaussianBlur blur = new GaussianBlur();blur.setRadius(10.0);image.setEffect(blur);

Node image = ...;DropShadow shdw= new DropShadow();shdw.setOffsetX(5); shdw.setOffsetY(5);image.setEffect(shdw);

Node image = ...;image.setEffect(new Reflection());

Node image = ...;image.setEffect(new SepiaTone());

Page 24: JavaFXで開く新世代GUI

Contents Design

CSS

Page 25: JavaFXで開く新世代GUI

CSS

Scene scene = new Scene(container, 400, 100);// スタイルシートの設定scene.getStylesheets().add("/style.css");

.button { -fx-font: 24pt "SansSerif"; -fx-text-fill: #006666; -fx-background-color: orange; -fx-border-radius: 20; -fx-background-radius: 20; -fx-padding: 5;}

.button { -fx-font: 16pt "SansSerif"; -fx-text-fill: #00FF33; -fx-background-color: #0066FF; -fx-border-radius: 0; -fx-background-radius: 0; -fx-padding: 20;}

Page 26: JavaFXで開く新世代GUI

CSS

Scene scene = new Scene(container, 400, 100);// スタイルシートの設定scene.getStylesheets().add("/style.css");

.button { -fx-font: 24pt "SansSerif"; -fx-text-fill: #006666; -fx-background-color: orange; -fx-border-radius: 20; -fx-background-radius: 20; -fx-padding: 5;}

.button { -fx-font: 16pt "SansSerif"; -fx-text-fill: #00FF33; -fx-background-color: #0066FF; -fx-border-radius: 0; -fx-background-radius: 0; -fx-padding: 20;}

Page 27: JavaFXで開く新世代GUI

Structure

Contents Design

ToolLogic

Design SceneBuilder

Page 28: JavaFXで開く新世代GUI

ConclusionConclusion

JavaFXJavaFXStructureStructure

ContentsContents

DesignDesign

ToolTool

Page 29: JavaFXで開く新世代GUI

で開くで開く

新世代 新世代 GUIGUI