Lecture 7:Introduction to JavaFX Michael Hsu CSULA.

Slides:



Advertisements
Similar presentations
Introduction to Eclipse. Start Eclipse Click and then click Eclipse from the menu: Or open a shell and type eclipse after the prompt.
Advertisements

Unit 091 Introduction to GUI Programming Introduction to User Interfaces Introduction to GUI Programming GUI Design Issues GUI Programming Issues Java.
Java Swing Joon Ho Cho. What is Java Swing? Part of the Java Foundation Classes (JFC) Provides a rich set of GUI components Used to create a Java program.
Java Swing - Lecture 1 An Introduction Milena Radenkovic slides originally by Chris Coleman.
Introduction to Java Programming. Contents 1. Java, etc. 2. Java's Advantages 3. Java's Disadvantages 4. Types of Java Code 5. Java Bytecodes 6. Steps.
Written by Liron Blecher
GUI Basics: Introduction. Creating GUI Objects // Create a button with text OK JButton jbtOK = new JButton("OK"); // Create a label with text "Enter your.
11 Getting Started with C# Chapter Objectives You will be able to: 1. Say in general terms how C# differs from C. 2. Create, compile, and run a.
Benedicto Fernandez Software Engineer CERN / GS-AIS Dubna 2012.
Applets and Frames CS 21a: Introduction to Computing I First Semester,
Presented By: Muhammad Tariq Software Engineer Android Training course.
Programming Concept Chapter I Introduction to Java Programming.
Unit 1: Java and Eclipse The Eclipse Development Environment.
CS Lecture 00 Swing overview and introduction Lynda Thomas
4-Nov-15 Air Force Institute of Technology Electrical and Computer Engineering Object-Oriented Programming Design Topic 1: The Java Environment Maj Joel.
CSE S. Tanimoto Java Introduction 1 Java A Programming Language for Web-based Computing with Graphics.
1 Java Swing - Lecture 2 Components and Containment Boriana Koleva
Applets and Frames. Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L14: GUI Slide 2 Applets Usually.
Applets Yong Choi School of Business CSU, Bakersfield.
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.
Topics Introduction Scene Graphs
Chapter 5 Introduction To Form Builder. Lesson A Objectives  Display Forms Builder forms in a Web browser  Use a data block form to view, insert, update,
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.
Section §14.1 Introduction  Graphical User Interface (GUI) applications, as opposed to console UI applications, rely heavily on objects  JavaFX.
Programming – Lecture 15 Going Beyond the ACM Library.
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.
Va installato Qui le istruzioni
CS 201 Lecture 1 (b) Using an IDE Tarik Booker CS 201: Introduction to Programming California State University, Los Angeles.
Chapter 14 JavaFX Basics.
Lecture 15 Basic GUI programming
Lecture 18 CS
Introduction to Java Import Scanner class to use in our program
Chapter 15 Event-Driven Programming and Animations
Working in the Forms Developer Environment
A Programming Language for Web-based Computing with Graphics
Java Programming Java FX.
Lecture 7:Introduction to JavaFX
Java Look-and-Feel Design Guidelines
Java FX.
Tutorial 6 Topic: jQuery and jQuery Mobile Li Xu
CISC124 Quiz 2 grading underway.
Java Tutorial Zhe Li.
EE 422C Java FX.
Chapter 14 JavaFX Basics Dr. Clincy - Lecture.
Chapter 14 JavaFX Basics Dr. Clincy - Lecture.
Chapter 1 Introduction to Computers, Programs, and Java
Introduction to Computing Using Java
How to Run a Java Program
CMPE212 – Stuff… Assignment 4 due March 23 – this Friday.
Introduction to Computing Using Java
12/28/2018 COSC 330.
CISC124 Last Quiz next week. Topics listed in Tuesday’s lecture.
How to Run a Java Program
Whatcha doin'? Aims: Begin to create GUI applications. Objectives:
SEEM4570 Tutorial 5: jQuery + jQuery Mobile
Introduction to Java Brief history of Java Sample Java Program
(Computer fundamental Lab)
Chapter 14 JavaFX Basics Part 1
Java Looking at our first console application in Eclipse
Chapter 14 JavaFX Basics Part 2
Chapter 15 Event-Driven Programming and Animations Part 1
CMPE212 – Reminders Assignment 5, a JavaFX GUI, due this Friday.
CMPE212 – Reminders Assignment 5, a JavaFX GUI, due next Friday.
Using JavaFX Applications
Introduction to Java FX
Foundations of Programming 2: JavaFX Basics
How to Run a Java Program
Presentation transcript:

Lecture 7:Introduction to JavaFX Michael Hsu CSULA

A New Era  You’ve learned most of the basic concepts of Java  You should be able to pick up any library, do some research, and use it in your project  From now and on, there are too many methods available in the libraries that we’re covering, we will not go over all of them in class  It’s up to you to figure it out

GUI Applications  So far, you’ve probably only worked on console applications  Provide input from keyboard  Read input using java.util.Scanner  Do something  Print result to System.out  It’ll be nice to have a GUI application  Examples: Microsoft Word, Apps on your phone, Your browser  We cover the basic material before covering GUI programming because it requires use of all the basic knowledge you’ve learned so far  We will cover JavaFX in this class

