CISC124 Last Quiz next week. Topics listed in Tuesday’s lecture.

Slides:



Advertisements
Similar presentations
Introduction to Java 2 Programming
Advertisements

Graphic User Interfaces Layout Managers Event Handling.
CMSC 341 Building Java GUIs. 09/26/2007 CMSC 341 GUI 2 Why Java GUI Development? Course is about Data Structures, not GUIs. We are giving you the opportunity.
Using Eclipse. Getting Started There are three ways to create a Java project: 1:Select File > New > Project, 2 Select the arrow of the button in the upper.
Today Assn 3 posted. Due March 13. Quiz 2 solutions posted. Assignment 2 sample solution is posted. Introduce Event-Driven Programming and GUI Design.
Unit 091 Introduction to GUI Programming Introduction to User Interfaces Introduction to GUI Programming GUI Design Issues GUI Programming Issues Java.
Chapter 13: Advanced GUIs and Graphics J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
Written by Liron Blecher
Java Programming Chapter 10 Graphical User Interfaces.
Chapter 13 Advanced GUIs and Graphics. Chapter Objectives Learn about applets Explore the class Graphics Learn about the class Font Explore the class.
Intro to GUIs (Graphical User Interfaces) Section 2.5Intro. to GUIs: a GUI Greeter Section 3.7Graphical/Internet Java: Einstein's Equation.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 12 Advanced GUIs and Graphics.
Applets and Frames CS 21a: Introduction to Computing I First Semester,
Copyright © Curt Hill First Window Builder Program Easy GUIs in Eclipse.
Chapter 9: Visual Programming Basics Object-Oriented Program Development Using Java: A Class-Centered Approach.
– Advanced Programming P ROGRAMMING IN Lecture 21 Introduction to Swing.
Graphic User Interface. Graphic User Interface (GUI) Most of us interact with computers using GUIs. GUIs are visual representations of the actions you.
Graphics and Event-Driven Programming in Java John C. Ramirez Department of Computer Science University of Pittsburgh.
CS Lecture 00 Swing overview and introduction Lynda Thomas
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.
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
Java GUI. Graphical User Interface (GUI) a list a button a text field a label combo box checkbox.
GUI Basics. Agenda What GUI How to make in java Creating frames Frequently used GUI components Layout Managers.
Basics of GUI Programming Chapter 11 and Chapter 22.
Creating a Window. A basic window in Java is represented by an object of the class Window in the package java.awt.
Java Swing One of the most important features of Java is its ability to draw graphics.
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
Graphical User Interface (GUI)
Applets. 9/04/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L12: Applets Slide 2 Applets Usually.
5-1 GUIs and Events Rick Mercer. 5-2 Event-Driven Programming with Graphical user Interfaces  Most applications have graphical user interfaces to respond.
Notices Assn 3 is posted – due this Friday. Quiz marking underway (still). See assn 3 forum postings on use of Color class and meaning of second Emitter.
CIS 270—Application Development II Chapter 11—GUI Components: Part I.
Notices Assn 3 is posted – due tomorrow. Quiz marking underway (still – sigh…). Alternate solution code was added on Tuesday to the assignment 3 statement.
Today Javadoc. Packages and static import. Viewing API source code. Upcoming Topics: –protected access modifier –Using the debugger in Eclipse –JUnit testing.
Java Programming Fifth Edition Chapter 13 Introduction to Swing Components.
Notices Assn 4 posted. Due last day of class. Last quiz this week in Moodle, in the lab. Would the student doing the USATS please get them from Emily Crawford.
Dive Into® Visual Basic 2010 Express
Java FX: Scene Builder.
A First Look at GUI Applications
Java Swing.
Lecture 27 Creating Custom GUIs
CISC124 Quiz 2 grading underway.
Ellen Walker Hiram College
CMPE212 – Stuff… Assn 3 due and Quiz 2 in the lab next week.
Chapter 13: Advanced GUIs and Graphics
Course Outcomes of Advanced Java Programming AJP (17625, C603)
EE 422C Java FX.
Chapter 14 JavaFX Basics Dr. Clincy - Lecture.
CMPE212 – Stuff… Assn 3 sample solution is posted.
GUIS: Graphical User Interfaces
CISC124 Last Quiz this week. Topics listed in last Tuesday’s lecture.
CISC124 Last Quiz this week. Topics listed in last Tuesday’s lecture.
CISC124 Last Quiz this week. Topics listed in last Tuesday’s lecture.
Fall 2018 CISC124 12/1/2018 CISC124 Note that the next assignment, on encapsulation, is due next Wednesday at 7pm – not Friday. The next Quiz is not until.
CMPE212 – Stuff… Assignment 4 due March 23 – this Friday.
CISC124 Assignment 4 on Inheritance due next Friday.
CISC124 Quiz 3 marking underway. Assn 5 due Friday. Fall 2018
Steps to Creating a GUI Interface
Advanced Programming in Java
Fall 2018 CISC124 2/24/2019 CISC124 Quiz 1 marking is complete. Quiz average was about 40/60 or 67%. TAs are still grading assn 1. Assn 2 due this Friday,
CISC124 Assignment 3 sample solution will be posted tonight after 7pm.
CMPE212 – Reminders Assignment 3 due next Friday.
Winter 2019 CMPE212 4/20/2019 CMPE212 – Reminders
CMPE212 – Reminders Assignment 2 due today, 7pm.
Winter 2019 CMPE212 5/25/2019 CMPE212 – Reminders
CMPE212 – Reminders Assignment 5, a JavaFX GUI, due this Friday.
CMPE212 – Reminders Assignment 5, a JavaFX GUI, due next Friday.
CMPE212 – Reminders Assignment 2 due next Friday.
Advanced GUIs and Graphics
Presentation transcript:

CISC124 Last Quiz next week. Topics listed in Tuesday’s lecture. Fall 2018 CISC124 12/31/2018 CISC124 Last Quiz next week. Topics listed in Tuesday’s lecture. Last assignment due last day of class. Fall 2018 CISC124 - Prof. McLeod Prof. Alan McLeod

Today Finish Lambda Functions. Method References. Event-Driven Programming. Fall 2018 CISC124 - Prof. McLeod

Lambda Functions, Cont. Filter is an example of a Functional Interface. These interfaces can only contain a single abstract method. Lambdas can only be created using Functional Interfaces. You can use the @FunctionalInterface annotation to make sure your interface is OK. Fall 2018 CISC124 - Prof. McLeod

Pre-Defined Functional Interfaces Turns out the java.util.function package has many pre-defined generic functional interfaces. See the API, svp. The one that matches our check function signature is called Predicate<T>. It has the abstract method signature: boolean test(T) See TestFilter4.java. Even better than the last best one! Fall 2018 CISC124 - Prof. McLeod

Method References ArrayList.sort() accepts a Comparator<T> object that can specify the desired algorithm for comparison of objects of type T. Turns out Comparator is a Functional Interface, so you can build a lambda function for a comparator. See TestSorting.java. Fall 2018 CISC124 - Prof. McLeod

Method References, Cont. But suppose our Person class has a method that matches the Comparator interface: public static int compareByAge(Person p1, Person p2) { return p1.age - p2.age; } In this case you can supply a Method Reference instead of building the lambda function. See TestSortingAgain.java. Fall 2018 CISC124 - Prof. McLeod

Method References, Cont. db.sort(Person::compareByAge); Wow, that was easy! Even easier than a Lambda! The method reference must match the functional interface’s specification. You can use non-static methods or methods from an instance. If you wish to supply a constructor, use: ClassName::new And you can use existing API methods! Fall 2018 CISC124 - Prof. McLeod

