SlideShare a Scribd company logo
JCD 2012 JavaFX 2
美觀、快速與流暢的Java用戶端應用程式
甲骨文授權教育訓練中心
聯成電腦
張益裕
JCheckBox

JWindow

JButton
JTable

Swing

JPanel
MouseListener
JList
JToggleButton

JEditorPane

JPopupMenu

ItemListener

Java3D

JColorChooser

JComboBox

AdjustmentListener

KeyListener
JRadioButton

GroutLayout

JToolBar

JOptionPane

JLabel

JRootPane

BorderLayout

JFrame

ActionListener
WindowListener
JMenuItem
JSplitPane

Java2D

CardLayout

JProgressBar

ComponentListener

JTextPane

JToolbar

JTextArea

FocusListener

GridLayout

JScrollPane

JTree

JScrollBar

TextListener

JTextField

JMenu

JTabbedPane

AWTJDialog

JPasswordField
FlowLayout

ScrollPaneLayout
Beautiful

Fast

Smooth

Simple
Beautiful

Fast

Smooth

Simple
Java EE

JavaFX

Java SE

Java ME

Java Card

JVM

Java ME VM

Card VM

Java Programming Language
• Java language features
• FXML for defining user interfaces
• New graphics pipeline for modern GPUs
• Rich set of UI controls
• Powerful Properties Model
• Swing and AWT Interoperability
JavaFX Public APIs and Scene Graph

Quantum Toolkit

Prism

Java 2D

Open GL

3D

Glass
Windowing
Toolkit

Media
Engine

Web
Engine
• Over 50+ components
• CSS skinning and layout
• Advanced UI controls
JCD 2012 JavaFX 2
JCD 2012 JavaFX 2
JCD 2012 JavaFX 2
JCD 2012 JavaFX 2
JCD 2012 JavaFX 2
JCD 2012 JavaFX 2
JCD 2012 JavaFX 2
JCD 2012 JavaFX 2
JCD 2012 JavaFX 2
JCD 2012 JavaFX 2
JCD 2012 JavaFX 2
JCD 2012 JavaFX 2
JCD 2012 JavaFX 2
JCD 2012 JavaFX 2
Animation
JCD 2012 JavaFX 2
JCD 2012 JavaFX 2
JCD 2012 JavaFX 2
Belgium
Antwerp
JCD 2012 JavaFX 2
JCD 2012 JavaFX 2
FXML
javafx.stage.Stage
javafx.scene.Scene
root

parent

leaf
javafx.application.Application

public class HelloJavaFX extends Application {
Top level container

@Override
public void start(Stage stage) {

Root container

BorderPane root = new BorderPane();
Button btn = new Button("Hello JavaFX!");
root.setCenter(btn);

}

}

Place Button

Scene scene = new Scene(root, 300, 250);
stage.setScene(scene);
stage.show();

public static void main(String[] args) {
launch(args);
}
Run...
• Region & Pane
• AnchorPane
• BorderPane
• FlowPane & TilePane
• GridPane
• VBox & HBox
• StackPane
BorderPane

FlowPane

GridPane

TilePane

AnchorPane

HBox

VBox

StackPane
• All new event structure and Handler
• Working with convenience methods
• Support Multi-Touch
KeyEvent.KEY_PRESSED
InputEvent.ANY

KeyEvent.ANY

KeyEvent.KEY_RELEASED
KeyEvent.KEY_TYPED

Event.ANY

ActionEvent.ACTION

MouseEvent.ANY

MouseEvent.MOUSE_PRESSED

...

MouseEvent.MOUSE_RELEASED
...

WindowEvent.ANY

WindowEvent.WINDOW_SHOWING
WindowEvent.WINDOW_SHOWN
...
listener?

Button btn = new Button("Hello JavaFX!");
Generic Event type

Register

btn.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
/* Do something */
Generic Event type
}
});

Override
final Circle circle = new Circle(radius, Color.RED);
circle.setOnMouseEntered(new EventHandler<MouseEvent>() {
public void handle(MouseEvent me) {
/* Do something */
}
});
circle.setOnMouseExited(new EventHandler<MouseEvent>() {
public void handle(MouseEvent me) {
/* Do something */
}
});
circle.setOnMousePressed(new EventHandler<MouseEvent>() {
public void handle(MouseEvent me) {
/* Do something */
}
});
handle

