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

Slides:



Advertisements
Similar presentations
Quiz #3 - CSS Lecture Code: Get Neighbors’ URLs for MP1
Advertisements

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.
Written by Liron Blecher
CSS The Definitive Guide Chapter 8.  Allows one to define borders for  paragraphs  headings  divs  anchors  images  and more.
SWING IF YOU GET LOST - IMPORTANT LINKS  Swing articles:
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
Topics Introduction Scene Graphs
Fall 2015CISC/CMPE320 - Prof. McLeod1 CISC/CMPE320 Assignment 3 is due Sunday, the 8 th at 7pm. Problems with assn 3? Discuss at your team meeting tonight.
Winter 2016CISC101 - Prof. McLeod1 CISC101 Reminders Quiz 3 next week. See next slide. Both versions of assignment 3 are posted. Due today.
Today… Modularity, or Writing Functions. Winter 2016CISC101 - Prof. McLeod1.
Quiz 3 Topics Functions – using and writing. Lists: –operators used with lists. –keywords used with lists. –BIF’s used with lists. –list methods. Loops.
Notices Assn 3 is posted – due tomorrow. Quiz marking underway (still – sigh…). Alternate solution code was added on Tuesday to the assignment 3 statement.
Lecture 7:Introduction to JavaFX Michael Hsu CSULA.
Today Javadoc. Packages and static import. Viewing API source code. Upcoming Topics: –protected access modifier –Using the debugger in Eclipse –JUnit testing.
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.
Lecture 7:Introduction to JavaFX Michael Hsu CSULA.
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.
Laying out Elements with CSS
Java FX: Scene Builder.
Weebly Elements, Continued
Cascading Style Sheets Boxes
CSS Layouts: Positioning and Navbars
Creating a Basic Form Module
Lecture 7:Introduction to JavaFX
Chapter 1: An Introduction to Visual Basic 2015
3.01 Apply Controls Associated With Visual Studio Form
3.01 Apply Controls Associated With Visual Studio Form
CISC124 Quiz 2 grading underway.
CMPE212 – Stuff… Assn 3 due and Quiz 2 in the lab next week.
Winter 2018 CMPE212 9/21/2018 CMPE212 – Stuff…
EE 422C Java FX.
CMPE212 – Stuff… Exercises 4, 5 and 6 are all fair game now.
CMPE212 – Stuff… Assn 3 sample solution is posted.
Winter 2018 CMPE212 11/12/2018 CMPE212 – Stuff…
Controlling Layout with Style Sheets
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.
CISC101 Reminders Assn 3 due Friday, this week. Quiz 3 next week.
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.
Fall 2018 CISC124 12/3/2018 CISC124 or talk to your grader with questions about assignment grading. Fall 2018 CISC124 - Prof. McLeod Prof. Alan McLeod.
CISC101 Reminders Quiz 2 graded. Assn 2 sample solution is posted.
CISC101 Reminders Assn 3 due tomorrow, 7pm.
CISC124 Last Quiz next week. Topics listed in Tuesday’s lecture.
CISC124 Assignment 4 on Inheritance due today at 7pm.
CISC124 Assignment 4 on Inheritance due next Friday.
CISC124 Assignment 3 due tomorrow at 7pm.
CISC124 Assignment 4 on Inheritance due next Friday.
CISC124 Quiz 3 marking underway. Assn 5 due Friday. Fall 2018
CISC124 Labs start this week in JEFF 155. Fall 2018
Fall 2018 CISC124 2/22/2019 CISC124 Quiz 1 This Week. Topics and format of quiz in last Tuesday’s notes. The prof. (me!) will start grading the quiz.
CISC/CMPE320 - Prof. McLeod
CISC/CMPE320 - Prof. McLeod
Floating and Positioning
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.
Winter 2019 CMPE212 4/5/2019 CMPE212 – Reminders
CMPE212 – Reminders Assignment 2 sample solution is posted.
CMPE212 – Reminders Assignment 3 due next Friday.
CISC101 Reminders Assignment 3 due next Friday. Winter 2019
Winter 2019 CMPE212 4/20/2019 CMPE212 – Reminders
CMPE212 – Reminders Assignment 2 due today, 7pm.
Winter 2019 CMPE212 5/25/2019 CMPE212 – Reminders
CISC101 Reminders Assignment 3 due today.
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.
Presentation transcript:

CISC124 Last Quiz this week. Topics listed in last Tuesday’s lecture. Fall 2018 CISC124 11/27/2018 CISC124 Last Quiz this week. Topics listed in last Tuesday’s lecture. Assn 4 sample solution posted. Final Exam preparation page posted. (Let’s have a look.) Fall 2018 CISC124 - Prof. McLeod Prof. Alan McLeod

Today Look at the “more OOP” version of the assignment 4 sample solution. How JavaFX works. Layout Panes. Fall 2018 CISC124 - Prof. McLeod

Alternate Assn 4 Sample Solution One common approach is to accept any value for an argument and then to check it against a limited collection of legal values. But how about limiting the values that can be supplied for an argument to just legal values in the first place? Implemented through the use of enums and classes with a collection of legal values as constant attributes. Fall 2018 CISC124 - Prof. McLeod

Alternate Assn 4 Sample Solution, Cont. With this approach, you can eliminate most of the argument checking code. Easier to add/edit legal values since they will all be in the same place and not buried in the hierarchy code. When building code, you can access enum and class members to choose from a supplied list of legal values. Use the classes of constant attributes where enum variable names cannot be easily constructed. Fall 2018 CISC124 - Prof. McLeod

Alternate Assn 4 Sample Solution, Cont. Have a quick look at the alternate solution. Look for: Enum<?> as a base type for any enum value. Collections of enums in Finishes and Materials classes. Use of public final static attributes in final classes, or public inner classes for values that cannot be legal enum values. Prevention of public instantiation or extension of these classes. How to name arguments and parameter types so that possible values are restricted. The resulting code simplicity and the easy way legal argument collections can be changed or added. Fall 2018 CISC124 - Prof. McLeod

Getting Started Using JavaFX - Topics Translate the code the wizard gave us. 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

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

JavaFX Scene Graph, Cont. Typically you build your GUI by first instantiating existing node objects. For example, Label myLabel = new Label(“Hello!”); In order to display the node in the window, you need to add the object you instantiated to the existing Scene Graph structure. Fall 2018 CISC124 - Prof. McLeod

JavaFX Scene Graph, Cont. In order to be able to place your nodes (or “controls”) where you want them, you add them to a Pane object. A Pane child object includes a layout manager that decides where nodes can be placed. A Pane object can be added to different type Pane objects as if it was a node itself to give you a great deal of flexibility in your layout. Finally, the root pane object becomes the root of the scene object and the entire Scene Graph that you have constructed can be displayed. Fall 2018 CISC124 - Prof. McLeod

Aside – Generating Import Statements Eclipse is great at helping you generate a missing import statement if you try to use a class that you have not yet imported. But: if you have a choice, make sure to choose the javafx one, rather than the class from javax.swing or java.awt. Fall 2018 CISC124 - Prof. McLeod

Pane Objects In order to design your window you need to understand how the different Pane objects work. From the JavaFX API Tree: Fall 2018 CISC124 - Prof. McLeod

Pane Objects, Cont. Won’t discuss: DialogPane – Used as the base container for customized dialog windows. We can just use the built-in dialogs. We don’t need to design our own. PopupControl.CSSBridge – Seems to be mostly for internal use. Fall 2018 CISC124 - Prof. McLeod

Aside – Layout Managers Each pane is associated with a different layout manager – an algorithm that determines where controls are placed within the pane and often their size. Provides flexibility during design and during runtime when the size of the window is changed or the window is viewed on a different OS (or even just a different monitor resolution!) than the one on which it was designed. Fall 2018 CISC124 - Prof. McLeod

Layout Managers – A Reference A Nice Reference – “Working with Layouts in JavaFX”: http://docs.oracle.com/javafx/2/layout/jfxpub-layout.htm Fall 2018 CISC124 - Prof. McLeod

