GUI Graphical User Interface Each onscreen component and window is an object Object interaction makes communication and scoping challenging Event-driven.

Slides:



Advertisements
Similar presentations
Chapter 2 - Introduction to Java Applications
Advertisements

Using JOptionPanes for graphical communication with our programs. Pages Horstmann 139.
1 Introduction to Java Programming Lecture 4 Using JOptionPane Spring 2008.
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.
COMP 14 Introduction to Programming Miguel A. Otaduy May 17, 2004.
COMP 14 Introduction to Programming Mr. Joshua Stough February 2, 2005 Monday/Wednesday 11:00-12:15 Peabody Hall 218.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie June 29, 2005.
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
Review. By the end of today you should be able to- Know how to use args Know how to use the JOptionPane Know how to convert a String to a number.
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.
Intro to GUIs (Graphical User Interfaces) Section 2.5Intro. to GUIs: a GUI Greeter Section 3.7Graphical/Internet Java: Einstein's Equation.
Introduction to GUI in Java 1. Graphical User Interface Java is equipped with many powerful,easy to use GUI component such as input and output dialog.
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.
OOP (Java): Simple/ OOP (Java) Objectives – –give some simple examples of Java applications and one applet 2. Simple Java Programs Semester.
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.
Chapter 2 – Continued Basic Elements of Java. Chapter Objectives Type Conversion String Class Commonly Used String Methods Parsing Numeric Strings Commonly.
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.
Chapter 2: Java Fundamentals Type conversion,String.
 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.
Java Fundamentals 5. Java Programming: From Problem Analysis to Program Design, Second Edition2 Parsing Numeric Strings  Integer, Float, and Double are.
Programming Fundamentals 2: Simple/ F II Objectives – –give some simple examples of Java applications and one applet 2. Simple Java.
1/28: Inputs, Variable Types, etc. Addition.java in depth Variable types & data types Input from user: how to get it Arithmetic operators.
Lecture 2 Objectives Learn about objects and reference variables.
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.
Graphical User Interfaces. Graphical input and output with JOptionPane.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 3 Introduction to Objects and Input/Output.
Introduction to Computing Concepts Note Set 15. JOptionPane.showMessageDialog Message Dialog Allows you to give a brief message to the user Can be used.
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.
Component-Based Software Engineering Java with added Swing Paul J Krause.
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.
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.
Introduction to GUI in 1 Graphical User Interface Nouf Almunyif.
Import javax.swing.JOptionPane; public class Rectangle { public static void main(String[] args) { double width, length, area, perimeter; String lengthStr,
A Quick Java Swing Tutorial
Java Programming Lecture 2
Outline Creating Objects The String Class Packages Formatting Output
Data Types – Reference Types
OBJECT ORIENTED PROGRAMMING I LECTURE 7 GEORGE KOUTSOGIANNAKIS
A Java Program: // Fig. 2.1: Welcome1.java // Text-printing program.
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.
Introduction to GUI in Graphical User Interface Nouf Almunyif.
OBJECT ORIENTED PROGRAMMING I LECTURE 7 GEORGE KOUTSOGIANNAKIS
Chapter 3: Introduction to Objects and Input/Output
CS18000: Problem Solving and Object-Oriented Programming
Chapter 2 - Introduction to Java Applications
Chapter 3: Introduction to Objects and Input/Output
Message, Input, and Confirm Dialogs
CS431 ws99 Half Text Half Graphics
Object-Oriented Software Engineering
JOptionPane class.
F II 2. Simple Java Programs Objectives
Chapter 2: Java Fundamentals cont’d
Presentation transcript:

GUI Graphical User Interface Each onscreen component and window is an object Object interaction makes communication and scoping challenging Event-driven - program’s execution is driven by the series of events that occur

Option pane – simple message box Includes a message or request for input JOptionPane

Parsing Number Strings Integer.parseInt(strExpression) Float.parseFloat(strExpression) Double.parseDouble(strExpression) Examples: Integer.parseInt(“-542”) = -542 Float.parseFloat(“34.63”) = Double.parseDouble(“ ”) =

Integer, Float, Double Classes Convert string to a number Wrapper classes parseInt is a method of class Integer parseFloat…

Using Dialog boxes GUI Class JOptionPane Contained in package javax.swing In earlier versions of java, Swing was an extension to Java’s feature set Two methods: – To present a list of choices to the user showInputDialog – Display a message showMessageDialog (parent window, display string) import javax.swing.*;

Gui1 import javax.swing.*; // for GUI components public class Gui1 { public static void main(String [] args) { JOptionPane.showMessageDialog(null, "Hello world!"); }

JOptionPane 1.Display a message (showMessageDialog) 2.To present a list of choices to the user (showInputDialog) 3.To ask the user to type input (showConfirmDialog)

GUI2 import javax.swing.*; // for GUI components public class Gui2 { public static void main(String [] args) { String name = JOptionPane.showInputDialog(null, "What is your name"); int choice = JOptionPane.showConfirmDialog(null, "Do you like chocolate, " + name + "?"); if (choice == JOptionPane.YES_OPTION) { JOptionPane.showMessageDialog(null, "Of course! Who doesn't?"); } else JOptionPane.showMessageDialog(null, "Seriously?"); }

showMessageDialog JOptionPane.showMessageDialog(parentComponent, messageStrExp, boxTitleStr, messageType); parentComponent – null causes dialog box to appear in middle of string messageStrExp – appears in dialog box boxTitleString – title of dialog box messageType – ERROR_MESSAGE – error icon INFORMATION_MESSAGE – information icon PLAIN_MESSAGE – no icon QUESTION_MESSAGE – question icon WARNING_MESSAGE – warning icon

import javax.swing.*; public class AreaAndCircumferenceProgram { public static final double PI = 3.14; public static void main(String[] args) { double radius, area, circumference; String radiusString,outputStr; radiusString = JOptionPane.showInputDialog(“Enter radius:"); radius = Double.parseDouble(radiusString); area = PI * radius * radius; circumference = 2 * PI * radius; outputStr = "Radius: " + radius + "\nArea: " + area + " square units\n" + "Circumference: " + circumference + " units"; JOptionPane.showMessageDialog(null, outputStr, "Circle", JOptionPane.INFORMATION_MESSAGE); System.exit(0); }

String method format String.format(formatString,argumentList) Works like printf Can be used as argument to println Double x = ; Double y = ; Double z = ; System.out.println(String.format(“%.2f”,x); System.out.println(String.format(“%.3f”,y); System.out.println(String.format(%.2f”,z);

import javax.swing.*; public class AreaAndCircumferenceProgram { public static final double PI = 3.14; public static void main(String[] args) { double radius, area, circumference; String radiusString,outputStr; radiusString = JOptionPane.showInputDialog(“Enter radius"); radius = Double.parseDouble(radiusString); area = PI * radius * radius; circumference = 2 * PI * radius; outputStr = String.format("Radius: %.2f %n Area: %.2f square units %nCircumference: %.2f units", radius, area, circumference); JOptionPane.showMessageDialog(null, outputStr, "Circle", JOptionPane.INFORMATION_MESSAGE); }

str = JOptionPane.showInputDialog(stringExpr); radiusStr = JOptionPane.showInputDialog(“Enter the radius:”)