Graphical User Interfaces

Similar documents
Graphical User Interfaces

Graphical User Interfaces

Computational Expression

CSC 1051 Data Structures and Algorithms I. Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University

Preparation: Get to know the Java coordinate system. 3. How is the background color of the window specified? Copy the exact code:

Data Representation and Applets

Applets and the Graphics class

GUI Output. Adapted from slides by Michelle Strout with some slides from Rick Mercer. CSc 210

Data Representation and Applets

Data Representation and Applets

@Override public void start(stage primarystage) throws Exception { Group root = new Group(); Scene scene = new Scene(root);

JavaFX Technology Building GUI Applications With JavaFX - Tutorial Overview

Grafica e non solo: Java FX

Building Graphical user interface using JavaFX

JavaFX. Working with the JavaFX Scene Graph Release 8 E March 2014 Learn about the concept of a scene graph and how it is used in JavaFX.

PART ONE CREATING THE BOARD AND MAIN SPRITES

Happy Cinco de Mayo!!!!

JavaFX. Using Image Ops Release 2.2 E

Week 5: Images & Graphics. Programming of Interactive Systems. JavaFX Images. images. Anastasia Bezerianos. Anastasia Bezerianos

Happy Cinco de Mayo!!!!

Java Foundations. 9-1 Introduction to JavaFX. Copyright 2014, Oracle and/or its affiliates. All rights reserved.

CSC 1051 Algorithms and Data Structures I. Midterm Examination October 7, Name:

Data Representation and Applets

Grafica e non solo: Java FX

CST141 JavaFX Basics Page 1

CISC 1600 Lecture 3.1 Introduction to Processing

Definizione dei costru'ori

COMP1406 Tutorial 5. Objectives: Getting Started: Tutorial Problems:

CSC 1051 Data Structures and Algorithms I. Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University

Multimedia-Programmierung Übung 3

c 2017 All rights reserved. This work may be distributed or shared at no cost, but may not be modified.

IT In the News. Login tokens have been reset for those affected and vulnerabilities have been fixed. o Vulnerabilities existed since July 2017

Grafica e non solo: Java FX

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

For your convenience Apress has placed some of the front matter material after the index. Please use the Bookmarks and Contents at a Glance links to

c.def (pronounced SEE-def) Language Reference Manual

CISC 1600, Lab 2.1: Processing

Java Programming Hello FX

Solution Notes. COMP 151: Terms Test

Chapter 6, Case Study: BallWorld

CSC 1051 Data Structures and Algorithms I

CSC 1051 Villanova University. CSC 1051 Data Structures and Algorithms I. Course website:

Appendix F: Java Graphics

Appendix F: Java Graphics

JavaFX Application Structure. Tecniche di Programmazione A.A. 2017/2018

CISC 1600, Lab 3.1: Processing

CSC 1051 Algorithms and Data Structures I. Midterm Examination February 24, Name: KEY 1

Chapter 14 JavaFX Basics. Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved.

CSC 1051 Algorithms and Data Structures I. Midterm Examination October 9, Name: KEY

Programming Fundamentals

+ Inheritance. Sometimes we need to create new more specialized types that are similar to types we have already created.

EXAMINATIONS 2017 TRIMESTER 2

CSC 1051 Data Structures and Algorithms I

An Introduction to Processing

To specify the dimensions of the drawing canvas use the size statement: ! size( 300, 400 );

5 Drawing Stuff in 2D

Composite Pattern Diagram. Explanation. JavaFX Subclass Hierarchy, cont. JavaFX: Node. JavaFX Layout Classes. Top-Level Containers 10/12/2018

The main method. The program s entry point

CSC 1051 Data Structures and Algorithms I

PyGame Unit ?

Arrays, Part 3: Multidimensional arrays

For your convenience Apress has placed some of the front matter material after the index. Please use the Bookmarks and Contents at a Glance links to

C12: JavaFX Scene Graph, Events, and UI Components

EXAMINATIONS 2016 TRIMESTER 2

SHAPES & TRANSFORMS. Chapter 12 of Pro WPF : By Matthew MacDonald Assist Lect. Wadhah R. Baiee. College of IT Univ.

C14: JavaFX: Overview and Programming User Interface

I/O Streams. program. Standard I/O. File I/O: Setting up streams from files. program. File I/O and Exceptions. Dr. Papalaskari 1

JavaFX Basics. Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved. 1.

File I/O and Exceptions

Java FX. Properties and Bindings

Introduction: Game. Key Design Points

Ai Adobe. Illustrator. Creative Cloud Beginner

TWO-DIMENSIONAL FIGURES

Designing Classes Part 2

Come organizzare gli ascoltatori/osservatori

Selection Statements and operators

//Create BorderPane layout manager. layout = new BorderPane(); //This is the "root node".

The Processing language. Arduino and Processing.

public static void main(string[] args) { GTest mywindow = new GTest(); // Title This program creates the following window and makes it visible:

Graphical User Interfaces JavaFX GUI Basics. CSE114, Computer Science I Stony Brook University

Posizionamento automa-co: Layouts di base. h5p://docs.oracle.com/javafx/2/ layout/jfxpub- layout.htm

CS-202 Introduction to Object Oriented Programming

I/O Streams. program. Standard I/O. File I/O: Setting up streams from files. program. File I/O and Exceptions. Dr. Papalaskari 1

I/O Streams. program. Standard I/O. File I/O: Setting up streams from files. program. File I/O and Exceptions. Dr. Papalaskari 1

Introduction to Arrays

CSC 1051 Algorithms and Data Structures I. Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University

Using Classes and Objects

mith College Computer Science CSC103 How Computers Work Week 7 Fall 2017 Dominique Thiébaut

Java Object Oriented Design. CSC207 Fall 2014

Computer Programming

CIS 110 Introduction to Computer Programming Summer 2014 Midterm. Name:

1 Getting started with Processing

1 Getting started with Processing

Selection Statements and operators

How to...create a Video VBOX Gauge in Inkscape. So you want to create your own gauge? How about a transparent background for those text elements?

Output models Drawing Rasterization Color models

JavaFX. Working with JavaFX Graphics Release 8 E

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. OpenCV

Recall that creating or declaring a variable can be done as follows:

Class #1. introduction, functions, variables, conditionals

Transcription:

Graphical User Interfaces CSC 1051 Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website: http://www.csc.villanova.edu/~map/1051/ Many slides in this presentation are adapted from Prof. Barbara Zimmerman s CSC 1051 slides and the slides accompanying Java Software Solutions, 9 th edition by Lewis & Loftus

Outline Pixels & bits & colors JavaFX Introduction Shapes

Pixels and Graphics Programs represent pictures as grids of picture elements or pixels Picture resolution: Relates to how many pixels are used

Display size (300, 120) vs. (500, 320) Scene scene = new Scene(root, 300, 120, Color.LIGHTGREEN); width height

Coordinate System The origin of the Java coordinate system is in the upper left corner All visible points have positive, int coordinates (0, 0) 112 X 40 (112, 40) Y

Representing Images Bitmap 1 bit Grayscale 8 bits RGB Color 3 colors: red, green, blue 24 bits srgb Color 3 colors: red, green, blue + alpha 32 bits TRANSPARENCY (alpha)

Example: Representing Pixels in RGB red=116 green=86 blue=142 y = 8 Color ( 01110100, 01010110, 10001110 ) x = 11 fff

srgb Color in JavaFX Color: Each pixel has a color associated with it We can specify a color using the Color.rgb method: Each color has a value from 0-255 Scene scene = new Scene(root,300,120,Color.rgb(0,0,255)); Or we can use a (predefined) Color constant Scene scene = new Scene(root,300,120, Color.BLUE); See Color class in the JavaFX API: https://docs.oracle.com/javase/8/javafx/api/javafx/scene/paint/color.html

Representing Color The static rgb method in the Color class returns a Color object with a specific RGB value: Color purple = Color.rgb(183, 44, 150); Scene scene = new Scene(root,300,120,Color.rgb(0,255,0)); The color method uses percentages: Color maroon = Color.color(0.6, 0.1, 0.0); Both methods allow an extra parameter to specify alpha value: ALPHA Color purple = Color.rgb(183, 44, 150, 0.3); Color maroon = Color.color(0.6, 0.1, 0.0, 0.8);?

Example: HelloJavaFX HelloJavaFX program makes use of Inheritance public class HelloJavaFX extends Application New class HelloJavaFX Based on an existing parent class Application Reuses items from the parent class attributes (variables) methods (code) JavaFX programs inherit core graphical functionality from the Application class

Example: HelloJavaFX Two methods A JavaFX program has a start method The main method is only needed to launch the JavaFX application and call the start method public void start(stage primarystage) The start method accepts the primary stage (window) See HelloJavaFX.java

//************************************************************************ // HelloJavaFX.java Author: Lewis/Loftus // // Demonstrates a basic JavaFX application. //************************************************************************ import javafx.application.application; import javafx.scene.group; import javafx.scene.scene; import javafx.scene.paint.color; import javafx.scene.text.text; import javafx.stage.stage; public class HelloJavaFX extends Application { //-------------------------------------------------------------------- // Creates and displays two Text objects in a JavaFX window. //-------------------------------------------------------------------- public void start(stage primarystage) { Text hello = new Text(50, 50, "Hello, JavaFX!"); Text question = new Text(120, 80, "How's it going?"); continued Group root = new Group(hello, question); Scene scene = new Scene(root, 300, 120, Color.LIGHTGREEN);

continued } primarystage.settitle("a JavaFX Program"); primarystage.setscene(scene); primarystage.show(); } //-------------------------------------------------------------------- // Launches the JavaFX application. This method is not required // in IDEs that launch JavaFX applications automatically. //-------------------------------------------------------------------- public static void main(string[] args) { launch(args); }

