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

Slides:



Advertisements
Similar presentations
Microsoft Expression Web-Illustrated Unit J: Creating Forms.
Advertisements

Customizing the MOSS 2007 Search Results November 2007 Rafael Perez.
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.
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
1 ADVANCED MICROSOFT WORD Lesson 15 – Creating Forms and Working with Web Documents Microsoft Office 2003: Advanced.
Written by Liron Blecher
Favorite Twitter® Searches App Android How to Program © by Pearson Education, Inc. All Rights Reserved.
Java Programming, 3e Concepts and Techniques Chapter 3 Section 65 – Manipulating Data Using Methods – Java Applet.
Copyright © Curt Hill First Window Builder Program Easy GUIs in Eclipse.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
Topics Introduction Scene Graphs
Class Builder Tutorial Presented By- Amit Singh & Sylendra Prasad.
Sadegh Aliakbary Sharif University of Technology Fall 2011.
Designing user interfaces using: Simple views 1. Views Basic views – TextView – EditText – Button – ImageButton – CheckBox – ToggleButton – RadioButton.
© 2010 Delmar, Cengage Learning Chapter 11 Creating and Using Templates.
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
Java How to Program, 10/e © Copyright by Pearson Education, Inc. All Rights Reserved.
Lecture 8:Event Driven Programming Michael Hsu CSULA.
Notices Assn 3 is posted – due tomorrow. Quiz marking underway (still – sigh…). Alternate solution code was added on Tuesday to the assignment 3 statement.
Notices Assn 2 is due tomorrow, 7pm. Moodle quiz next week – written in the lab as before. Everything up to and including today’s lecture: Big Topics are.
Interstage BPM v11.2 1Copyright © 2010 FUJITSU LIMITED FORMS.
Today Enumerated Types - Summary. Start Nested Classes: Inner Classes, Local Classes, Anonymous Classes, Lambda Functions Next: Interfaces, Abstract Classes.
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.
Notices Assn 2 is due Friday, 7pm. Moodle quiz next week – written in the lab as before. Everything up to and including Thursday’s lecture: Big Topics.
Product Training Program
Java FX: Scene Builder.
ASP.NET Forms.
Lecture 8:Event Driven Programming
Forms and Reports 09.
Chapter 8: Writing Graphical User Interfaces
Single Sample Registration
Mobile Application Development Chapter 4 [Android Navigation and Interface Design] IT448-Fall 2017 IT448- Fall2017.
Core LIMS Training: Advanced Administration
CISC124 Quiz 2 grading underway.
Chap 7. Building Java Graphical User Interfaces
CMPE212 – Stuff… Assn 3 due and Quiz 2 in the lab next week.
Winter 2018 CMPE212 9/21/2018 CMPE212 – Stuff…
Graphical User Interfaces -- Introduction
EE 422C Java FX.
CMPE212 – Stuff… Assn 3 sample solution is posted.
CISC124 Assignment 4 on Inheritance due next Monday, the 12th at 7pm.
CISC124 Assignment 4 on Inheritance due next Monday, the 12th at 7pm.
CISC124 Last Quiz this week. Topics listed in last Tuesday’s lecture.
CISC124 Last Quiz this week. Topics listed in last Tuesday’s lecture.
CMPE212 – Stuff… Assignment 4 due March 23 – this Friday.
CISC124 Last Quiz next week. Topics listed in Tuesday’s lecture.
CISC124 Assignment 4 on Inheritance due today at 7pm.
Electronics II Physics 3620 / 6620
CISC124 Assignment 4 on Inheritance due next Friday.
Using Cascading Style Sheets (CSS)
CISC124 Assignment 3 due tomorrow at 7pm.
CISC124 Assignment 4 on Inheritance due next Friday.
Lecture 9 GUI and Event Driven CSE /16/2019.
CISC124 Quiz 3 marking underway. Assn 5 due Friday. Fall 2018
Advanced Programming in Java
CISC124 Assignment 3 sample solution will be posted tonight after 7pm.
CMPE212 – Reminders Assignment 2 sample solution is posted.
CMPE212 – Reminders Assignment 3 due next Friday.
Winter 2019 CMPE212 4/20/2019 CMPE212 – Reminders
Planning a Group Policy Management and Implementation Strategy
First Window Builder Program
Java Looking at our first console application in Eclipse
Winter 2019 CMPE212 5/3/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.
Chapter 12 JavaFX Graphical User Interfaces: Part 1
Unit J: Creating a Database
Presentation transcript:

CISC124 Last Quiz this week. Topics listed in last Tuesday’s lecture. Fall 2018 CISC124 11/26/2018 CISC124 Last Quiz this week. Topics listed in last Tuesday’s lecture. Fall 2018 CISC124 - Prof. McLeod Prof. Alan McLeod

Today Getting a Button to do something… Using Scenebuilder. Event Handlers. Next Topic: Input Nodes. Fall 2018 CISC124 - Prof. McLeod

Getting a Button to do Something Use the .setOnAction() mutators to add an event handler to the button. The handler for a mouse click event must implement EventHandler<ActionEvent>. Four ways of doing this: Another separate class. (we’ll skip this one…) A private inner class. An anonymous class. A Lambda function. Fall 2018 CISC124 - Prof. McLeod

Project11InnerClass The handler object can be private and is contained within the same class that defines the rest of the window. Fall 2018 CISC124 - Prof. McLeod

Project11AnonymousClass Gets rid of private inner class and the need for the Label object to be an attribute. But it has added some “bloat” to the start() method. (An anonymous class has to be short!) Fall 2018 CISC124 - Prof. McLeod

Project11Lambda Wow! That was easy! Button changeButton = new Button("Change Label"); changeButton.setOnAction(event -> { if (changeLabel.getText().equals("Hello!")) changeLabel.setText("Goodbye!"); else changeLabel.setText("Hello!"); }); Wow! That was easy! Fall 2018 CISC124 - Prof. McLeod

Project11Lambda, Cont. This works because the EventHandler<T extends Event> interface is a Functional Interface – an interface consisting of just a single abstract function: void handle (T event); Event is the parent class for many events, so this same handler can be used for a wide variety of event types. Fall 2018 CISC124 - Prof. McLeod

Using SceneBuilder Start by adding a .fxml file to your project: Fall 2018 CISC124 - Prof. McLeod

Using SceneBuilder, Cont. Give the file a name and choose a Pane: Fall 2018 CISC124 - Prof. McLeod

Using SceneBuilder, Cont. Not much in the file to start with: The language is xml or “Extensible Markup Language”, the “fxml” version! This can be edited manually, but SceneBuilder is much easier. Fall 2018 CISC124 - Prof. McLeod

Using SceneBuilder, Cont. (Install SceneBuilder first!) Right-click on the file and choose “Open with SceneBuilder”. Fall 2018 CISC124 - Prof. McLeod

SceneBuilder (after some work) Fall 2018 CISC124 - Prof. McLeod

Using SceneBuilder, Cont. Choose the pane (GridPane in this case) and on the Properties tab at the right and choose the stylesheet (“application.css”) for your project. The css settings will override any settings made in the fxml file. You will see little blue boxes to show which properties have been dictated by the css file. You can also use the “CSS Analyzer” to display the hierarchy of css changes to any control. Fall 2018 CISC124 - Prof. McLeod

Using SceneBuilder, Cont. Choose controls and drag them into the pane. Edit control properties using the “Properties” and “Layout” tabs. If you are using SceneBuilder, do not edit the fxml file directly. In SceneBuilder, save your changes, using <Cntrl>s, and when you go back to eclipse, use <F5> to refresh the view of the .fxml file. You can also preview your window using “Preview” or <Cntrl>p in SceneBuilder. Fall 2018 CISC124 - Prof. McLeod

Using SceneBuilder, Cont. For each control that needs to interact with Java code, create an fx:id for that control in the “Code” tab. The name has to be unique to your project. Fall 2018 CISC124 - Prof. McLeod

Using SceneBuilder, Cont. To associate a controller class with your fxml file, choose the “Controller” tab at the bottom, left. Provide a package and a class name here (“application.Project11Controller” in this case). Go back to eclipse and create the *.java file with the same name in the package (application, for example) that you specified. Fall 2018 CISC124 - Prof. McLeod

