COMP6700/2140 GUI and Event Driven Programming

Similar documents
COMP6700/2140 Scene Graph, Layout and Styles

CS 4300 Computer Graphics

COMP6700/2140 Code as Data

COMP6700/2140 Packages, Modules and Jigsaw

Graphical User Interfaces (GUIs)

COMP6700/2140 Std. Lib., I/O

Graphical User Interface (GUI)

COMP6700/2140 Methods

Graphical User Interface (GUI)

JavaFX. JavaFX Overview Release E

COMP6700/2140 Objects

Object-Oriented Programming Design. Topic : Graphics Programming GUI Part I

Windows and Events. created originally by Brian Bailey

COMP6700/2140 Recursive Operations

COMP6700/2140 JDK Tools

COMP6700/2140 Data and Types

COMP6700/2140 Abstract Data Types: Lists and Iteration

Original GUIs. IntroGUI 1

COMP6700/2140 First Program

COMP6700/2140 Abstract Data Types: Queue, Set, Map

CSE 331 Software Design & Implementation

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

Java Swing Introduction

CS415 Human Computer Interaction

Widget. Widget is a generic name for parts of an interface that have their own behaviour. e.g., buttons, progress bars, sliders, drop-down

Graphical User Interfaces in Java Part 2

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

COMP6700/2140 Generic Methods

Widgets. Overview. Widget. Widgets Widget toolkits Lightweight vs. heavyweight widgets Swing Widget Demo

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.

Widget Toolkits CS MVC

Developing applications using JavaFX

CSE 331 Software Design & Implementation

IT101. Graphical User Interface

IBM JZOS Meets Web 2.0

Designing Interactive Systems II

Widgets. Widgets Widget Toolkits. 2.3 Widgets 1

Review. Designing Interactive Systems II. Introduction. Web 2.0 in keywords GWT Cappuccino HTML5. Cross platform GUI Toolkit

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

GUI Implementation Support

Heavyweight with platform-specific widgets. AWT applications were limited to commonfunctionality that existed on all platforms.

Widgets. Widgets Widget Toolkits. User Interface Widget

Example Programs. COSC 3461 User Interfaces. GUI Program Organization. Outline. DemoHelloWorld.java DemoHelloWorld2.java DemoSwing.

Lecture 19 GUI Events

GUI Program Organization. Sequential vs. Event-driven Programming. Sequential Programming. Outline

COMP6700/2140 Enums. Alexei B Khorev and Josh Milthorpe. Research School of Computer Science, ANU. March 2017

(Incomplete) History of GUIs

CS260. UI Toolkits. Björn Hartmann University of California, Berkeley EECS, Computer Science Division Fall 2010

Advanced Java for Bioinformatics Winter 2017/18. Prof. Daniel Huson

Beautiful User Interfaces with JavaFX

Computational Expression

JavaFX. JavaFX Interoperability with SWT Release 2.2 E

Introduction to Graphical Interface Programming in Java. Introduction to AWT and Swing

The Joy of. An Overview of the X Window System. Niall Mansfield

Hardware Accelerated Graphics for High Performance JavaFX Mobile Applications

Introduction to GUIs. Principles of Software Construction: Objects, Design, and Concurrency. Jonathan Aldrich and Charlie Garrod Fall 2014

COMP6700/2140 Control Flow

Developing Applications for ios

COMP6700/2140 Program Design

Multimedia-Programmierung Übung 3

Fall UI Design and Implementation 1

Chapter 1 Introduction to Computers, Programs, and Java

Running Java Programs

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

Java.net - the Source for Java(tm) Technology Collaboration

Java FX 2.0. Dr. Stefan Schneider Oracle Deutschland Walldorf-Baden

CSE 331 Software Design and Implementation. Lecture 19 GUI Events

COMP6700/2140 Operators, Expressions, Statements

Rendering a 3-Dimensional Cube Applet Using Light Weight Java Graphing Library (LWJGL) with Java Swing with NetBeans IDE 6.1

CO Java SE 7: Develop Rich Client Applications