Lambda Functions, Cont. You can have multiple lines of code in a lambda, but don’t make them too long. You can use as many lambdas as you wish when invoking a function, as long as they each match up to some functional interface. In GUI programming the most common event handler interface, EventHandler<ActionEvent> is a functional interface, so lambdas can be used to attach event code to handlers. Fall 2018 CISC124 - Prof. McLeod

Event-Driven Programming Fall 2013 CISC124 Event-Driven Programming So far, for assignments, you have written single threaded “batch” programs – the coder (you!) controls the flow of execution. For event-driven programs, the user controls the flow by initiating events. A GUI interface consists of components contained within a frame (or “window”). Components and even the frame itself can respond to events. Fall 2018 CISC124 - Prof. McLeod Prof. Alan McLeod

Possible Events Some things that can trigger code execution: Left mouse click down on a command button. Left mouse click down on any component. Similarly for any mouse button. Similarly for holding a mouse button down. Similarly for mouse button up. Double click on a component… Cursor over a component. Cursor leaving a component. Cursor hovering over a component. Component has focus or has lost focus. Component contents have changed. Alt-key or Cntrl-key or Shift-key, etc… Fall 2018 CISC124 - Prof. McLeod

Events, Cont. Most events you ignore – your interface does not have to respond to every possible keyboard and mouse initiated event – that would be crazy!! To respond to an event in code, you attach an Event Handler object to a component. When an event occurs to a component that has the focus, the handler receives an object which contains information about the source of the event (which mouse button, etc.) You decide which events are of interest and what you want your program to do when these events occur. Fall 2018 CISC124 - Prof. McLeod

GUI Construction Construction of a Graphical User Interface involves: Fall 2013 CISC124 GUI Construction Construction of a Graphical User Interface involves: Creating the design of the window – choosing components (buttons, labels, text boxes, etc.) and where they are positioned in the window. Changing properties, including appearance properties, of the components. Adding and linking functionality to events, where needed. Repeating these steps for each window! Connecting the program flow between windows. Fall 2018 CISC124 - Prof. McLeod Prof. Alan McLeod

History of GUI Components in Java Fall 2013 CISC124 History of GUI Components in Java Next slide has a hierarchy of Historical Interest: These classes are part of the Component hierarchy in javax.swing Swing was a modern improvement of the older AWT (“Abstract Windows Toolkit”) classes. The following diagram is a simplified summary of the structure: Fall 2018 CISC124 - Prof. McLeod Prof. Alan McLeod

java.awt javax.swing Abstract Class Concrete Class Object Component BorderLayout FlowLayout GridLayout Container Window java.awt Frame javax.swing JFrame JComponent Fall 2018 CISC124 - Prof. McLeod

javax.swing JFrame JComponent JPanel AbstractButton JLabel JMenuBar JTextComponent JMenuItem JButton JMenu JTextArea JTextField Fall 2018 CISC124 - Prof. McLeod

JavaFX JavaFX classes are no longer part of this hierarchy. JavaFX is a bold, relatively new world of GUI coding! Swing API code will no longer be updated. Any improvements will be in JavaFX packages only. Library code used to be in a separate API, but now javafx.* packages are included in the distributed JRE (in various javafx.* modules). You still need to configure eclipse to program in JavaFX (later). Fall 2018 CISC124 - Prof. McLeod

JavaFX, Cont. Swing was developed mostly for enterprise/business use, not for personal use and certainly not for mobile devices. JavaFX is available in the API since Java 7. The latest is called JavaFX 10. Jazzier controls and more support for portable devices. Fall 2018 CISC124 - Prof. McLeod

“Client Technologies” For lots of links on JavaFX and Swing see: http://docs.oracle.com/javase/8/javase-clienttechnologies.htm Fall 2018 CISC124 - Prof. McLeod

Getting Started Using JavaFX - Topics Overview / Installation. Start by looking at the Scene/Stage model. What is a Scene Graph? How components are laid out using Pane-based layout managers. Look at the use of CSS style sheets. Attach events to components. Look at the use of FXML files and SceneBuilder. Fall 2018 CISC124 - Prof. McLeod

