Chapter 8 Improving the User Interface

Slides:



Advertisements
Similar presentations
Chapter 4 Loops Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved
Advertisements

1. XP 2 * The Web is a collection of files that reside on computers, called Web servers. * Web servers are connected to each other through the Internet.
Chapter 5: Control Structures II (Repetition)
Chapter 16 Graphical User Interfaces
1 Exceptions: An OO Way for Handling Errors Rajkumar Buyya Grid Computing and Distributed Systems (GRIDS) Laboratory Dept. of Computer Science and Software.
Lists, Loops, Validation, and More
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 5- 1 STARTING OUT WITH Visual Basic 2008 FOURTH EDITION Tony Gaddis.
BASIC SKILLS AND TOOLS USING ACCESS
© 2010 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Chapter 5: Repetition and Loop Statements Problem Solving & Program.
Tutorial 9 – Creating On-Screen Forms Using Advanced Table Techniques
XP New Perspectives on Microsoft Office Word 2003 Tutorial 6 1 Microsoft Office Word 2003 Tutorial 6 – Creating Form Letters and Mailing Labels.
Lecture 10 Flow of Control: Loops (Part 2) COMP1681 / SE15 Introduction to Programming.
Excel Lesson 11 Improving Data Accuracy
© Paradigm Publishing, Inc Access 2010 Level 1 Unit 1Creating Tables and Queries Chapter 2Creating Relationships between Tables.
1 Lesson 10 Working with Tables Computer Literacy BASICS: A Comprehensive Guide to IC 3, 3 rd Edition Morrison / Wells.
Microsoft Office Illustrated Fundamentals Unit K: Working with Data.
Word Lesson 7 Working with Documents
Microsoft Access.
Review Chapter 11 - Tables © 2010, 2006 South-Western, Cengage Learning.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 12 – Security Panel Application Introducing.
1 What is JavaScript? JavaScript was designed to add interactivity to HTML pages JavaScript is a scripting language A scripting language is a lightweight.
Benchmark Series Microsoft Excel 2013 Level 2
COMPUTER INTERFACES.
Chapter 5 Microsoft Excel 2007 Window
4 Oracle Data Integrator First Project – Simple Transformations: One source, one target 3-1.
Chapter 5 Loops Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved.
INTRODUCTORY MICROSOFT WORD Lesson 7 – Working With Documents
25 seconds left…...
Lesson 12 Getting Started with Word Essentials
Chapter 15 Multithreading, Networks, and Client/Server Programming
Computer Concepts BASICS 4th Edition
Lesson 13 Editing and Formatting Documents
© Paradigm Publishing, Inc Access 2010 Level 2 Unit 2Advanced Reports, Access Tools, and Customizing Access Chapter 8Integrating Access Data.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 13 – Salary Survey Application: Introducing.
Chapter 16 Graphical User Interfaces John Keyser’s Modifications of Slides by Bjarne Stroustrup
Benchmark Series Microsoft Excel 2013 Level 2
Chapter 3 Syntax, Errors, and Debugging
Chapter 2 First Java Programs
Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
Chapter 10 Introduction to Arrays
Java Programming, 3e Concepts and Techniques Chapter 4 Decision Making and Repetition with Reusable Objects.
Chapter 7 Improving the User Interface
Concepts of Database Management Sixth Edition
Chapter 2 First Java Programs
Lesson 7: Improving the User Interface
1 Chapter 2 First Java Programs Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
CNG 140 C Programming (Lecture set 9) Spring Chapter 9 Character Strings.
Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java.
Concepts of Database Management Seventh Edition
1 Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java.
Java Programming, 2E Introductory Concepts and Techniques Chapter 4 Decision Making and Repetition with Reusable Objects.
Programming Logic and Design Fourth Edition, Comprehensive Chapter 14 Event-Driven Programming with Graphical User Interfaces.
12-Jun-16 Event loops. 2 Programming in prehistoric times Earliest programs were all “batch” processing There was no interaction with the user Input Output.
Programming with Microsoft Visual Basic 2012 Chapter 14: Access Databases and SQL.
Chapter 2 First Java Programs Fundamentals of Java.
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
Introduction to Programming and Visual Basic
Chapter 3 Syntax, Errors, and Debugging
Objectives You should be able to describe: Interactive Keyboard Input
Event loops 16-Jun-18.
Chapter 2 First Java Programs
A First Book of ANSI C Fourth Edition
Section 3.2c Strings and Method Signatures
Event loops.
Event loops 17-Jan-19.
Event loops 17-Jan-19.
Event loops 8-Apr-19.
Event loops.
Event loops 19-Aug-19.
Presentation transcript:

Chapter 8 Improving the User Interface Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne

Objectives Construct a query-driven terminal interface. Construct a menu-driven terminal interface. Construct a graphical user interface. Format text, including numbers, for output. Handle number format exceptions during input. 2 2

Vocabulary application controller pattern data model event-driven format flag format specifier menu-driven program model view query-controlled input 3 3

A Thermometer Class Used to convert temperatures between Fahrenheit and Celsius. Class stores temperature internally in Celsius, but it can be set and retrieved in either Fahrenheit or Celsius. 4 4

