Java Fx

Click here to load reader

  • date post

  • Category


  • view

  • download


Embed Size (px)


Presentation on Java FX

Transcript of Java Fx

  • JavaFX Workshop 1
  • What is & Why JavaFX?
  • Rich Clients Are Changing the Game! Clients are becoming visually rich > Too much engineering effort to create using traditional tools > Challenging the conventional notion of GUI toolkits > Buttons with image Image buttons (HTML) ??? Clients are omnipresence > The concept of one software on one computer is dying... > Browsers are no longer the only client - They are used as delivery vehicles Clients are designed rather than programmed > Working together with graphic designers to conceptualize the interface and use cases
  • What does RIA mean today? Extend RIA, across multiple screens
  • JavaFX Vision JavaFX is THE platform for creating and delivering Rich Internet Applications (RIA) across all the screens of your life JavaFX is Powered by Java
  • Key Features of JavaFX
  • Key Features One-stop shop RIA platform for all screens: > Build engaging visual experiences across desktop, browser and mobile with a unified development and deployment model. Broadest market reach: > Distribute RIAs easily across billions of devices with the power of Java. Designer-developer workflow: > Dramatically shorten your production cycle for design and development.
  • Key Features (Continued) Break free from the browser: > Drag-and drop a JavaFX application from the browser to deploy to the desktop. Built over powerful Java runtime: > Leverage the extreme ubiquity, power, performance and security of the Java runtime. Java technology compatibility: > Preserve your investment by enabling the use of any Java library within a JavaFX application.
  • Things You Can Build with JavaFX
  • 3-D Display Shelf With the PerspectiveTransform The PerspectiveTransform built into JavaFX can be used to easily create 3-D effects
  • Flying Saucer The new out-of-process Java applet plugin in Java SE 6 update 10 enables you to make applets which can run outside of the browser.
  • Simple Video Player Incorporating video in your application is as simple as creating an instance of this component, setting a few variables and including a link to your video source.
  • VideoCube Shows how to use JavaFX technology to rotate a cube that displays video on its faces. The sample enables the user to click a cube face to play video, or drag a face to rotate the cube
  • JavaFX Platform Architecture
  • JavaFX Platform Architecture
  • Example: Hello World in JavaFX Declarative Syntax Stage { title: "Welcome to JavaFX!" scene: Scene { content: [ Text { content: "Hello World!" x:25 y:25 fill: Color.BLACK font: Font{ size: 32 } } ] } }
  • Data Types
  • Basic Data Types Boolean Integer Number String Duration Data types cannot be null
  • String: Declaration A String can be declared using either single or double quotes: > var s1 = 'Hello'; > var s2 = "Hello"; Single and double quotes are symmetrical: you can embed single quotes within double quotes, and double quotes within single quotes. There is no difference between single- and double- quoted strings.
  • String: Embedded Expressions You can also embed expressions inside a string using curly braces "{}": > def name = 'Joe'; > var s = "Hello {name}"; // s = 'Hello Joe' The embedded expression can itself contain quoted strings, which, in turn, can contain further embedded expressions: > def answer = true; > var s = "The answer is {if (answer) "Yes" else "No"}"; // s = 'The answer is Yes'
  • String: Joining (Concatenating) To join (concatenate) multiple strings, use curly braces inside the quotes: def one = "This example "; def two = "joins two strings."; def three = "{one}{two}"; // join string one and string two println(three); // 'This example joins two strings.'
  • Number and Integer: Declaration The Number and Integer types represent numerical data, although for most scripting tasks, you will usually just let the compiler infer the correct type: def numOne = 1.0; // compiler will infer Number def numTwo = 1; // compiler will infer Integer You can, however, explicitly declare a variable's type: def numOne : Number = 1.0; def numTwo : Integer = 1; Number represents floating-point numbers while Integer only represents integers. Use Number only when you absolutely need floating-point precision. In all other cases, Integer should be your first choice.
  • Boolean The Boolean type represents two values: true or false var isAsleep = true; or when evaluating a conditional expression: if (isAsleep) { wakeUp(); }
  • Duration The Duration type represents a fixed unit of time (millisecond, second, minute, or hour.) 5ms; // 5 milliseconds 10s; // 10 seconds 30m; // 30 minutes 1h; // 1 hour Durations are notated with time literals for example, 5m is a time literal representing five minutes. Time literals are most often used in animation
  • Void Void is used to indicate that a function does not return any value: The following two are equivalent // Return type is set to Void function printMe() : Void { println("I don't return anything!"); } // No return type function printMe() { println("I don't return anything!"); }
  • Null Null is a special value used to indicate a missing normal value. Null is not the same as zero or an empty string, so comparing for null is not the same as comparing for zero or an empty string. function checkArg(arg1: Address) { if(arg1 == null) { println("I received a null argument."); } else { println("The argument has a value."); } }
  • Script Variables
  • Script Variables Script variables are declared using the var or def keywords. > The difference between the two is that var variables may be assigned new values throughout the life of the script, whereas def variables remain constant at their first assigned value. def numOne = 100; def numTwo = 2; var result;
  • Type Inference (by Compiler) You don't have to explicitly specify the types of variable in JavaFX The compiler is smart enough to figure out your intent based on the context in which the variable is used. This is known as type inference. Type inference makes your job as a script programmer a little easier because it frees you from the burden of declaring the data types that your variable is compatible with.
  • Writing Your Own Classes
  • Class Definition Address class definition: The Address class declares street, city, state, and zip instance variables all of type String class Address { var street: String; var city: String; var state: String; var zip: String; }
  • Class Definition Customer class definition with functions - functions are like methods in Java class Customer { var firstName: String; var lastName: String; var phoneNum: String; var address: Address; function printName() { println("Name: {firstName} {lastName}"); } function printPhoneNum(){ println("Phone: {phoneNum}"); }
  • Object Literals
  • What is an Object? (Same as in Java) Objects represent state and behavior > An object's state is represented by its variables. > An object's behavior is represented by its functions. Conceptually an object can model just about anything, from GUI components (buttons, check boxes, text labels) to non-visual abstractions (temperature data, financial records, product