An applet is a program written in the Java programming language that can be included in an HTML page, much in the same way an image is included in a

DESIGN AND IMPLEMENTATION OF SAGE DISPLAY CONTROLLER PROJECT

EPITA Première Année Cycle Ingénieur. Atelier Java - J5

Merge Sort Quicksort 9 Abstract Windowing Toolkit & Swing Abstract Windowing Toolkit (AWT) vs. Swing AWT GUI Components Layout Managers Swing GUI

Outline. Topic 9: Swing. GUIs Up to now: line-by-line programs: computer displays text user types text AWT. A. Basics

Anatomy of a GUI (Graphical User Interface) Rony G. Flatscher, WU 2018 International Rexx Symposium

CS415 Human Computer Interaction

Beyond CSE143. What s Left To Do? Templates. Using Templates. A Template Class. A Problem with Reusing Code CSE 143

MODEL UPDATES MANIPULATES USER


Automated GUI testing. How to test an interactive application automatically?

GUI Programming. Chapter. A Fresh Graduate s Guide to Software Development Tools and Technologies

COMP6700/2140 Sorting and Searching

THE CPU SPENDS ALMOST ALL of its time fetching instructions from memory

CSE : Python Programming

Educational Fusion. Implementing a Production Quality User Interface With JFC

Event Dispatch. Interactor Tree Lightweight vs. Heavyweight Positional Dispatch Focus Dispatch. 2.4 Event Dispatch 1

Level 3 Computing Year 2 Lecturer: Phil Smith

Eng. Mohammed Alokshiya

Organization of User Interface Software

Creating Professional Swing UIs Using the NetBeans GUI Builder

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

SVG in Data Acquisition and Control Systems. Tao Jiang Boston Scientific

Interface Builders and Interface Description Languages

COMP3421 Computer Graphics

G51PRG: Introduction to Programming Second semester Applets and graphics

Programming Language Concepts: Lecture 8

C15: JavaFX: Styling, FXML, and MVC

The JFrame Class Frame Windows GRAPHICAL USER INTERFACES. Five steps to displaying a frame: 1) Construct an object of the JFrame class

IQTIDAR ALI Lecturer IBMS Agriculture University Peshawar

Transcription:

COMP6700/2140 GUI and Event Driven Programming Alexei B Khorev and Josh Milthorpe Research School of Computer Science, ANU April 2017 Alexei B Khorev and Josh Milthorpe (RSCS, ANU) COMP6700/2140 GUI and Event Driven Programming April 2017 1 / 12

Topics 1 Graphical User Interface Programming 2 Asynchronous Control-Flow: Event-Driven Programming 3 Java Platform for GUI and Rich Client Programming: Abstract Window Toolkit (AWT) Swing (and Java Foundation Classes) JavaFX 4 JavaFX and Rich Client Applications 5 Scene Graph Alexei B Khorev and Josh Milthorpe (RSCS, ANU) COMP6700/2140 GUI and Event Driven Programming April 2017 2 / 12

Graphical User Interface Nowadays, all computer programmes which are intended for interaction with the human user are created with Graphical User Interface (while In the Beginning was Command Line, by Neal Stephenson) According to Wiki: allows for interaction with a computer or other media formats which employs graphical images, widgets, along with text to represent the information and actions available to a user The actions are usually performed through direct manipulation of the graphical elements The history of GUI development so far is very worth reading Since standard computers have a well defined and constrained (less constrained now, after introduction of iphone and ipad) interface, the type of GUI which can be deployed on them is often called WIMP (window, icon, menu, pointing device) One of the very first GUI as it was created by Xerox 6085 ( Daybreak ) workstation in 1985 It inspired the first mass-produced computer with native GUI Macintosh, by Apple Comp As Steve Jobs explained regarding this influence by quoting Picasso: Ordinary people borrow, real artist steals Alexei B Khorev and Josh Milthorpe (RSCS, ANU) COMP6700/2140 GUI and Event Driven Programming April 2017 3 / 12