Intro to JavaFX NOTE: position of each Text object is specified explicitly Text hello = new Text(50,50,"Hello, JavaFX!"); In this example, two Text objects are added to a Group Group is used to create one name for several items Order in the group is the order of adding to the scene Group root = new Group(hello,question); object

Examine two lines Group root = new Group(hello,question); Scene scene = new Scene(root, 300, 120, Color.LIGHTGREEN); The group serves as the root node of a Scene The scene is displayed on the Stage primarystage (window) The size and background color of the scene can be set when the Scene object is created

Basic Shapes JavaFX shapes are represented by classes in one of the packages we import import javafx.scene.shape.*; A line segment is defined by the Line class, whose constructor accepts the coordinates of the two endpoints: Line(startX, starty, endx, endy) DEFINED For example: USED Line myline = new Line(10, 20, 300, 80);

Basic Shapes A rectangle is specified by its upper left corner and its width and height: Rectangle(x, y, width, height) Rectangle r = new Rectangle(30, 50, 200, 70); A circle is specified by its center point and radius: Circle(centerX, centery, radius) Circle c = new Circle(100, 150, 40);

Basic Shapes An ellipse is specified by its center point and its radius along the x and y axis: Ellipse(centerX, centery, radiusx, radiusy) Ellipse e = new Ellipse(100, 50, 80, 30); Shapes are drawn in the order in which they are added to the group The stroke and fill of each shape can be set See Einstein.java