JavaFX Overview You can separate style and layout from functional code using *.css and *.fxml files. Very modern! Contains a rich set of tools for: Web browsing. Media playing. 2D and 3D drawing and animation. Including many visual effects. Taking advantage of hardware accelerated rendering. Fall 2018 CISC124 - Prof. McLeod

JavaFX Overview, Cont. Already contains separate threads for: The main application. Rendering. Media playback. Over 50 controls, built-in. A dozen built-in chart types. 2D and 3D transformations as well as many other visual effects can be applied to most controls. Fall 2018 CISC124 - Prof. McLeod

Fall 2013 CISC124 JavaFX - Installation You need to add e(fx)clipse to eclipse in order to have the libraries and tools you need to write JavaFX code. You don’t need SceneBuilder but might like to play with it later. See the Resources page on the course web site. The homepage for e(fx)clipse is: http://www.eclipse.org/efxclipse Fall 2018 CISC124 - Prof. McLeod Prof. Alan McLeod

e(fx)clipse Version May 2018: released version 3.3.0... Follow the instructions on the course “Resources” page. Fall 2018 CISC124 - Prof. McLeod

SceneBuilder Version Latest installer build linked to the Gluon site is 10.0.0 (June, 2018) for Java 10. A drag and drop visual editor that edits an *.fxml file in the background. SceneBuilder can be invoked from within eclipse, but essentially runs outside of eclipse. More later… Fall 2018 CISC124 - Prof. McLeod

New JavaFX Project Wizard Sets up quite an elaborate structure for you! Don’t have more than one JavaFX project per eclipse project. Let’s have a look! Fall 2018 CISC124 - Prof. McLeod

New JavaFX Project Wizard, Cont. Your GUI class needs to extend the javafx.application.Application class. Your main() method must invoke the inherited launch() method to start the application. Supply the args from the main parameter list to launch(). The wizard overrides the start() method from Application and the parameter for start() is the Stage object for the window, called “primaryStage”. Fall 2018 CISC124 - Prof. McLeod

New JavaFX Project Wizard, Cont. An item (layouts, controls, images, etc.) is called a “node”. Nodes are added to the Nodes hierarchy (next, next slide), and the root node of this hierarchy is added to the Scene object when it is instantiated (and it is given a size in pixels). The Scene object is then put on the stage using the .setScene() mutator. When the scene is all constructed the “curtains are raised” by invoking .show() on the stage object. Fall 2018 CISC124 - Prof. McLeod

New JavaFX Project Wizard, Cont. The wizard also adds a link to a CSS (“Cascading Style Sheet”) file for the scene, called “application.css”. Initially the file is empty, but you can “skin” the scene using css style specifications for the window and any controls you are using. You can do all this in your GUI class too, but using the css file allows you to separate style code from application code. We’ll look into doing this a bit later. For now we’ll just use the default style (“Modena”). Fall 2018 CISC124 - Prof. McLeod

JavaFX Scene Graph Here is part of the existing Node hierarchy: Node Parent Region Control Pane Labeled Fall 2018 CISC124 - Prof. McLeod

JavaFX Scene Graph, Cont. Left-hand branch are containers – used to contain and organize other controls. Right-hand branch are the controls. Usually a container type object will be the “root”. Fall 2018 CISC124 - Prof. McLeod

JavaFX Scene Graph, Cont. There are many more classes extending nodes in this hierarchy. For example, some classes extending from Labeled: Labeled ButtonBase Label Button CheckBox ToggleButton See the JavaFX API Tree diagrams for all the classes. RadioButton Fall 2018 CISC124 - Prof. McLeod

Aside - JavaFX API Docs Are now included in the normal set of API docs that you can download. Let’s have a look! Fall 2018 CISC124 - Prof. McLeod