Message, Input, and Confirm Dialogs

Slides:



Advertisements
Similar presentations
Chapter 2: Java Fundamentals cont’d
Advertisements

Building Applications Dialogs Passing data between windows Validating Input using FocusListeners.
Chapter 2 - Introduction to Java Applications
Chapter 2: Using Data.
Mathematical Operators  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course. Introduction to Computers and Programming in.
Object-Oriented Programming with Java Java with added Swing Lecture 3.
Introduction to Computers and Programming Lecture 3: Variables and Input Professor: Evan Korth New York University.
IC211 Lecture 8 I/O: Command Line And JOptionPane.
School of Computing Science CMT1000 Ed Currie © Middlesex University Lecture 4: 1 CMT1000: Introduction to Programming Ed Currie Lecture 5a: Input and.
Chapter 2 - Introduction to Java Applications
Programming with Java standard classes. Java API Application Programming Interface Provides hundreds of standard classes that can be incorporated into.
JOptionPane class. Dialog Boxes A dialog box is a small graphical window that displays a message to the user or requests input. A variety of dialog boxes.
Warm-Up: Monday, March 3 List all devices you can think of that can be used to input information into the computer.
Intro to GUIs (Graphical User Interfaces) Section 2.5Intro. to GUIs: a GUI Greeter Section 3.7Graphical/Internet Java: Einstein's Equation.
Using Classes BCIS 3680 Enterprise Programming. Overview 2  Using Classes  Using premade classes for input and output  Display output: System, JOptionPane.
Java Programming, Second Edition Chapter Five Input and Selection.
Introduction to Java. 2 A Brief History of OOP and Java Early high level languages –_________________________ More recent languages –BASIC, Pascal, C,
 2000 Prentice Hall, Inc. All rights reserved. 1 Chapter 2 - Introduction to Java Applications Outline 2.1Introduction 2.2A Simple Program: Printing a.
1 Java Programming 1 Introduction to Basic GUI Lesson 4.
Programming Fundamentals 2: Simple/ F II Objectives – –give some simple examples of Java applications and one applet 2. Simple Java.
Input & Output Functions JavaScript is special from other languages because it can accept input and produce output on the basis of that input in the same.
1/23: Java Modular Components Identifiers: naming requirements for Java variables & objects Stepping out of the MS-DOS window: The Java Modular Component:
Option Panes CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
Basics and arrays Operators:  Arithmetic: +, -, *, /, %  Relational:, >=, ==, !=  Logical: &&, ||, ! Primitive data types Byte(8), short(16), int(32),
Dialog Boxes.
Data Types – Reference Types Objective To understand what reference types are The need to study reference types To understand Java standard packages To.
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 13 GUI Programming.
GUI Graphical User Interface Each onscreen component and window is an object Object interaction makes communication and scoping challenging Event-driven.
Java Fundamentals Part Integer Division Division can be tricky. In a Java program, what is the value of 1/2? You might think the answer is.
Introduction to Computing Concepts Note Set 15. JOptionPane.showMessageDialog Message Dialog Allows you to give a brief message to the user Can be used.
SD2054 Software Development. By the end of this lecture you should be able to: Advanced Graphics Programming create pull down menus create combo boxes.
Ihsan Ayyub Qazi Introduction to Computer Programming Recitation 3 Ihsan Ayyub Qazi.
JOptionPane Class JOptionPane makes it easy to pop up a standard dialog box that prompts users for a value or informs them of something. While the JOptionPane.
SE-1020 Dr. Mark L. Hornick 1 Graphical User Interfaces.
CS-1010 Dr. Mark L. Hornick 1 Selection and Iteration and conditional expressions.
Creating and Using Dialogs ● A dialog is a box that pops up and prompts the user for a value or informs them of something ● One way: directly create objects.
InterestRate Create an InterestRate class and InterestRateViewer client class to do the following: A person is purchasing an item with their credit card.
Data Types – Reference Types Objective To understand what reference types are The need to study reference types To understand Java standard packages To.
Casting, Wrapper Classes, Static Methods, JOptionPane Class.
CS 115 OBJECT ORIENTED PROGRAMMING I LECTURE 6_1 GEORGE KOUTSOGIANNAKIS Copyright: FALL 2015 Illinois Institute of Technology- George Koutsogiannakis 1.
Object Oriented Programming (OOP) LAB # 3 TA. Maram & TA. Mubaraka TA. Kholood & TA. Aamal.
INTERMEDIATE PROGRAMMING USING JAVA
Java Programming Lecture 2
Topics Graphical User Interfaces Using the tkinter Module
Outline Creating Objects The String Class Packages Formatting Output
Data Types – Reference Types
OBJECT ORIENTED PROGRAMMING I LECTURE 7 GEORGE KOUTSOGIANNAKIS
“Form Ever Follows Function” Louis Henri Sullivan
Objectives You should be able to describe: Interactive Keyboard Input
2.5 Another Java Application: Adding Integers
Section 64 – Manipulating Data Using Methods – Java Swing
Dialogues and Wrapper Classes
Message, Input, Confirm, and Specialized Dialogs
JOptionPane Dialogs javax.swing.JOptionPane is a class for creating dialog boxes. Has both static methods and instance methods for dialogs. Easy to create.
Predefined Dialog Boxes
CS-0401 INTERMEDIATE PROGRAMMING USING JAVA
OBJECT ORIENTED PROGRAMMING I LECTURE 7 GEORGE KOUTSOGIANNAKIS
WEB PROGRAMMING JavaScript.
CS18000: Problem Solving and Object-Oriented Programming
Chapter 2 - Introduction to Java Applications
Chapter 3: Introduction to Objects and Input/Output
Messages and Input boxes
The System.exit() Method
Object Oriented Programming
CS431 ws99 Half Text Half Graphics
Dr. Sampath Jayarathna Cal Poly Pomona
JOptionPane class.
F II 2. Simple Java Programs Objectives
Chapter 2: Java Fundamentals cont’d
Presentation transcript:

Message, Input, and Confirm Dialogs JOptionPane JOptionPane Dialogs January 17, 2019

Dialog Boxes Message, Input, and Confirm Dialogs JOptionPane Dialogs January 17, 2019

Dialog Boxes A dialog box is a small graphical window that displays a message to the user or requests input A variety of simple dialog boxes can be displayed using the JOptionPane class Message Dialog - a dialog box that displays a message Input Dialog - a dialog box that prompts the user for typed input Confirm Dialog This is a dialog box that asks the user a Yes/No question JOptionPane Dialogs January 17, 2019

Dialog Boxes The JOptionPane class provides static methods to display each type of dialog box JOptionPane Dialogs January 17, 2019

Message dialogs JOptionPane Dialogs January 17, 2019

Message Dialogs JOptionPane.showMessageDialog(null, "Hello World"); The first argument can be a reference to a graphical component such as another window The dialog box is displayed centered on that component If null is passed as the first argument, the dialog box to be displayed in the center of the screen The second argument is the message that is to be displayed JOptionPane Dialogs January 17, 2019

Last parameter determines which icon is shown here Message Dialogs By default the dialog box has: the string “Message” displayed in its title bar, and an information icon (showing the letter “i”) is displayed JOptionPane.showMessageDialog(null, "Invalid Data", "My Message Box", JOptionPane.ERROR_MESSAGE); The third parameter is the title bar text Last parameter determines which icon is shown here JOptionPane Dialogs January 17, 2019

Message Dialogs These constants can be used to control the icon that is displayed JOptionPane.ERROR_MESSAGE JOptionPane.INFORMATION_MESSAGE JOptionPane.WARNING_MESSAGE JOptionPane.QUESTION_MESSAGE JOptionPane.PLAIN_MESSAGE JOptionPane Dialogs January 17, 2019

Message Dialogs with Icons JOptionPane Dialogs January 17, 2019

Message Dialogs The dialog boxes displayed by the JOptionPane class are modal dialog boxes A modal dialog box suspends execution of any other instructions in your program until the dialog box is closed When the JOptionPane.showMessageDialog method is called, the instructions after the method call do not execute until the user closes the message box JOptionPane Dialogs January 17, 2019

Input Dialog JOptionPane Dialogs January 17, 2019

Input Dialogs An input dialog is a quick and simple way to ask the user to enter String data The dialog displays a text field, an OK button and a Cancel button If OK is pressed, the dialog returns the user’s input If Cancel is pressed, the dialog returns null JOptionPane Dialogs January 17, 2019

