Dialog Boxes.

Slides:



Advertisements
Similar presentations
Chapter 2 Review Questions
Advertisements

Chapter 2 - Introduction to Java Applications
Dialogs. Displaying Text in a Dialog Box Windows and dialog boxes –Up to this our output has been to the screen –Many Java applications use these to display.
Using JOptionPanes for graphical communication with our programs. Pages Horstmann 139.
1 Introduction to Java Programming Lecture 4 Using JOptionPane Spring 2008.
CS 106 Introduction to Computer Science I 01 / 29 / 2008 Instructor: Michael Eckmann.
Mathematical Operators  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course. Introduction to Computers and Programming in.
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
1 Introduction to Java Programming Lecture 4 Using JOptionPane Spring 2010.
Relational Operators Control structures Decisions using “if” statements  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course.
Chapter 3: Introduction to Objects and Input/Output.
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.
Constants public class Car { //This class produces cars with 18 MPG private String color; private String make; private String model; private double gas;
Intrinsic Functions Pre-coded Functions Used to improve developer productivity Broad Range of Activities Math calculations Time/Date functions String.
OOP (Java): Simple/ OOP (Java) Objectives – –give some simple examples of Java applications and one applet 2. Simple Java Programs Semester.
1 Introduction to C# Programming Console applications No visual components Only text output Two types MS-DOS prompt - Used in Windows 95/98/ME Command.
Jaeki Song ISQS6337 JAVA Lecture 03 Introduction to Java -The First Java Application-
Java Programming: From Problem Analysis to Program Design, 3e Chapter 3 Introduction to Objects and Input/Output.
Input/Output in Java. Output To output to the command line, we use either System.out.print () or System.out.println() or System.out.printf() Examples.
 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.
CS 106 Introduction to Computer Science I 01 / 31 / 2007 Instructor: Michael Eckmann.
Programming Fundamentals 2: Simple/ F II Objectives – –give some simple examples of Java applications and one applet 2. Simple Java.
Variables When programming it is often necessary to store a value for use later on in the program. A variable is a label given to a location in memory.
1 Introduction to C# Programming Console applications No visual components Only text output Two types MS-DOS prompt - Used in Windows 95/98/ME Command.
Chapter 3 Java Input/Output.
1/28: Inputs, Variable Types, etc. Addition.java in depth Variable types & data types Input from user: how to get it Arithmetic operators.
Graphical User Interface You will be used to using programs that have a graphical user interface (GUI). So far you have been writing programs that have.
Lecture 2 Objectives Learn about objects and reference variables.
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 Programming: From Problem Analysis to Program Design, 4e Chapter 3 Introduction to Objects and Input/Output.
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.
Ihsan Ayyub Qazi Introduction to Computer Programming Recitation 3 Ihsan Ayyub Qazi.
Controlling Program Flow with Looping Structures
Computer Programming1 Computer Science 1 Computer Programming.
Strings and I/O. Lotsa String Stuff… There are close to 50 methods defined in the String class. We will introduce several of them here: charAt, substring,
InterestRate Create an InterestRate class and InterestRateViewer client class to do the following: A person is purchasing an item with their credit card.
Starting Out with Java: From Control Structures through Objects 5 th edition By Tony Gaddis Source Code: Chapter 5.
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.
JOptionPane. Import javax.swing.JOptionPane Use showInputDialog() for input. Only string values can be input. To convert an input value from a string.
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.
AP Java 10/1/2015. public class Rolling { public static void main( String [] args) public static void main( String [] args) { int roll; int roll; for.
Loops Review. How to generate random numbers Math.random() will return a random decimal value in the form of a double. double num1 = Math.random(); num1.
INTERMEDIATE PROGRAMMING USING JAVA
Java Programming Lecture 2
Data Types – Reference Types
OBJECT ORIENTED PROGRAMMING I LECTURE 7 GEORGE KOUTSOGIANNAKIS
Program: Shape Area Print the area for various shape types using the respective formulas.
Section 64 – Manipulating Data Using Methods – Java Swing
Dialogues and Wrapper Classes
Chapter 3 Java Input/Output.
Message, Input, Confirm, and Specialized Dialogs
Chapter 3: Introduction to Objects and Input/Output
Chapter 3 Input/Output.
Message, Input, and Confirm Dialogs
Introduction to Java Programming
Object Oriented Programming
Starting Out with Java: From Control Structures through Objects
JOptionPane class.
F II 2. Simple Java Programs Objectives
Chapter 2: Java Fundamentals cont’d
Presentation transcript:

Dialog Boxes

JOptionPane Class Allows you to display a dialog box Small graphical window that displays a message to the user or requests input Types: Message Dialog Input Dialog Need to import javax.swing.JOptionPane

Displaying Message Dialogs showMessaegDialog method – used to display a message dialog JOptionPane.showMessageDialog(null, “Hello World”); First argument will be discussed when we learn about Graphical User Interfaces (GUIs) – used to display other graphical windows Second argument is the message that we wish to display

Displaying Input Dialogs Quick and easy way to enter data String name; name = JOptionPane.showInputDialog(“Enter your name.”);

Ending Program Need: System.exit(0); When using the JOptionPane class, you must end a program Does not automatically stop executing when the end of the main method is reached because the class causes an additional task(thread) to run Need: System.exit(0); Needs an integer argument - value 0 traditionally indicates that the program ended successfully

Converting String Input to Numbers Unlike the Scanner class, the JOptionPane class does not have different methods for reading values of different data types as input showMessaegDialog method always returns the user’s input as a String, even if a numeric value was entered What is the problem with this?

Converting String Input to Numbers Use methods to convert string value to a numeric value Method Example Code Double.parseDouble double num; num = Double.parseDouble(str) Integer.parseInt int num; num = Integer.parseInt(str)

Example *Now you could use number to perform math methods* int number; String str; str = JOptionPane.showInputDialog(“Enter a number.”) number = Integer.parseInt(str); *Now you could use number to perform math methods*