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.

Slides:



Advertisements
Similar presentations
JustinMind: Dynamic Panels
Advertisements

CMSC 341 Building Java GUIs. 09/26/2007 CMSC 341 GUI 2 Why Java GUI Development? Course is about Data Structures, not GUIs. We are giving you the opportunity.
1 Microsoft Access 2002 Tutorial 9 – Automating Tasks With Macros.
Building Applications Dialogs Passing data between windows Validating Input using FocusListeners.
Automating Tasks With Macros
© The McGraw-Hill Companies, 2006 Chapter 18 Advanced graphics programming.
School of Computing Science CMT1000 Ed Currie © Middlesex University Lecture 4: 1 CMT1000: Introduction to Programming Ed Currie Lecture 5a: Input and.
CPSC150 Week 12 Graphical User Interfaces Chapter 11.
Scott Grissom, copyright 2006Ch 11: GUI Slide 1 Graphical User Interfaces (Ch 11) Careful design of a graphical user interface is key to a viable software.
Adobe Forms THE FORM ELEMENT PANEL. Creating a form using the Adobe FormsCentral is a quick and easy way to distribute a variety of forms including surveys.
CC1007NI: Further Programming Week 5 Dhruba Sen Module Leader (Islington College)
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.
8 Copyright © 2004, Oracle. All rights reserved. Creating LOVs and Editors.
F27SB2 Software Development 2 Lecture 9: Java GUIs 6.
Multiple Forms, Container Controls, AddHandler This presentation is based on the Forms and ContainerControls VB Projects 1.
SWING. Split Panes JSplitPane is used to divide two (and only two) Components. The two Components are graphically divided based on the look and feel implementation,
Java Software Solutions Lewis and Loftus Chapter 10 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Graphical User Interfaces --
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.
Chapter 8: Writing Graphical User Interfaces Visual Basic.NET Programming: From Problem Analysis to Program Design.
Java Programming, Second Edition Chapter Five Input and Selection.
Intro to Java Java Applications Swing Class Graphics.
Photo Gallery A photo gallery is a web page that contains a collection of graphics arranged in a specific layout. Microsoft FrontPage provides four different.
CS1101X: Programming Methodology Recitation 3 Control Structures.
Dale Roberts GUI Programming using Java - Introduction Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer.
GUI Clients 1 Enterprise Applications CE00465-M Clients with Graphical User Interfaces.
Creating Graphical User Interfaces (GUI’s) with MATLAB By Jeffrey A. Webb OSU Gateway Coalition Member.
Timer class and inner classes. Processing timer events Timer is part of javax.swing helps manage activity over time Use it to set up a timer to generate.
Chapter 11: Block References and Attributes. After completing this Chapter, you will be able to use the following features: Create and insert block references.
Chapter 3 Java Input/Output.
GUI Basics. What is GUI? A graphical user interface (GUI) is a type of user interface item that allows people to interact with programs in more ways than.
1/23: Java Modular Components Identifiers: naming requirements for Java variables & objects Stepping out of the MS-DOS window: The Java Modular Component:
Global Change. The Global Change gives users the ability to make global changes to quotes by displaying common options, allowing users to edit the options.
Introduction to GUI in 1 Graphical User Interface 2 Nouf Almunyif.
Option Panes CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
Data Types – Reference Types Objective To understand what reference types are The need to study reference types To understand Java standard packages To.
GUI development with Matlab: GUI Front Panel Components GUI development with Matlab: Other GUI Components 1 Other GUI components In this section, we will.
GUI Graphical User Interface Each onscreen component and window is an object Object interaction makes communication and scoping challenging Event-driven.
Presented By: Weidong WU, Ph.D. Date: Part I Creating a drawing format for the paper size A (11 x 8.5) 1. Start Pro/E wildfire. 2. File  set.
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.
SE-1020 Dr. Mark L. Hornick 1 Graphical User Interfaces.
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.
1 CSE 331 Composite Layouts; Decorators slides created by Marty Stepp based on materials by M. Ernst, S. Reges, D. Notkin, R. Mercer, Wikipedia
Copyright © Curt Hill Common Dialogs Easily Obtaining File Names in DevC++ Windows Programs.
Objects First With Java A Practical Introduction Using BlueJ Building Graphical User Interfaces (GUIs) Week
Microsoft Visual C# 2010 Fourth Edition Chapter 3 Using GUI Objects and the Visual Studio IDE.
제 14 장 고급 스윙 컴포넌트.
This screen may be skipped altogether if the user chooses a report from the server and clicks Ad Hoc or Edit or whatever. Also, the next screen would ordinarily.
Prepared by: Dr. Abdallah Mohamed, AOU-KW Unit 6 Graphical user interfaces 1.
Chapter 9: Graphical User Interfaces
Building a Swing Interface
“Form Ever Follows Function” Louis Henri Sullivan
CSE 114 – Computer Science I Event Programming
Chap 7. Building Java Graphical User Interfaces
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.
Predefined Dialog Boxes
CS18000: Problem Solving and Object-Oriented Programming
Message, Input, and Confirm Dialogs
CS431 ws99 Half Text Half Graphics
Ch. No Name Marks 01 AWT Networking JDBC Swing 05
Lesson Seven: Customizing Columns in Patient Lists
Object-Oriented Software Engineering
Ch. No Name Marks 01 AWT Networking JDBC Swing 05
Chapter 4 Interface Types and Polymorphism Part 1
TA: Nouf Al-Harbi NoufNaief.net :::
Presentation transcript:

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 class may appear complex because of the large number of methods, almost all uses of this class are one-line calls to one of the static showXxxDialog methods shown below: showConfirmDialogAsks a confirming question, like yes/no/cancel. showInputDialogPrompt for some input. showMessageDialogTell the user about something that has happened. showOptionDialogThe Grand Unification of the above three.

