13 JavaFX - University of Hawaii

Download Report

Transcript 13 JavaFX - University of Hawaii

13. JavaFX
2
JavaFX Intro
• Sun's answer to
– the popularity of scripting languages
– problems with Java GUI
• AWT is very basic
• Swing is too complex, too cumbersome, too voluminous and gained therefore little
popularity
– problems with RIA and multimedia in Java
•
•
•
•
•
JavaSound is too low-level
JMF (Java Media Framework) is virtually unsupported
Java 2D is good, but follows different design than other media packages
Image IO is good, also follows different design
Java 3D is completely separate, self-contained software monolith
• Java never really made it to the desktop
• But, the building blocks are there
3
Building Blocks
•
Java language itself
–
very popular
•
•
•
•
–
widely used
•
•
•
•
Remote Method Invocation (RMI)
XML Web Services (JAX-WS).
Applets
–
supported by most browsers
•
•
–
–
•
server-side web programming
cell phones
TV set-top boxes
Rich set of libraries, e.g.,
–
–
•
over 6Mio. developers
major industry support (IBM, Google, Oracle; almost everyone, except Microsoft)
many universities adopted Java as prime teaching language
most programming books now use Java
either directly with <applet> tag
or at least as using the Java plug-in
some PC's have Java pre-installed
but not as widely available as Flash
WebStart
–
applets and applications can be downloaded to desktop
4
Features
•
•
Separate scripting language "JavaFX Script"
Multiplatform
–
–
–
–
•
browsers
desktop
cell phones
TV settop boxes
Multimedia
–
–
–
–
–
text
GUI widgets
graphics in 2D and 3D
animations
audio and video
• Integration for graphic designers
– Adobe Photoshop and Illustrator plugins for JavaFX
•
•
direct manipulation of assets, animation paths, etc.
Drag to install
5
Concepts
•
Based on Java and Java tools
–
JDK
•
–
–
–
•
efficient
no eval() support
Supported by NetBeans IDE
–
–
•
applets
Java plugin
WebStart
Scripting-like, but compiled
–
–
•
Swing GUI
preview
building into jar files with ant and jnlp files
Scripts can
–
directly use Java classes (e.g. all of JDK)
6
JavaFX Script
• Syntax more like JavaScript then Java
– less cryptic
– function instead of method
– var (resp. var for constants) instead of declaration via type
• Object-oriented
– classes
•
e.g., var home = Address {street: "1 Main Street"; city: "Honolulu"; zip: "HI 96813";}
– inheritance
•
•
e.g., var student = student {name: "John Wu"; address: home;}
override function
– properties
– encapsulation
•
public, (private is default) , protected , package, public-read, public-init
– anonymous functions
•
e.g., action: function () {nextTick ()}
7
JavaFX Script Highlights
• Variables
– can, but don't need to be typed
– entire expressions can be "interpolated into a string using {expression}
•
e.g., "4+5={4+5}"
– strings can be enclosed in " as well as in '
• Types
– String, Number, Integer, Boolean, Duration, Void, Null
•
•
e.g., var delay: Duration = 50ms // s, m, h also valid suffixes
Boolean operators: not, and, or
– Arrays and called Sequences
•
var nums = [1..5]; // same as: var nums = [1,2,3,4,5];
•
various operations, such as appending, inserting, deleting elements, as well as subsequences
• Statements
– for (variable in sequence)
•
e.g., for (i in [1..10]) {…}
8
Binding
• Keyword bind associates a variable with the value of a bound
expression
– bound expressions
•
•
•
variable
expression
function call
– bound function
– when the variable 's value changes, the code of the bound expression
is re-evaluated
• Binding is used for
– animation
– handling interactions with GUI widgets
• e.g., transforms: Rotate {angle: bind seconds * 6}
• see: java.sun.com/javafx/1/tutorials/core/dataBinding/index.html
9
Potential Problems
• On many PCs, applets are not installed
– compare with Flash which has 90%+ penetration
• Downloading Java takes a lot of time
– Swing packages are huge
• Java upgrades are relatively frequent
– upgrades (= downloads) are necessary
• Competition:
– Adobe Flex
• not free