Why JavaFX  JavaFX is a new framework for developing Java GUI Programs  Graphical functionality is provided by the library, no need to write your own  Some Java History  Ancient code: AWT  Until Java 7: Swing (Will never die, most current application still use it)  Java 8 and later: JavaFX  Do not use Swing/AWT examples copied from online sources  Good way to review and use all the knowledge you acquired so far  Object Oriented Programming  The principles you learn in this class will apply to many UI frameworks you learn in the future

Getting JavaFX to work on your computer  Couple of options:  Download the all-in-one eclipse package   Install the e(fx)clipse plugin in your existing eclipse   Modify the Java Compiler Option for a JavaFX Project (not recommended)  The reason why eclipse shows an error is JavaFX may not be available on all machines, it is part of the “extended API”  Go to Window -> Preferences -> Java -> Compiler -> Errors/Warnings. Then under Deprecated and restricted API, change “Forbidden reference (access rules)” to ignore.  Compiling from command line should work as long as you’re using the latest JDK

JavaFX HelloWorld Example // import javafx.scene.control.Button, not java.awt.Button!!!!! public class HelloWorld extends Application { public static void main(String[] args) { launch(args); } // Override the start method in the Application public void start(Stage primaryStage) { // Create a scene and place a button in the scene Button btOK = new Button("OK"); Scene scene = new Scene(btOK, 200, 250); primaryStage.setTitle("MyJavaFX"); // Set the stage title primaryStage.setScene(scene); // Place the scene primaryStage.show(); }

JavaFX HelloWorld Example: Start public class HelloWorld extends Application { public static void main(String[] args) { launch(args); } // Override the start method in the Application public void start(Stage primaryStage) { // Create a scene and place a button in the scene Button btOK = new Button("OK"); Scene scene = new Scene(btOK, 200, 250); primaryStage.setTitle("MyJavaFX"); // Set the stage title primaryStage.setScene(scene); // Place the scene primaryStage.show(); } Starting Point of a JavaFX application Main Method can be omitted when running from console/with e(fx)clispe installed A primary stage is created automatically

JavaFX HelloWorld Example: Controls public class HelloWorld extends Application { public static void main(String[] args) { launch(args); } // Override the start method in the Application public void start(Stage primaryStage) { // Create a scene and place a button in the scene Button btOK = new Button("OK"); Scene scene = new Scene(btOK, 200, 250); primaryStage.setTitle("MyJavaFX"); // Set the stage title primaryStage.setScene(scene); // Place the scene primaryStage.show(); } Individual UI components are called controls Example: Labels, Buttons

Some Terminologies  Stage  Represents windows, top level container  Many setter methods: setTitle(), setWidth()  You can create multiple stages and use one or another  Scene  Each stage has a scene  Scene holds controls (buttons, labels, etc)  Pane  You can put controls in Scenes directly, but we usually Panes for better layout  Examples: StackPane, BorderPane, HBox, VBox

JavaFX HelloWorld Example: Creating the Stage public class HelloWorld extends Application { public static void main(String[] args) { launch(args); } // Override the start method in the Application public void start(Stage primaryStage) { // Create a scene and place a button in the scene Button btOK = new Button("OK"); Scene scene = new Scene(btOK, 200, 250); primaryStage.setTitle("MyJavaFX"); // Set the stage title primaryStage.setScene(scene); // Place the scene primaryStage.show(); } Place the scene in the Stage Stage.show() makes window appear

JavaFX Example: Multiple Stages public class MultiStageDemo extends Application { public static void main(String[] args) { launch(args); } // Override the start method in the Application public void start(Stage primaryStage) { // Create a scene and place a button in the scene Button btOK = new Button("OK"); Scene scene = new Scene(btOK, 200, 250); primaryStage.setTitle("MyJavaFX"); // Set the stage title primaryStage.setScene(scene); // Place the scene primaryStage.show(); Stage secondStage = new Stage(); secondStage.setTitle("Second Stage"); secondStage.setScene(new Scene(new Label("This is exmaple of label"))); secondStage.show(); }

12 Basic Structure of JavaFX  Application  Override the start(Stage) method  Stage, Scene, and Nodes

13 Layout Panes JavaFX provides many types of panes for organizing nodes in a container.

Using Panes  Required Reading:  Familiar yourself with the built in layouts  You can mix and match different types of layouts  Panes are also nodes  You can have an HBox in a BorderPane, a VBox in a StackPane, etc

15 Panes, UI Controls, and Shapes Read:

16 Display a Shape This example displays a circle in the center of the pane. ShowCircle.java

17 Binding Properties  JavaFX introduces a new concept called binding property  Enables a target object to be bound to a source object.  If the value in the source object changes, the target property is also changed automatically.  The target object is simply called a binding object or a binding property. ShowCircleCentered.java BidrectionalBinding.java

18 Binding Property: getter, setter, and property getter

Common Properties and Methods for Nodes  style: set a JavaFX CSS style   You can use both in-line code styling and external stylesheets, just like HTML.  rotate: Rotate a node

20 The Image Class

21 The ImageView Class

JavaFX Resources  Oracle JavaFX Portal:   How to Use Layouts:   UI Controls:  tutorial/ui_controls.htm#JFXUI336 tutorial/ui_controls.htm#JFXUI336  Property Binding:  tutorial/binding.htm#JFXBD107 tutorial/binding.htm#JFXBD107