Object-Oriented Programming in Java

Similar documents
More about JOptionPane Dialog Boxes

Chapter 8: GUI Dialog & Table. Informatics Practices Class XII. By- Rajesh Kumar Mishra. KV No.1, AFS, Suratgarh

JOptionPane Dialogs. javax.swing.joptionpane is a class for creating dialog boxes. Has both static methods and instance methods for dialogs.

Introduction to Java. Nihar Ranjan Roy.

19. GUI Basics. Java. Fall 2009 Instructor: Dr. Masoud Yaghini

Course PJL. Arithmetic Operations

Chapter 2: Using Data

Copyright 1999 by Deitel & Associates, Inc. All Rights Reserved.

Guessing Game with Objects

Graphical User Interfaces 2

Topic 9: Swing. Swing is a BIG library Goal: cover basics give you concepts & tools for learning more

Topic 9: Swing. Why are we studying Swing? GUIs Up to now: line-by-line programs: computer displays text user types text. Outline. 1. Useful & fun!

Chapter 2: Using Data

The price of gold. source: nowiknow.com. moodle.yorku.ca CSE 1020

Graphical User Interfaces 2

Graphical User Interfaces 2

Chapter 02: Using Data

Java Foundations John Lewis Peter DePasquale Joe Chase Third Edition

In this lab, you will be given the implementation of the classes GeometricObject, Circle, and Rectangle, as shown in the following UML class diagram.

Guessing Game with Objects

Starting Out with Java: From Control Structures Through Objects Sixth Edition

ว ฒนพงศ ส ทธภ กด Java Programming ( )

CompSci 230 S Programming Techniques. Basic GUI Components

PROGRAMMING DESIGN USING JAVA (ITT 303) Unit 7

Outline. Topic 9: Swing. GUIs Up to now: line-by-line programs: computer displays text user types text AWT. A. Basics

Key Concept: all programs can be broken down to a combination of one of the six instructions Assignment Statements can create variables to represent

Swing. By Iqtidar Ali

Unit 6: Graphical User Interface

Flow of Control. Chapter 3

Introduction to the JAVA UI classes Advanced HCI IAT351

This page intentionally left blank

JDirectoryChooser Documentation

Full file at

Lesson 3: Accepting User Input and Using Different Methods for Output

MyProgram m i ng Lab. get with the programming. Through the power of practice and immediate personalized

Week Chapter Assignment SD Technology Standards. 1,2, Review Knowledge Check JP3.1. Program 5.1. Program 5.1. Program 5.2. Program 5.2. Program 5.

Due Date: Two Program Demonstrations (Testing and Debugging): End of Lab

Graphical Applications

Handout 3 cs180 - Programming Fundamentals Fall 17 Page 1 of 6. Handout 3. Strings and String Class. Input/Output with JOptionPane.

Building Java Programs Bonus Slides

CT 229 Fundamentals of Java Syntax

BASICS OF GRAPHICAL APPS

GUI Components: Part 1

Introduction. Introduction

INTERNATIONAL INDIAN SCHOOL, RIYADH XI XII BOYS SECTION INFORMATICS PRACTICES WORKSHEET 15 TH CHAPTER DATABASE TRANSACTION IMPORTANT QUESTION

Example 3-1. Password Validation

Chapter 4 Loops. int x = 0; while ( x <= 3 ) { x++; } System.out.println( x );

Graphical User Interfaces (GUIs)

Flow of Control. Chapter 3. Chapter 3 1

Agenda. Programming Seminar. By: dr. Amal Khalifa. Coordinate systems Colors Fonts Drawing shapes Graphics2D API

THE UNIVERSITY OF AUCKLAND

CSC 111, Test 1 (Fall 2009)

Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. Overview. Objectives. Teaching Tips. Quick Quizzes. Class Discussion Topics

MIT AITI Swing Event Model Lecture 17

Cork Institute of Technology. Spring 2006 GUI/Mobile/Web (Time: 3 Hours)

Advanced Java Programming. Swing. Introduction to Swing. Swing libraries. Eran Werner, Tel-Aviv University Summer, 2005

GUI Basics. Object Orientated Programming in Java. Benjamin Kenwright

CS 231 Data Structures and Algorithms Fall Event Based Programming Lecture 06 - September 17, Prof. Zadia Codabux

DM503 Programming B. Peter Schneider-Kamp.

5. In JAVA, is exception handling implicit or explicit or both. Explain with the help of example java programs. [16]

In this lab we will practice creating, throwing and handling exceptions.

CS 4300 Computer Graphics

Introduction p. 1 JFC Architecture p. 5 Introduction to JFC p. 7 The JFC 1.2 Extension p. 8 Swing p. 9 Drag and Drop p. 16 Accessibility p.

Graphics. Lecture 18 COP 3252 Summer June 6, 2017

CS 251 Intermediate Programming GUIs: Components and Layout

IT101. Graphical User Interface

CS 106 Introduction to Computer Science I

CS 106 Introduction to Computer Science I

Chapter 4 Introduction to Control Statements

