Chapter 14 JavaFX Basics Part 1

Slides:



Advertisements
Similar presentations
Chapter 13 Graphics.
Advertisements

Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 14 Graphics.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 13 Graphics.
Graphics Programming. In this class, we will cover: The difference between AWT and Swing Creating a frame Frame positioning Displaying information in.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L01 (Chapter 13) Graphics.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L24 (Chapter 25) Networking.
Java Review Structure of a graphics program. Computer Graphics and User Interfaces Java is Object-Oriented A program uses objects to model the solution.
Written by Liron Blecher
Photocollage System. What is Photocollage? Photographic approach in combining multiple images to create a new whole Result is an expressive composition.
(c) University of Washington08-1 CSC 143 Models and Views Reading: Ch. 18.
Java Programming: Advanced Topics 1 Common Elements of Graphical User Interfaces Chapter 6.
CIS3023: Programming Fundamentals for CIS Majors II Summer 2010 Ganesh Viswanathan Introduction to Applets Course Lecture Slides 29 th July 2010.
SIMPLE PROBLEM SOLVING in Java: a Problem Set Framework Viera K. Proulx Richard Rasala Jason Jay Rodrigues CCSCNE 2002 Conference.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Creating GUIs in Java Using.
Objects and Classes Java Methods A & AB Object-Oriented Programming and Data Structures Maria Litvin ● Gary Litvin Copyright © 2006 by Maria Litvin, Gary.
Cs413_chapt01.ppt Chapter 1 Web Sites Numerous
Object Oriented Software Development 9. Creating Graphical User Interfaces.
Session 27 Swing vs. AWT. AWT (Abstract Window ToolKit) It is a portable GUI library for stand-alone applications and/or applets. The Abstract Window.
School of Computer Science & Information Technology G6DICP - Lecture 17 GUI (Graphical User Interface) Programming.
Java Applets. 2 Introduction to Java Applet Programs Applications are ___________________ programs –executed with Java interpreter Applet is a small program.
Object Oriented programming Instructor: Dr. Essam H. Houssein.
Cs413_chapt02.ppt CS413 Advanced Swing Graphical User Interface Components Text: Advanced Java 2 Platform: Chapter 2 Abstract Windowing Toolkit (AWT) Library.
Java Applets: GUI Components, Events, Etc. Ralph Westfall June, 2010.
Applets Yong Choi School of Business CSU, Bakersfield.
GUI Basics. What is GUI? A graphical user interface (GUI) is a type of user interface item that allows people to interact with programs in more ways than.
Creating Windows. How can we use Java to create programs that use windows (GUI applications)? How can we use Java to create programs that use windows.
The Abstract Window Toolkit (AWT) supports Graphical User Interface (GUI) programming. AWT features include: a rich set of user interface components; a.
GUIs Graphical User Interfaces. Everything coming together Known: – Inheritance – Interfaces – Abstract classes – Polymorphism – Exceptions New: – Events.
Review_6 AWT, Swing, ActionListener, and Graphics.
Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved. 1 Chapter 15 Event-Driven Programming and.
Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved. 1 Chapter 14 JavaFX Basics.
Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved. 1 Chapter 15 Event-Driven Programming and.
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
May 6, 1998CS102-02Lecture 6-2 Cross-Platform Programming CS Lecture 6-2 Making everyone happy.
Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved. 1 Chapter 14 JavaFX Basics.
Lecture 7:Introduction to JavaFX Michael Hsu CSULA.
Lecture 7:Introduction to JavaFX Michael Hsu CSULA.
Chapter 14 JavaFX Basics.
Welcome To java
Java FX: Scene Builder.
Chapter 15 Event-Driven Programming and Animations
Lecture 7:Introduction to JavaFX
Java Look-and-Feel Design Guidelines
Java FX.
EE 422C Java FX.
Chapter 14 JavaFX Basics Dr. Clincy - Lecture.
Chapter 14 JavaFX Basics Dr. Clincy - Lecture.
Chapter 15 Event-Driven Programming and Animations
Recall: Timeline Class
.NET and .NET Core 7. XAML Pan Wuming 2017.
Understanding the Visual IDE
Java Applets.
Week 8 Swing NetBeans GUI Builder
Constructors, GUI’s(Using Swing) and ActionListner
Chapter 13 Graphics.
Model, View, Controller design pattern
Chapter 15 Event-Driven Programming and Animations Part 1
Chapter 12 GUI Basics.
Introduction to Java FX
Chapter 13 Graphics.
Chapter 14 JavaFX Basics.
Graphical User Interface
APPLET PROGRAMMING.
Foundations of Programming 2: JavaFX Basics
TA: Nouf Al-Harbi NoufNaief.net :::
TA: Nouf Al-Harbi NoufNaief.net :::
Presentation transcript:

Chapter 14 JavaFX Basics Part 1

JavaFX vs. Swing & AWT Initially Java came with the AWT (Abstract Windows Toolkit) GUI (Graphical User Interface) library. AWT is fine for developing simple graphical user interfaces, but not for developing comprehensive GUI projects. AWT components are platform-dependent AWT was replaced by a more robust, versatile, and flexible library, Swing, in 1998. Swing components are platform- independent Java 8 introduced in 2014 the JavaFX GUI framework for developing Rich Internet Applications (RIA) that provide a desktop-like experience on Web applications. JavaFX is an excellent example of how the object-oriented principles are applied. JavaFX components are platform-independent

JavaFX vs. Swing & AWT Swing example JavaFX example AWT example

Structure of a JavaFX Program Every JavaFX program is defined in a class that extends javafx. application. Application Extend Application Override start(Stage) Create Nodes (e.g., Button) Place the Nodes in the Scene Place the Scene on Stage Show Stage MyJavaFX Run MultipleStageDemo Run

Panes, UI Controls, and Shapes Extend Application Override start(Stage) Create Nodes Place Nodes in a Parent Place the Parent in the Scene Place the Scene on Stage Show Stage ButtonInPane Run

Example: Circle at the Center of a Pane ShowCircle Run

Property Binding Property binding enables a property of a target object to be bound to a property of the source object. If the value of the property in the source object changes, the corresponding target property changes automatically The target object is called a binding object or a binding property. The source object is called a bind-able or observable object Syntax: target.bind(source); circle.centerXProperty().bind(pane.widthProperty().divide(2)); circle.centerYProperty().bind(pane.heightProperty().divide(2)); The center of the circle will always remain in the middle of the pane ShowCircleCentered Run

Property Binding: Accessor, Mutator & Property Accessor Each binding property (e.g., centerX) in a JavaFX class (e.g., Circle) has the usual accessor (e.g., getCenterX()) and a mutator (e.g., setCenterX(double)) Each binding property also has a property accessor for returning the property itself. The name for this property accesor method should be the property name followed by the word Property Syntax Example

Uni- and Bi-directional Binding The binding demonstrated in the ShowCircleCentered example is known as unidirectional binding Occasionally, it is useful to synchronize two properties so that a change in one property is reflected in another object, and vice versa. This is called a bidirectional binding If the target and source are both binding properties and observable properties, they can be bound bi-directionally using bindBidirectional() BindingDemo Run BidirectionalBindingDemo Run

Pane and its Subclasses Pane (or any of its subclasses) is used for organizing nodes The Pane is then placed in a Scene, which is placed on a Stage The Stage is then revealed on the screen using show()

Pane and its Subclasses

FlowPane ShowFlowPane Run

GridPane ShowGridPane Run

BorderPane ShowBorderPane Run

HBox

VBox ShowHBoxVBox Run

The Color Class

The Font Class FontDemo Run

The Image & ImageView Classes The Image class represents a graphical image and is used for loading an image from a specified filename or URL. For example: new Image("image/us.gif") creates an Image object for the file us.gif under the directory image in the Java class directory new Image("http://www.armstrong.edu/image/us.gif") creates an Image object for the image file in the URL on the Web ImageView is used for displaying an Image object. For example, Image image = new Image("image/us.gif"); ImageView imageView = new ImageView(image);

Image ImageView ShowImage Run

Node Properties: style & rotate The abstract Node class defines many properties & methods. Here we focus upon two of those properties: style and rotate Syntax for setting the style of a node is styleName:value. A style property is defined with a prefix -fx- Multiple style properties for a node can be set together separated by semicolon. For example, the statement: circle.setStyle("-fx-stroke: black; -fx-fill: red;"); sets two style properties for a circle The rotate property is used to specify an angle in degrees for rotating the node. For example, the following code rotates a button by 80 degrees: button.setRotate(80); NodeStyleRotateDemo Run