Java in the GUI Game Was there from its birth 1995: as the part of the first release, Java contained Application Window(ing?) Toolkit, AWT, a collection of containers, widgets, events and event handlers (Java API also contained javageom package for 2D drawing, so called Java2D) Implementation of AWT was heavy-weight, ie, in native code Strong OS dependence in look and feel Still has some use today (eg, Apple programming advice on DialogBox use) 1998: new, partially dependent on AWT, set of containers and widgets (also some events, but those from AWT are still in active use), called Swing (not sure why?) was included in Java SDK 12 Swing API lives in javaxswing and javaxswing* packages Swing is light weight, eg, most of its classes in implemented in Java First releases had performance issues, but over the years achieved significant improvement and expansion Note: reliance on AWT events results in otherwise pure Swing applications have OS specific traits of behaviour Example: MouseSpyjava 2012: Java SDK 17 is released with a new, pure Java, GUI and Rich Client API called JavaFX The actual version is 2, so there is some history: Conceived by Chris Oliver (SeeBeyond) as a scripting language FFF and API (c 2006) Bought by Sun, and the language renamed as JavaFX (2007); versions 10-13 released between 2008 and Sun s acquisition by Oracle in 2010 Had its own compiler to bytecode JavaFX 2 released as API only ( Forget that stupid little language, S Blackburn) Complete alternative to AWT/Swing JavaFX programs can be run as standalone, or deployed to be executed in a browser Alexei B Khorev and Josh Milthorpe (RSCS, ANU) COMP6700/2140 GUI and Event Driven Programming April 2017 4 / 12

Program Architecture Command-Line Application Event-Driven Application Command-line: Application has control at all stages of execution User s interaction with the application is pre-programmed Event-Driven: After initialising the user-interface, application passes control over to the operation system System waits for the user actions and other events, then calls an appropriate function This is Event-Driven Programming GUI is type of ED application (non-gui examples: servers, stream parsers etc) Alexei B Khorev and Josh Milthorpe (RSCS, ANU) COMP6700/2140 GUI and Event Driven Programming April 2017 5 / 12

Event-Driven Programming Event-driven programming involve a new type of flow-of-controls events Events are asynchronous (happen at unpredictable time), they manifest themselves by altering the state of execution environment They are detected though this change Event-driven programs have the following distinctions: Control structure is inverted system has control, not the application System waits for an event (like user action, or lapsing a time interval, or else), then calls the appropriate routine in the application This can make otherwise simple programs much more complicated In GUI applications, one needs a set of classes (widgets) which can detect user s input, and a set of classes, called listeners or event-handler, which define what the system will do in response to an event Event-driven programs are not only GUI Events can be generated by a stream of data Eg, the XML-scanning API called SAX, in orgxmlsax, is an event-driven library It provides several listeners which allow to program client s response to events like start of an XML document, start of an XML element, a data element and so on The event-driven approach makes the task of complex data processing easier GUI Application events: user input eg click on a button internal events eg timeouts window events eg expose Alexei B Khorev and Josh Milthorpe (RSCS, ANU) COMP6700/2140 GUI and Event Driven Programming April 2017 6 / 12

Event-Driven and (Functional) Reactive Programming The technique called (Functional) Reactive Programming has gained traction in recent years with the advent of functional languages or functional language features in traditional languages like Java The Reactive Programming is an event-driven programming (ie, programming with an asynchronous event streams) in which you are given standard functional programming tricks like treating a stream a sequence of ongoing events ordered in time as an object or as code (a function) so it can be passed to another stream; composing (merging) two (many) streams into one; filtering streams; mapping one stream (consisting of objects of one kind) into another (consisting of objects of a different kind) In FRP, a stream can emit events using the interface: value() (or next()) error() completed() FRP is a functional (better?) alternative to the programming which utilises the Observer pattern (discussed later) Alexei B Khorev and Josh Milthorpe (RSCS, ANU) COMP6700/2140 GUI and Event Driven Programming April 2017 7 / 12