//************************************************************************ // Einstein.java Author: Lewis/Loftus // // Demonstrates the use of various shape classes. //************************************************************************ import javafx.application.application; import javafx.scene.group; import javafx.scene.scene; import javafx.scene.paint.color; import javafx.scene.shape.*; import javafx.scene.text.text; import javafx.stage.stage; public class Einstein extends Application { //-------------------------------------------------------------------- // Creates and displays several shapes. //-------------------------------------------------------------------- public void start(stage primarystage) { Line line = new Line(35, 60, 150, 170); continued Circle circle = new Circle(100, 65, 20); circle.setfill(color.blue);

continued Rectangle rect = new Rectangle(60, 70, 250, 60); rect.setstroke(color.red); rect.setstrokewidth(2); rect.setfill(null); Changes outline width Ellipse ellipse = new Ellipse(200, 100, 150, 50); ellipse.setfill(color.palegreen); Text quote = new Text(120, 100, "Out of clutter, find " + "simplicity.\n-- Albert Einstein"); Group root = new Group(ellipse, rect, circle, line, quote); Scene scene = new Scene(root, 400, 200); } primarystage.settitle("einstein"); primarystage.setscene(scene); primarystage.show(); } // We will typically exclude the main method. Use it to launch // the application if needed.

continued Rectangle rect = new Rectangle(60, 70, 250, 60); rect.setstroke(color.red); rect.setstrokewidth(2); rect.setfill(null); Ellipse ellipse = new Ellipse(200, 100, 150, 50); ellipse.setfill(color.palegreen); Text quote = new Text(120, 100, "Out of clutter, find " + "simplicity.\n-- Albert Einstein"); Group root = new Group(ellipse, rect, circle, line, quote); Scene scene = new Scene(root, 400, 200); } primarystage.settitle("einstein"); primarystage.setscene(scene); primarystage.show(); } // We will typically exclude the main method. Use it to launch // the application if needed.