EventHandler
final Ellipse oval = new Ellipse(100, 50);
oval.setOnZoom(new EventHandler<ZoomEvent>() {...});
oval.setOnScroll(new EventHandler<ScrollEvent>() {...});
oval.setOnRotate(new EventHandler<RotateEvent>() {...});
• JavaBean Component architecture
• Expanded JavaBean properties
• In conjunction with Binding
Label mile = new Label();

KM to mile

double kmValue = 32.5;
double mileValue = kmValue * 0.621371192;
String mileText = Double.toString(kmValue);
mile.setText(mileText);
Set Label text

Double to String
KM Property Object

DoubleProperty kmPro = new SimpleDoubleProperty();
Label mile = new Label();

StringBinding Object,
hold KM to mile value

StringBinding mileBinding =
kmPro.multiply(0.621371192).asString();
mile.textProperty().bind(mileBinding);
...

Bind mile value
to Text Property

kmPro.set(32.5);
Change KM Property value
DoubleProperty kmPro = new SimpleDoubleProperty();
Label mile = new Label();

Extends Binding Class

StringBinding mileBinding = new StringBinding() {
{
Binding Property
super.bind(kmPro);
}
Override computeValue method

@Override
protected String computeValue() {
return Double.toString(kmPro.get() * 0.621371192);
}
Produce value here

};
mile.textProperty().bind(mileBinding);
...
kmPro.set(32.5);
JCD 2012 JavaFX 2
JCD 2012 JavaFX 2
Login.css

.root	
  {	
  
	
  	
  	
  	
  -­‐fx-­‐background-­‐image:	
  url("background.jpg");
}
.label	
  {	
  	
  	
  	
  ...	
  	
  	
  	
  }
#welcome-­‐text	
  {	
  	
  	
  	
  ...	
  	
  	
  	
  }
#ac@ontarget	
  {	
  	
  	
  	
  ...	
  	
  	
  	
  }
.buAon	
  {	
  	
  	
  	
  ...	
  	
  	
  	
  }
.buAon:hover	
  {	
  	
  	
  	
  ...	
  	
  	
  	
  }
Scene scene = new Scene(grid, 300, 275);
scene.getStylesheets().add("login/Login.css");
Text scenetitle = new Text("Welcome");
scenetitle.setId("welcome-text");
Text actiontarget = new Text();
actiontarget.setId("actiontarget");

Login.css

.root	
  {	
  
	
  	
  	
  	
  -­‐fx-­‐background-­‐image:	
  url("background.jpg");
}
.label	
  {	
  	
  	
  	
  ...	
  	
  	
  	
  }
#welcome-­‐text	
  {	
  	
  	
  	
  ...	
  	
  	
  	
  }
#ac,ontarget	
  {	
  	
  	
  	
  ...	
  	
  	
  	
  }
.buAon	
  {	
  	
  	
  	
  ...	
  	
  	
  	
  }
.buAon:hover	
  {	
  	
  	
  	
  ...	
  	
  	
  	
  }
FXML

• XML-based language
• Separate UI from your code
• Support localize
• Support any JVM language
BorderPane border = new BorderPane();
Label topPaneText = new Label("Label - TOP");
border.setTop(topPaneText);
Button centerPaneButton = new Button("Button - CENTER");
border.setCenter(centerPaneButton);
FXML

<BorderPane>
<top>
<Label text="Label - TOP"/>
</top>
<center>
<Button text="Button - CENTER"/>
</center>
</BorderPane>
Parent root =
FXMLLoader.load(getClass().getResource("Sample.fxml"));
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
Sample.fxml

<BorderPane>
<top>
<Label text="Label - TOP"/>
</top>
<center>
<Button text="Button - CENTER"/>
</center>
</BorderPane>
Sample.fxml

<BorderPane fx:controller="SampleController" >
<top>
<Label text="Label - TOP" fx:id="label" />
</top>
<center>
<Button text="Button - CENTER"
fx:id="button"
onAction="#handleButtonAction"/>
</center>
</BorderPane>

...
public class SampleController implements Initializable {
@FXML
private Label label;
@FXML
private Button button;

SampleController.java

@FXML
private void handleButtonAction(ActionEvent event) {
button.setText("Button Pressed!");
label.setText("Button Pressed!");
}
...
}
• UI Layout Tool
• FXML Visual Editor
• Integrated Developer Workflow
• Preview Your Work
• CSS support
ImageView

TableView

Button

ListView

Label, TextField and TextArea
JCD 2012 JavaFX 2
• JavaFX
❖http://www.oracle.com/technetwork/java/javafx/
• NetBeans
❖http://netbeans.org/
59
Thanks
甲骨文授權教育訓練中心
聯成電腦
張益裕