Repeating Sets of Inputs Techniques for handling repeating set of inputs: Count-controlled and sentinel-controlled already learned. Query-controlled input: Before each set of inputs after the first, the program asks the user if there are more inputs. 5 5

Repeating Sets of Inputs (continued) Interface for a query-controlled temperature conversion program 6 6

Repeating Sets of Inputs (continued) The program is implemented by means of two classes: One to handle user interface. The Thermometer class. The code for the interface class uses String variable doItAgain. Controls how many times the loop repeats. 7 7

A Menu-Driven Conversion Program Menu-driven programs begin by displaying a list of options. The user selects an option. Then the program prompts for additional inputs related to the option, and performs the needed computations. The menu displays again. Code uses if-else statements to evaluate next step after each input. 8 8

A Menu-Driven Conversion Program (continued) Interface for a menu-driven version of the temperature conversion program 9 9

Formatted Output with printf and format Using printf to Format Numbers: The precision of floating-point numbers refers to the number of digits to the right of the decimal program supported by the programming language. The print and println methods display only the necessary digits for the number. The printf method is used to format output. 10 10

Formatted Output with printf and format (continued) Using printf to Format Numbers (cont)? The parameters of the method printf consist of a format string and one or more data values. The format string is a combination of literal string information and formatting information. The formatting information consists of one or more format specifiers: Begin with a % character, and end with a letter that indicates the format type. 11

Formatted Output with printf and format (continued) Using printf to Format Numbers (cont): Commonly used format types 12

Formatted Output with printf and format (continued) Using printf to Format Numbers (cont): The symbol %n can be used to embed an end-of-line character in a format string. The symbol %% produces the % character. Otherwise, when the compiler encounters a format specifier in a format string, it attempts to match it to an expression following the string. The two must match in type and position. 13 13

Formatted Output with printf and format (continued) Text Justification and Multiple Columns: Data-processing applications frequently display tables with columns of words and numbers. Unless carefully formatted, these tables are unreadable. Each column has a designated width, and the values are justified in the same manner (left, right or center). 14 14

Formatted Output with printf and format (continued) Text Justification and Multiple Columns (cont): A table of sales figures shown with and without formatting 15 15

Formatted Output with printf and format (continued) Text Justification and Multiple Columns (cont): The columns in Version 2 are produced by displaying pieces of text that are justified within fields. Field: a fixed number of columns within which the characters of a data value can be placed. A data value is left-justified when its display begins in the leftmost column of its field. Trailing or leading spaces are used to occupy columns that are not filled by the value. 16 16

Formatted Output with printf and format (continued) Text Justification and Multiple Columns (cont): Format flags support the justification of text as well as other format styles. Some commonly used format flags 17 17

Formatted Output with printf and format (continued) Text Justification and Multiple Columns (cont): To output data in formatted columns, establish the width of each field and then choose the appropriate format flags and specifiers to use with printf. Some example format strings and their outputs 18 18

Formatted Output with printf and format (continued) Formatting with String.format: The String method can be used to build a formatted string. The method expects the same parameters as printf and returns a formatted string. 19 19

Handling Number Format Exceptions During Input If input data are invalid, the program can display an error message and prompt for the data again. Typical errors are input numbers that are without a certain range. Input methods must be able to detect if data is entered in an invalid format. The Scanner and nextDouble methods do. 20 20

Handling Number Format Exceptions During Input (continued) When format errors are detected, these methods throw an exception that halts the program. The bad format is detected before the client code can react to the error. Acceptable during testing and debugging, but the final product needs to respond to formatting errors without halting the program. 21 21

Handling Number Format Exceptions During Input (continued) The programmer embeds the call to an input method in a try-catch statement: The statements within the try clause are executed until one throws an exception. Then, the catch clause is executed. If no exception, the catch clause is skipped. 22 22

Graphics and GUIs A GUI can present the user with entry fields for many data values simultaneously: Command buttons, drop-down menus The Model/View/Controller Pattern: Data model: class type whose responsibilities include initializing and managing the data. View: class type such as windows, buttons, data files, and labels that display controls for user interaction. 23 23

Graphics and GUIs (continued) The Model/View/Controller Pattern (cont): Controller: class type that are listeners. Responsible for handling user interaction. Application: class type that sets up the other elements in a main method to provide an entry point for running a Java program. Interface for the GUI-based temperature conversion program 24 24

Graphics and GUIs (continued) Use grids, panels, and padding when designing the layout of labels and data fields. Real GUI programs are event-driven. When the program opens, it waits for events such as mouse click or typing characters in a field. The JVM runs in a loop behind the scenes. To make the program robust, allow the JVM to track the main window of the dialog box. 25 25

Summary In this chapter, you learned: A terminal input/output (I/O) interface can be extended to handle repeated sets of inputs, by using either a query-based pattern or a menu-driven pattern. A graphical user interface (GUI) allows the user to interact with a program by displaying window objects and handling mouse events. 26 26

Summary (continued) In a terminal-based program, the program controls most of the interaction with the user, whereas GUI-based programs are driven by user events. The two primary tasks of a GUI-based program are to arrange the window objects in a window and handle interactions with the user. 27 27