Input Dialogs The JOptionPane has several overloaded versions of the static showInputDialog method Here are two of them: showInputDialog(Object message) showInputDialog(Component parent, Object message, String title, int messageType) JOptionPane Dialogs January 17, 2019

Input Dialogs String name; name = JOptionPane.showInputDialog("Enter your name."); The argument passed to the method is the message to display If the user clicks on the OK button, name references the string entered by the user If the user clicks on the Cancel button, name references null JOptionPane Dialogs January 17, 2019

Input Dialogs By default, the input dialog box: has the string “Input” in its title bar, and displays a question icon String value; value = JOptionPane.showInputDialog (null, "Enter the value again.", "Enter Carefully!", JOptionPane.WARNING_MESSAGE); JOptionPane Dialogs January 17, 2019

Input Dialog with Default Value Occasionally with an Input Dialog, a particular value is entered frequently In that case, that value can be used as a default value the user can accept or replace The calling sequence in this case is JOptionPane.showInputDialog (message, defaultValue) Example: JOptionPane Dialogs January 17, 2019

Numeric Data Type Wrappers The Input Dialog inputs only string data. If one inputs a number, it must be converted from the string received into a number before it can be used in numeric calculations Java provides wrapper classes for all primitive data types The numeric primitive wrapper classes are: Wrapper Class Numeric Primitive Type It Applies To Byte byte Double double Float float Integer int Long long Short short JOptionPane Dialogs January 17, 2019

The Parse Methods A string containing a number, such as “127.89”, can be converted to a numeric data type Each of the numeric wrapper classes has a static method that converts a string to a number The Integer class has a method that converts a String to an int The Double class has a method that converts a String to a double The other numeric wrapper classes have similar methods These methods are known as parse methods because their names begin with the word “parse” JOptionPane Dialogs January 17, 2019

The Parse Methods: Examples // Store 1 in bVar byte bVar = Byte.parseByte("1"); // Store 2599 in iVar int iVar = Integer.parseInt("2599"); // Store 10 in sVar short sVar = Short.parseShort("10"); // Store 15908 in longVar long longVar = Long.parseLong("15908"); // Store 12.3 in fVar float fVar = Float.parseFloat("12.3"); // Store 7945.6 in dVar double dVar = Double.parseDouble("7945.6"); The parse methods all throw a NumberFormatException if the String argument does not represent a numeric value JOptionPane Dialogs January 17, 2019

Now, one can use hours and sales in calculations “Parse” examples Now, one can use hours and sales in calculations JOptionPane Dialogs January 17, 2019

Confirm dialog JOptionPane Dialogs January 17, 2019

Confirm Dialog A confirm dialog box typically asks the user a yes or no question By default Yes, No, and Cancel buttons are displayed The showConfirmDialog method is used to display a confirm dialog box There are several overloaded versions of this method int showConfirmDialog(Component parent, Object message) int showConfirmDialog(Component parent, Object message, String title, int optionType) JOptionPane Dialogs January 17, 2019

Confirm Dialog By default the confirm dialog box displays: int value; value = JOptionPane.showConfirmDialog (null, "Are you sure?"); By default the confirm dialog box displays: “Select an Option” in its title bar Yes, No, and Cancel buttons JOptionPane Dialogs January 17, 2019

Confirm Dialog The showConfirmDialog method returns an integer that represents the button clicked by the user The button that was clicked is determined by comparing the method’s return value to one of the following constants: JOptionPane.YES_OPTION JOptionPane.NO_OPTION JOptionPane.CANCEL_OPTION JOptionPane Dialogs January 17, 2019

Confirm Dialog int value; value = JOptionPane.showConfirmDialog (null, "Are you sure?"); if (value == JOptionPane.YES_OPTION) { // If the user clicked Yes, this code is executed } else if (value == JOptionPane.NO_OPTION) // If the user clicked No, this code is executed else if (value == JOptionPane.CANCEL_OPTION) // If the user clicked Cancel, this code is executed JOptionPane Dialogs January 17, 2019

Confirm Dialog int value; value = JOptionPane.showConfirmDialog(null, "Are you sure?", "Please Confirm", JOptionPane.YES_NO_OPTION); One of the following constants can be used for the fourth parameter to control which buttons appear in the Confirm dialog JOptionPane.YES_NO_OPTION JOptionPane.YES_NO_CANCEL_OPTION Example: TestAverageDialog.java JOptionPane Dialogs January 17, 2019