Using SceneBuilder, Cont. In SceneBuilder, go “View”, then “Show Sample Controller Skeleton”. Choose “Full” and then “Copy”. Paste the code over your controller *.java file. Note that SceneBuilder will not create or edit *.java files in your project. Fall 2018 CISC124 - Prof. McLeod

Using SceneBuilder, Cont. The *.fxml file allows you to remove node creation, sizing and positioning out of the Main.java file. Now you can remove functional code from here as well! You have two choices: Write lambda functions in the initialize() method. Use Scenebuilder to create a separate method skeleton and then fill it in. Fall 2018 CISC124 - Prof. McLeod

Event Handlers In the initialize() method in the controller class, assuming the fx:id is “myButton”: myButton.setOnAction(event -> { if (myLabel.getText().equals("Hello!")) myLabel.setText("Goodbye!"); else myLabel.setText("Hello!"); }); Fall 2018 CISC124 - Prof. McLeod

Event Handlers, Cont. You can also attach a handler to a control in the fxml file. Using SceneBuilder with the control of interest: Choose one of the possible events of interest and type in a name for the handler. “On Action” is the general purpose handler often used with buttons. Fall 2018 CISC124 - Prof. McLeod

Event Hanlders, Cont. This adds “onAction="#myButtonAction" to the fxml tag for the button. Look in the controller “skeleton” for: @FXML void myButtonAction(ActionEvent event) { } Add this to your controller class and fill it in: Fall 2018 CISC124 - Prof. McLeod

Event Hanlders, Cont. @FXML void myButtonAction(ActionEvent event) { if (myLabel.getText().equals("Hello!")) myLabel.setText("Goodbye!"); else myLabel.setText("Hello!"); } The code in controller is now outside initialize() and is even simpler than the lambda version. See Project11LambdaFXML. Fall 2018 CISC124 - Prof. McLeod

Using SceneBuilder, Cont. In your Main.java file replace the declaration of “root” with (assuming you are using GridPane): GridPane root = (GridPane) FXMLLoader.load(getClass().getResource("../Project11.fxml")); You don’t need any control instantiations in Main.java or any of the code to do with the controls. No more layout or style code either!! Fall 2018 CISC124 - Prof. McLeod

Order of Operations: The order is critical, especially if you have to interpret errors: The application invokes main, which invokes launch, which invokes start, supplying it with the Stage object. The start() method in Main.java identifies and then starts loading the fxml file as part of the creation of the root object. The *.css file is located (listed in fxml) and loaded. The controller class is located (listed in fxml). Fall 2018 CISC124 - Prof. McLeod

Order of Operations, Cont. The rest of the fxml file is processed, creating and configuring the controls. Stylesheet changes are applied. The controller class is instantiated. All controls with a fx:id are injected into the instance of the controller class everywhere there is an @FXML annotation. Events are attached to controls, if the fxml contains event tags. Fall 2018 CISC124 - Prof. McLeod

Order of Operations, Cont. When the injection process is complete the initialize() method in the controller class is invoked. Back in the start method, the root object has been created and now contains the scene graph for the window. The scene object is added to the Stage object. The Stage object is shown. Now containers and controls will have their actual sizes. Fall 2018 CISC124 - Prof. McLeod

SceneBuilder Links Using SceneBuilder in eclipse: https://docs.oracle.com/javase/8/scene-builder-2/work-with-java-ides/sb-with-eclipse.htm Another example: http://docs.oracle.com/javase/8/scene-builder-2/get-started-tutorial/jfxsb-get_started.htm#JSBGS101 User’s Guide: http://docs.oracle.com/javase/8/scene-builder-2/user-guide/index.html Fall 2018 CISC124 - Prof. McLeod

Input Nodes Lots of controls accept input from the user: Button, RadioButton, ToggleButton, CheckBox, ChoiceBox, TextField, TextArea, PasswordField, ListView, TableView, TreeView, TreeTableView, ComboBox, Slider, Menu, Spinner, … You can even use a dialog which opens a separate window. See: http://docs.oracle.com/javase/8/javafx/user-interface-tutorial/ui_controls.htm Fall 2018 CISC124 - Prof. McLeod