Aside – Absolute Positioning Used by Microsoft’s Visual Studio .NET, for example. Control positions and sizes (in pixels) are all absolute. The visual editor helps you assign default values and to line up controls. But .NET is designed to run on one OS only… You can still use absolute positioning in JavaFX, but you are giving away some convenience. Fall 2018 CISC124 - Prof. McLeod

BorderPane BorderPane lays out components in top, left, right, bottom, and center positions: Fall 2018 CISC124 - Prof. McLeod

BorderPane, Cont. For example, to add a Button to the Top position: BorderPane bPane = new BorderPane(); Button myButton = new Button(“Click Me!”); bPane.setTop(myButton); A component adopts its preferred size if it is smaller than the available region. Center swells to occupy neighbouring positions if they are empty. Fall 2018 CISC124 - Prof. McLeod

BorderPane, Cont. You can add margins around a component by using an Insets object with the static .setMargin() method. You can also specify alignment within a position using a value from the Pos enum and the static .setAlignment() method. This layout is good for blocking out an entire window into sub-regions and then you use another layout in the regions of interest. Fall 2018 CISC124 - Prof. McLeod

BorderPane, Cont. See FXProjectBorderPane Test control positioning, alignment and sizing. Setting individual control properties one at a time will be painful, especially when the properties are all being set to the same value… Fall 2018 CISC124 - Prof. McLeod

Aside – Running JavaFX Lecture Notes Code Create a blank JavaFX project. Remove any files in the application folder. In a file browser, unzip the archive (*.zip) file to the application folder of the project. At the moment this is just Main.java and some also have application.css. Back in eclipse, use <F5> to refresh the project listing. Fall 2018 CISC124 - Prof. McLeod

Aside - Component Sizing Padding Border Margin Unless you define a preferred size the calculated size is based on the size of the rendered label plus a default padding size between the label and the border. You can also change the size of the margin in code. Fall 2018 CISC124 - Prof. McLeod

AnchorPane Components are anchored at a specified distance from the edge of the Pane using the static methods: “value” is in pixels as a distance from the border of the pane. Why a double? Fall 2018 CISC124 - Prof. McLeod

AnchorPane, Cont. See FXProjectAnchorPane. Here is the interesting part: AnchorPane root = new AnchorPane(); Button leftTopButton = new Button("Left Top"); leftTopButton.setFont(new Font("Consolas", 20)); Button rightBottomButton = new Button("Right Bottom"); rightBottomButton.setFont(new Font("System", 18)); Label leftBottomLabel = new Label("Left Bottom"); leftBottomLabel.setFont(new Font("Times New Roman", 22)); AnchorPane.setLeftAnchor(leftTopButton, 10.0); AnchorPane.setTopAnchor(leftTopButton, 10.0); AnchorPane.setRightAnchor(rightBottomButton, 10.0); AnchorPane.setTopAnchor(rightBottomButton, 10.0); AnchorPane.setBottomAnchor(rightBottomButton, 10.0); AnchorPane.setLeftAnchor(leftBottomLabel, 80.0); AnchorPane.setBottomAnchor(leftBottomLabel, 80.0); root.getChildren().addAll(leftTopButton, leftBottomLabel, rightBottomButton);

AnchorPane, Cont. Note the effect of window re-sizing. Note how two or more anchors can combine to change the size of the control away from its calculated/preferred size. This is another relatively crude layout manager that might be best used to lay panes out in a window. Fall 2018 CISC124 - Prof. McLeod

Aside – Pane “Children” Nodes added to a pane are also called “Children”. Add nodes to a pane by invoking the .add() or .addAll() methods on the children collection owned by the pane. The .addAll() method can also accept a Collection<? extends Node> object. The .getChildren() method of the pane object “exposes” its children collection. Fall 2018 CISC124 - Prof. McLeod

FlowPane Piles children into the pane in the order in which they are added from left to right (by default). The children wrap around if the available space is full. See FXProjectFlowPane. See what happens when you re-size the window. Play with gaps, padding, default sizes and alignment. Note the use of an ArrayList<Button> to hold buttons. Why are some buttons larger than others? Fall 2018 CISC124 - Prof. McLeod