More Related Content

PDF
JDD 2013 JavaFX
PDF
Web 6 | JavaScript DOM
PPTX
PDF
Joe Walker Interactivewebsites Cometand Dwr
PDF
Web 5 | JavaScript Events
PDF
Remy Sharp The DOM scripting toolkit jQuery
PPTX
jQuery from the very beginning
PPTX
AngularJS
JDD 2013 JavaFX
Web 6 | JavaScript DOM
Joe Walker Interactivewebsites Cometand Dwr
Web 5 | JavaScript Events
Remy Sharp The DOM scripting toolkit jQuery
jQuery from the very beginning
AngularJS

What's hot (7)

PDF
Angular js 24 april 2013 amsterdamjs
PDF
Learning jQuery in 30 minutes
DOCX
Kursus
PPTX
jQuery Data Manipulate API - A source code dissecting journey
KEY
PHPConf-TW 2012 # Twig
PDF
Utopia Kindgoms scaling case: From 4 to 50K users
PDF
Workshop 8: Templating: Handlebars, DustJS
Angular js 24 april 2013 amsterdamjs
Learning jQuery in 30 minutes
Kursus
jQuery Data Manipulate API - A source code dissecting journey
PHPConf-TW 2012 # Twig
Utopia Kindgoms scaling case: From 4 to 50K users
Workshop 8: Templating: Handlebars, DustJS
Ad

Similar to JCD 2012 JavaFX 2 (20)

KEY
jrubykaigi2010-lt-rubeus
PDF
[22]Efficient and Testable MVVM pattern
KEY
Jarv.us Showcase — SenchaCon 2011
PPTX
J Query The Write Less Do More Javascript Library
PDF
JavaFX – 10 things I love about you
PDF
Griffon @ Svwjug
PDF
Overview of The Scala Based Lift Web Framework
PDF
Scala based Lift Framework
PDF
Overview Of Lift Framework
PDF
Integrating SAP the Java EE Way - JBoss One Day talk 2012
PPT
Learning Java 4 – Swing, SQL, and Security API
PDF
How to React Native
PDF
React on Rails - RailsConf 2017 (Phoenix)
PPTX
Build Lightweight Web Module
PDF
Porting legacy apps to Griffon
PPTX
College management system.pptx
PDF
준비하세요 Angular js 2.0
DOC
code for quiz in my sql
KEY
前端概述
PPTX
React responsively, render responsibly - react meetup
jrubykaigi2010-lt-rubeus
[22]Efficient and Testable MVVM pattern
Jarv.us Showcase — SenchaCon 2011
J Query The Write Less Do More Javascript Library
JavaFX – 10 things I love about you
Griffon @ Svwjug
Overview of The Scala Based Lift Web Framework
Scala based Lift Framework
Overview Of Lift Framework
Integrating SAP the Java EE Way - JBoss One Day talk 2012
Learning Java 4 – Swing, SQL, and Security API
How to React Native
React on Rails - RailsConf 2017 (Phoenix)
Build Lightweight Web Module
Porting legacy apps to Griffon
College management system.pptx
준비하세요 Angular js 2.0
code for quiz in my sql
前端概述
React responsively, render responsibly - react meetup
Ad

Recently uploaded (20)

PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PPTX
Lesson notes of climatology university.
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
VCE English Exam - Section C Student Revision Booklet
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
A systematic review of self-coping strategies used by university students to ...
PDF
Classroom Observation Tools for Teachers
PPTX
Cell Structure & Organelles in detailed.
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PPTX
Cell Types and Its function , kingdom of life
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
Computing-Curriculum for Schools in Ghana
PDF
Yogi Goddess Pres Conference Studio Updates
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
O7-L3 Supply Chain Operations - ICLT Program
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Lesson notes of climatology university.
Final Presentation General Medicine 03-08-2024.pptx
Module 4: Burden of Disease Tutorial Slides S2 2025
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
VCE English Exam - Section C Student Revision Booklet
Final Presentation General Medicine 03-08-2024.pptx
A systematic review of self-coping strategies used by university students to ...
Classroom Observation Tools for Teachers
Cell Structure & Organelles in detailed.
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Cell Types and Its function , kingdom of life
human mycosis Human fungal infections are called human mycosis..pptx
Computing-Curriculum for Schools in Ghana
Yogi Goddess Pres Conference Studio Updates
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
2.FourierTransform-ShortQuestionswithAnswers.pdf
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
O7-L3 Supply Chain Operations - ICLT Program

JCD 2012 JavaFX 2