Event Handling Models Polling (old, single-threaded) Application has the main loop that checks repeatedly for input or timeouts, then calls the appropriate routine Examples include most (pre OS-X) Macintosh programs, Unix programs that just use basic X window Leads to a more complex application, messy interfaces to the library Largely replaced by the callback mechanism Callbacks (modern, multi-threaded) A callback is when a routine in the application is called not from within the application, but from the library (by a widget when it detects a signal) The application must first tell the toolkit what events it wants to handle and which routines to call Main loop and decoding of events are done by the library This happens in more modern higher-level Unix GUI libraries like Xt, Qt, Motif or GTK; also the Microsoft Foundation Classes, Cocoa Framework (MacOSX) In Java programming callbacks is done using events and event listeners Alexei B Khorev and Josh Milthorpe (RSCS, ANU) COMP6700/2140 GUI and Event Driven Programming April 2017 8 / 12

GUI Concepts widget a GUI component like a window, a push button, a label, a scroll-bar, a menu item pixel a single dot on the display screen; displays typically have 800 600, 1024 768, 1280 1024 pixels depth the number of bits per pixel - depth 1 = black & white - depth 8 = 2 8 = 256 colours - depth 24 = 2 24 = 16,777,216 colours colour map translation between pixel values and actual screen colours on a low-depth display bitmap an image one pixel deep pixmap an image of arbitrary depth (effectively as a 2D array of pixels, although you may not be able to access them like array elements) font a mapping from character (or symbol) shapes to bitmaps event change in computation environment caused by user or smth else which induces application response An event has the source (widget which registers it) and the target, an application component which will react to it (change as the result) event handler part of application which defines how and what is changed as the result of event Alexei B Khorev and Josh Milthorpe (RSCS, ANU) COMP6700/2140 GUI and Event Driven Programming April 2017 9 / 12

JavaFX: Scene Graph The JavaFX Scene Graph (modelled on graphical applications and libraries like vector editing tools, 3D libraries, and video games) is the model (discussed later, in Model-Veiw-Controller architecture) of all graphical objects which exist in an application It contains information about what objects to display, what areas of the screen need repainting, and how to render it all Individual objects (buttons, shapes, text etc) are leaves; groups of objects are nodes The scene graph is rooted by a container, usually javafxscenegroup or javafxsceneregion, which is embedded into a scene object (a window) Once set, an entire scene graph is passed as a stage parameter to the (overridden) method javafxapplicationapplicationstart() method as the starting point of execution Alexei B Khorev and Josh Milthorpe (RSCS, ANU) COMP6700/2140 GUI and Event Driven Programming April 2017 10 / 12

The Structure of a JavaFX Program 1 Your main class must extend javafxapplicationapplication 2 Optionally include the overridden method called Applicationinit() (a public void method with an empty body), which can be overridden, but must not include UI statements (like constructing Stage or Scene, defining callbacks etc), and may include fxml- and css- bindings Note that a different (can be private, take parameters, and even have another name) method init can be defined inside the application class and called inside start() (like private void init(stage primarystage) in MouseEventsjava) it s just an ordinary, coder-defined auxiliary method to modularise the stage assembly 3 Applicationstart(Stage stage) is the method which launches a JavaFX application In principle, one has to include main for a full ceremony: public static void main(string[] args) { launch(args); } But it is only necessary if the run-time platform (an IDE) cannot deploy your application properly An IDE like Netbeans ignores main; the latter is still required, however, when you need to pass command-line arguments, in which case, you should use the method javafxapplicationapplicationgetparameters() 4 Once launched, a JavaFX application will start main, event-processing and other threads, and run until a callback will cause Platformexit() to execute, which will call Applicationstop() to shut down the application Alexei B Khorev and Josh Milthorpe (RSCS, ANU) COMP6700/2140 GUI and Event Driven Programming April 2017 11 / 12

Where to look for this topic in the textbook? Hortsmann s Core Java for the Impatient (not covered) Hortsmann s Java SE 8 for the Really Impatient, Ch 4 Oracle s JavaFX Tutorial Alexei B Khorev and Josh Milthorpe (RSCS, ANU) COMP6700/2140 GUI and Event Driven Programming April 2017 12 / 12