HelloJavaFX Sketch Find reference points 0 0 50 100 150 200 250 300 350 400 450 500 550 600 50 (60,70) (200,100) 100 (120,100) 150 200 (150,170) 250 300 350 400 Practice: 1. Add the center of the circle and other endpoint of line 2. Verify width and height of all objects

Groups order matters Group root = new Group(ellipse, rect, circle, line, quote); First thing drawn is the ellipse then the rectangle What would happen if I had the ellipse last? Groups can be nested within groups Translating a shape or group shifts its position along the x or y axis A shape or group can be rotated using the setrotate method See Snowman.java

//************************************************************************ // Snowman.java Author: Lewis/Loftus // // Demonstrates the translation of a set of shapes. //************************************************************************ import javafx.application.application; import javafx.stage.stage; import javafx.scene.group; import javafx.scene.scene; import javafx.scene.paint.color; import javafx.scene.shape.*; public class Snowman extends Application { //-------------------------------------------------------------------- // Presents a snowman scene. //-------------------------------------------------------------------- public void start(stage primarystage) { Ellipse base = new Ellipse(80, 210, 80, 60); base.setfill(color.white); continued Ellipse middle = new Ellipse(80, 130, 50, 40); middle.setfill(color.white);

continued Circle head = new Circle(80, 70, 30); head.setfill(color.white); Circle righteye = new Circle(70, 60, 5); Circle lefteye = new Circle(90, 60, 5); Line mouth = new Line(70, 80, 90, 80); Circle topbutton = new Circle(80, 120, 6); topbutton.setfill(color.red); Circle bottombutton = new Circle(80, 140, 6); bottombutton.setfill(color.red); Line leftarm = new Line(110, 130, 160, 130); leftarm.setstrokewidth(3); Line rightarm = new Line(50, 130, 0, 100); rightarm.setstrokewidth(3); (snowman in original position) continued Rectangle stovepipe = new Rectangle(60, 0, 40, 50); Rectangle brim = new Rectangle(50, 45, 60, 5); Group hat = new Group(stovepipe, brim); hat.settranslatex(10); hat.setrotate(15); Move and rotate hat

(snowman in original position) continued Move Snowman } } Group snowman = new Group(base, middle, head, lefteye, righteye, mouth, topbutton, bottombutton, leftarm, rightarm, hat); snowman.settranslatex(170); snowman.settranslatey(50); Circle sun = new Circle(50, 50, 30); sun.setfill(color.gold); Rectangle ground = new Rectangle(0, 250, 500, 100); ground.setfill(color.steelblue); Group root = new Group(ground, sun, snowman); Scene scene = new Scene(root, 500, 350, Color.LIGHTBLUE); primarystage.settitle("snowman"); primarystage.setscene(scene); primarystage.show();

Summary Pixels & bits & colors JavaFX Introduction Shapes