JOptionPane Class All dialogs are modal. Each showXxxDialog method blocks the current thread until the user's interaction is complete. The basic appearance of one of these dialog boxes is generally similar to the picture below, although the various look-and-feels are ultimately responsible for the final result. In particular, the look-and-feels will adjust the layout to accommodate the option pane's ComponentOrientation property. icon message input value option buttons

JOptionPane Class The parameters to these methods follow consistent patterns: parentComponent Defines the Component that is to be the parent of this dialog box. It is used in two ways: the Frame that contains it is used as the Frame parent for the dialog box, and its screen coordinates are used in the placement of the dialog box. In general, the dialog box is placed just below the component. This parameter may be null, in which case a default Frame is used as the parent, and the dialog will be centered on the screen (depending on the L&F).

JOptionPane Class message A descriptive message to be placed in the dialog box. In the most common usage, message is just a String or String constant. However, the type of this parameter is actually Object. Its interpretation depends on its type: Object[]An array of objects is interpreted as a series of messages (one per object) arranged in a vertical stack. The interpretation is recursive - each object in the array is interpreted according to its type. ComponentThe Component is displayed in the dialog. IconThe Icon is wrapped in a JLabel and displayed in the dialog. othersThe object is converted to a String by calling its toString() method. The result is wrapped in a JLabel and displayed.

JOptionPane Class messageType Defines the style of the message. The Look and Feel manager may lay out the dialog differently depending on this value, and will often provide a default icon. The possible values are:  ERROR_MESSAGE Used for error messages  INFORMATION_MESSAGE Used for information messages  WARNING_MESSAGE Used for warning messages  QUESTION_MESSAGE Used for questions  PLAIN_MESSAGE No icon is used

JOptionPane Class optionType Defines the set of option buttons that appear at the bottom of the dialog box:  DEFAULT_OPTION  YES_NO_OPTION  YES_NO_CANCEL_OPTION  OK_CANCEL_OPTION You aren't limited to this set of option buttons. You can provide any buttons you want using the options parameter.

JOptionPane Class options A more detailed description of the set of option buttons that will appear at the bottom of the dialog box. The usual value for the options parameter is an array of Strings. But the parameter type is an array of Objects. A button is created for each object depending on its type:  Component The component is added to the button row directly.  Icon A JButton is created with this as its label.  other The Object is converted to a string using its toString() method and the result is used to label a JButton.

JOptionPane Class icon A decorative icon to be placed in the dialog box. A default value for this is determined by the messageType parameter. title The title for the dialog box. initialValue The default selection (input value).

JOptionPane Class When the selection is changed, setValue is invoked, which generates a PropertyChangeEvent. If a JOptionPane has configured to all input setWantsInput the bound property JOptionPane.INPUT_VALUE_PROPERTY can also be listened to, to determine when the user has input or selected a value. When one of the showXxxDialog methods returns an integer, the possible values are:  YES_OPTION  NO_OPTION  CANCEL_OPTION  OK_OPTION  CLOSED_OPTION

Examples Show an error dialog that displays the message, 'alert': JOptionPane.showMessageDialog(null, "alert", "alert", JOptionPane.ERROR_MESSAGE); Show an information panel with the options yes/no and message 'choose one': JOptionPane.showConfirmDialog(null, "choose one", "choose one", JOptionPane.YES_NO_OPTION);

Examples Show a warning dialog with the options OK, CANCEL, title 'Warning', and message 'Click OK to continue': Object[] options = { "OK", "CANCEL" }; JOptionPane.showOptionDialog(null, "Click OK to continue", "Warning", JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[0]);

Examples Show a dialog asking the user to type in a String: String inputValue = JOptionPane.showInputDialog( "Please input a value");

Examples Show a dialog asking the user to select a String: Object[] possibleValues = { "First", "Second", "Third" }; Object selectedValue = JOptionPane.showInputDialog(null, "Choose one", "Input", JOptionPane.INFORMATION_MESSAGE, null, possibleValues, possibleValues[0]);