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

Things to mention public static void main(String [] args) –The starting point for a free-standing Java application (i.e. one not run from the DrJava interactions.
Visual Basic 2010 How to Program. © by Pearson Education, Inc. All Rights Reserved.2.
Unit 091 Introduction to GUI Programming Introduction to User Interfaces Introduction to GUI Programming GUI Design Issues GUI Programming Issues Java.
Graphics Programming. In this class, we will cover: The difference between AWT and Swing Creating a frame Frame positioning Displaying information in.
Introduction to Java Programming, 4E
Android: Hello World Frank Xu Gannon University. Steps Configuration ▫Android SDK ▫Android Development Tools (ADT)  Eclipse plug-in ▫Android SDK and.
18-Jun-15 Applets. 2 An applet is a program that is typically embedded in a Web page and can be run from a browser You need special HTML in the Web page.
28-Jun-15 Applets. 2 An applet is a program that is typically embedded in a Web page and can be run from a browser You need special HTML in the Web page.
Developing User Interfaces (DUI) Chris North cs3724: HCI.
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.
An intro to programming. The purpose of writing a program is to solve a problem or take advantage of an opportunity Consists of multiple steps:  Understanding.
Applets and Frames CS 21a: Introduction to Computing I First Semester,
Presented By: Muhammad Tariq Software Engineer Android Training course.
Jaeki Song ISQS6337 JAVA Lecture 03 Introduction to Java -The First Java Application-
Programming Concept Chapter I Introduction to Java Programming.
Introduction to Java Programming with Forte Y. Daniel Liang.
Copyright © Curt Hill First Window Builder Program Easy GUIs in Eclipse.
Graphics and Event-Driven Programming in Java John C. Ramirez Department of Computer Science University of Pittsburgh.
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
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved COS240 O-O Languages AUBG,
CIS Intro to JAVA Lecture Notes Set 8 9-June-05.
Review_6 AWT, Swing, ActionListener, and Graphics.
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.
Computer Science A 1. Course plan Introduction to programming Basic concepts of typical programming languages. Tools: compiler, editor, integrated editor,
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.
Notices Assn 3 is posted – due tomorrow. Quiz marking underway (still – sigh…). Alternate solution code was added on Tuesday to the assignment 3 statement.
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.
Lecture 7:Introduction to JavaFX Michael Hsu CSULA.
Chapter 14 JavaFX Basics.
Lecture 18 CS
Chapter 15 Event-Driven Programming and Animations
A Programming Language for Web-based Computing with Graphics
Java Programming Java FX.
Lecture 7:Introduction to JavaFX
Java FX.
CISC124 Quiz 2 grading underway.
EE 422C Java FX.
Chapter 14 JavaFX Basics Dr. Clincy - Lecture.
Chapter 14 JavaFX Basics Dr. Clincy - Lecture.
Lecturer: Mukhtar Mohamed Ali “Hakaale”
Introduction to Computing Using Java
How to Run a Java Program
12/28/2018 COSC 330.
CISC124 Last Quiz next week. Topics listed in Tuesday’s lecture.
Chapter 14 JavaFX Basics Part 1
Chapter 15 Event-Driven Programming and Animations Part 1
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  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 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

Example: Multiple Stages

Examples: Using Panes

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

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

15 Panes, UI Controls, and Shapes

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

19 Common Properties and Methods for Nodes  style: set a JavaFX CSS style  rotate: Rotate a node

20 The Image Class

21 The ImageView Class