Object-Oriented Programming in Java

Working with Java Applications. SilkTest 2008 R2

CST141 Thinking in Objects Page 1


Widget. Widget is a generic name for parts of an interface that have their own behaviour. e.g., buttons, progress bars, sliders, drop-down

DM550 / DM857 Introduction to Programming. Peter Schneider-Kamp

Solutions to Chapter Exercises. GUI Objects and Event-Driven Programming

CS 106 Introduction to Computer Science I

Outline HW2. Feedback. CS1007: Object Oriented Design and Programming in Java

CS 11 java track: lecture 3

Command-Line Applications. GUI Libraries GUI-related classes are defined primarily in the java.awt and the javax.swing packages.

Widgets. Widgets Widget Toolkits. 2.3 Widgets 1

Widgets. Widgets Widget Toolkits. User Interface Widget

Full file at

Arrays (Deitel chapter 7)

Graphical User Interface (Part-1) Supplementary Material for CPSC 233

Using the Customize Dialog Box

DM537 Object-Oriented Programming. Peter Schneider-Kamp.

Window Interfaces Using Swing Objects

Higher National Diploma in Information Technology First Year, Second Semester Examination 2015

CPS122 Lecture: Graphical User Interfaces and Event-Driven Programming

Java Programming Lecture 6

The first applet we shall build will ask the user how many times the die is to be tossed. The request is made by utilizing a JoptionPane input form:

Instruction to students:

Chapter 7: A First Look at GUI Applications

12/22/11. Java How to Program, 9/e. public must be stored in a file that has the same name as the class and ends with the.java file-name extension.

Assignment #3 (Due 4/4/2017)

Chapter 3 - Introduction to Java Applets

CSC207H: Software Design Lecture 11

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

MODEL UPDATES MANIPULATES USER

Transcription:

CSCI/CMPE 3326 Object-Oriented Programming in Java 1. GUI 2. Dialog box Dongchul Kim Department of Computer Science University of Texas Rio Grande Valley

Introduction to GUI Many Java application use a graphical user interface or GUI (pronounced gooey ). A GUI is a graphical window or windows that provide interaction with the user. GUI s accept input from: the keyboard a mouse. A window in a GUI consists of components that: present data to the user allow interaction with the application.

Introduction to GUI Some common GUI components are: buttons, labels, text fields, check boxes, radio buttons, combo boxes, and sliders.

JFC, AWT, Swing Java programmers use the Java Foundation Classes (JFC) to create GUI applications. The two sets of JFC classes that we focus on are AWT and Swing classes. Abstract Windowing Toolkit (AWT).

AWT Java programs using the AWT: look consistent with other applications on the same system. can offer only components that are common to all the operating systems that support Java. The behavior of components across various operating systems can differ. Programmers cannot easily extend the AWT components.

Swing Swing was introduced with the release of Java 2. Swing is a library of classes that provide an improved alternative for creating GUI applications and applets. Swing draws most of its own components. Swing components have a consistent look and predictable behavior on any operating system. Swing components can be easily extended.

javax.swing and java.awt In an application that uses Swing classes, it is necessary to use the following statement: import javax.swing.*; Note the letter x that appears after the word java. Some of the AWT classes are used to determine when events, such as the clicking of a mouse, take place in applications. In an application that uses an AWT class, it is necessary to use the following statement. import java.awt.*; Note that there is no x after java in this package name.

Event Driven Programming Programs that operate in a GUI environment must be event-driven. An event is an action that takes place within a program, such as the clicking of a button. Part of writing a GUI application is creating event listeners. An event listener is an object that automatically executes one of its methods when a specific event occurs.

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 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 input. Confirm Dialog -This is a dialog box that asks the user a Yes/No question.

Dialog Boxes The JOptionPane class provides static methods to display each type of dialog box.

Message Dialogs JOptionPane.showMessageDialog method is used to display a message dialog. There are several overloaded versions of this method. showmessagedialog(component parent, Object message) showmessagedialog(component parent, Object message, String title, int messagetype)

Message Dialogs JOptionPane.showMessageDialog(null, "Hello World"); The first argument can be a reference to a graphical component. The dialog box is displayed inside that component. If null is passed as the first argument, which causes the dialog box to be displayed in the center of the screen. The second argument is the message that is to be displayed.

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. You can change options JOptionPane.showMessageDialog(null, "Invalid Data", "My Message Box", JOptionPane.ERROR_MESSAGE); The third option is the title bar text.

Message Dialogs icons JOptionPane.ERROR_MESSAGE JOptionPane.INFORMATION_MESSAGE JOptionPane.WARNING_MESSAGE JOptionPane.QUESTION_MESSAGE JOptionPane.PLAIN_MESSAGE

Message Dialogs

Input Dialogs An input dialog is a quick and simple way to ask the user to enter 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. 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)

Input Dialogs String name; name = JOptionPane.showInputDialog("Enter your name.");

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);

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)

Confirm Dialog 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.

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

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.

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: JOptionPane.YES_NO_OPTION JOptionPane.YES_NO_CANCEL_OPTION