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

Similar documents
Visit for more.

More about JOptionPane Dialog Boxes

Object-Oriented Programming in Java

Visit for more.

Introduction to Java. Nihar Ranjan Roy.

Course PJL. Arithmetic Operations

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

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

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

Java IDE Programming-I


Chapter 2: Using Data

Introduction to the JAVA UI classes Advanced HCI IAT351

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!

1.1 GUI. JFrame. import java.awt.*; import javax.swing.*; public class XXX extends JFrame { public XXX() { // XXX. init() main() public static

Basics of programming 3. Java GUI and SWING

GUI Components Continued EECS 448

GUI Programming- A Review. Visit for more.

CLASS XII SUBJECT: - INFORMATICS PRACTICES (065) I.P. (Theory)

CSE 143. Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT

SPLIT UP SYLLABUS SUBJECT : INFORMATICS PRATICES (065) SESSION: CLASS XII ( ) (THEORY)

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.

Swing. Component overview. Java UI, summer semester 2017/2018 1

JDirectoryChooser Documentation

Assignment 1. Application Development

Chapter 02: Using Data

Basics of Object Oriented Programming. Visit for more.

Visit for more.

Java Programming Lecture 6

Graphical User Interfaces 2

PROGRAMMING DESIGN USING JAVA (ITT 303) Unit 7

Graphical User Interfaces 2

Java Programming Fundamentals. Visit for more.

Chapter 10: Web Application Development. Informatics Practices Class XII. By- Rajesh Kumar Mishra. KV No.1, AFS, Suratgarh

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

Chapter 2: Using Data

Getting Started with IDE Programming

Graphical User Interfaces 2

Class XII (Theory) Class XII

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

COURSE DESIGN Class XII ( ) (THEORY)

GUI Event Handlers (Part II)

CS 251 Intermediate Programming GUIs: Components and Layout

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

CS 201 Advanced Object-Oriented Programming Lab 6 - Sudoku, Part 2 Due: March 10/11, 11:30 PM

Chapter 17: Table & Integrity Contraints. Informatics Practices Class XII. By- Rajesh Kumar Mishra. KV No.1, AFS, Suratgarh

Prototyping a Swing Interface with the Netbeans IDE GUI Editor

Chapter 16: Advanced MySQL- Grouping Records and Joining Tables. Informatics Practices Class XII. By- Rajesh Kumar Mishra

Chapter 18. Advanced graphics programming

Flow of Control. Chapter 3

Full file at

Lecture (06) Java Forms

Unit 6: Graphical User Interface

Introduction to Graphical User Interfaces (GUIs) Lecture 10 CS2110 Fall 2008

Is image everything?

COURSE DESIGN CLASS XII ( ) (THEORY) Networking and Open Standards 10 Marks (20 Theory+4 Practical) Periods

Containers. Atomic Components. Containment Hierarchy. Example Example 3.3 (revisited) Example DemoSwing.java

Example 3-1. Password Validation

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

CompSci 230 S Programming Techniques. Basic GUI Components

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

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

Graphical User Interface

MONTHLY SYLLABUS SESSION CLASS-XI SUBJECT : INFORMATICS PRACTICES (065) LANGUAGE JAVA, MYSQL

SPLIT UP SYLLABUS SUBJECT: INFORMATICS PRACTICES (065) SESSION: Class XI (Theory) Duration: 3 hours Total Marks: 70

To gain experience using GUI components and listeners.

Graphics. Lecture 18 COP 3252 Summer June 6, 2017

Chapter 12 GUI Basics

GUI Forms and Events, Part II

Swing UI. Powered by Pentalog. by Vlad Costel Ungureanu for Learn Stuff

Guessing Game with Objects

Getting started with Ms Access Getting Started. Primary Key Composite Key Foreign Key

TIME : 3 Hrs MAX. MARKS : 70 SET 1

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.

CSCI 201L Midterm Written SOLUTION Fall % of course grade

Downloaded from

CS410G: GUI Programming. The Model/View/Controller Pattern. Model. Controller. View. MVC is a popular architecture for building GUIs

This document describes the installation procedure for Embed-SE (Simulation Edition)

POS Designer Utility

Contents Introduction 1

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

StudyCBSENotes.com 1 COURSE DESIGN. Class XII ( ) (THEORY)

MVC Table / Delegation

Building Java Programs Bonus Slides

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

Introduction to Graphical Interface Programming in Java. Introduction to AWT and Swing

All the Swing components start with J. The hierarchy diagram is shown below. JComponent is the base class.

Computer Science 210: Data Structures. Intro to Java Graphics

CSE 331. Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT

Frames, GUI and events. Introduction to Swing Structure of Frame based applications Graphical User Interface (GUI) Events and event handling

Graphical User Interface (GUI)

Java Foundations John Lewis Peter DePasquale Joe Chase Third Edition

Swing. By Iqtidar Ali

Chapter 3: JAVA GUI Programming

CSE 331. Event- driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT

Candy is Dandy Project (Project #12)

CS Fall Homework 5 p. 1. CS Homework 5

Starting Excel application

Using the Customize Dialog Box

Transcription:

Chapter 8: GUI Dialog & Table Informatics Practices Class XII By- Rajesh Kumar Mishra PGT (Comp.Sc.) KV No.1, AFS, Suratgarh e-mail : rkmalld@gmail.com

Objective In this presentation, you will learn about the following- JDilog Swing Control: Design & implementation. JOptionPane: Using pre-defined, built-in dialog control. JTable Swing Control: Displaying Data in Tabular Form using JTable Control.

GUI Dialogs in JAVA- Introduction A Dialog box is a small separate sub-window that appears to either provide or request information to/from the users. Dialog Boxes are used in the application for user-friendly interaction. Java provides extensive support for dialogs. It offers the following dialog types- JDialog: General purpose dialog using JDialog class. JOptionPane: Predefined and ready-to-use buil-in dialog box. JFileChooser: Dialog for choosing files. JColorChooser: Dialog for choosing color.

JDialog A Simple General purpose dialog The JDialog is a swing window dialog equipped with Minimise, Maximise and Close functionality. JDialog creates a standard pop-up window for displaying desired information related to your application. Steps to Attach a JDIalog Control- 1. Design an application as required and drag Dialog control from swing palette and drop it into the application. 2. To open Dialog frame, double click on jdialog node under other component in Inspector window. 3. Attach message button and title in Dilog control as per requirement. 4. Attach the following ActionPerformed event handler of attached button. jdialog1.dispose(); 5. Now switch to Frame by double clicking on JFrame node in Inspector window. 6. Attach the following code on button from where you want to run the dialog. jdialog.setvisible(true);

Working with Dialog Control A dialog control is a control that can be used to display messages in the application. It may contains message, image and buttons etc. Add jdialog control from swing controls and customize it as per you requirement with text, image and buttons. It can be invoked in ActionPerformed Event of a button in top level container jframe by jdialog1.setvisible(true) command. You can set text at run time by jdialog1.settext() method before invoking it. Top level container frame setvisible(true) jdialog control Close Have a good day.. OK jdialog1.setvisible(true); Dispose() jdialog1.dispose();

JOptionPane : Built-In Dialog of JAVA JOptionPane allows to create pop-up window or dialog with predefined style. A JoptionPane Dialog window comprises the following elements- Icon: A joptionpane provides four types of Icons, these are- Error (X), Information (i), Warning (!) and Question (?) Message: A text to convey the information to user. Input Area: It allows user to give input using Text box or combo. Button(s): Set of buttons like OK, Cancel, Yes, No etc.

JOptionPane Dialog Types: Java provides four types of Dialogs which can be used as per requirement. Dialog Types Message Dialog Input Dialog Confirm Dialog Option Dialog Method showmessagedialog() showinputdialog() showconfirmdialog() showoptiondialog() Description Used to inform user by displaying a message. It includes OK button only. Used to get user input using JTextField, JComboBox etc. Used to ask a user to confirm some information with Yes/No or OK/Cancel buttons. You may customize these dialog with text messages and buttons as per need

JOptionPane Dialog Types: Message Dialog Confirm Dialog Title Icon Buttons Message to be displayed Text Field Input Dialog

Working with JOptionPane To use the JoptionPane dialog control in the application, you must import the following class(s). import.javax.swing.*; In general, the following syntax of methods along with optional parameters can be used- JoptionPane.show ([frame name],< Message > Frame Name: [,< Title >] [,Option Type] [,Message Type]) Generally null is used, since current frame is assumed to display dialog boxes. Message: User given string to covey the message. Title: Text to be displayed as Title on the Title bar.

Working with JOptionPane Option Type: It determines the Buttons to be displayed on the dialog. The following values or equivalent code may be used. Value -1 0 1 Equivalent code JOptionPane.DEFAULT_OPTION JOptionPane.YES_NO_OPTION JOptionPane.YES_NO_CANCEL_OPTION Buttons OK button only. YES and No button. YES, NO and CANCEL 2 JOptionPane.OK_CANCEL_OPTION OK and CANCEL button Message Type: It determines the Icon to be displayed. The values are- Value -1 0 1 2 3 Equivalent code JOptionPane.PLAIN_MESSAGE JOptionPane.ERROR_MESSAGE JOptionPane.INFORMATION_MESSAGE JOptionPane.WARNING_MESSAGE JOptionPane.QUESTION_MESSAGE Buttons No Icon. X Icon. i Icon.! Icon? Icon

How to use JOptionPane dialog You can invoke JOptionPane Dialogs by using.show Dialog() method in the coding where you want to display the dialog box. Examples: JOptinPane.showMessageDialog(null, JAVA Welcomes You ); JOptinPane.showMessageDialog(null, Hi.. I am Amit ); JOptinPane.showMessageDialog(null, JAVA Welcomes You, Hi.. ); String n= JOptinPane.showInputDialog(null, Enter your Name? ); String n= JOptinPane.showInputDialog(null, Enter your Name?, Input Name ); String n= JOptinPane.showInputDialog(null, Enter your Name?, 0,3); JOptinPane.showConfirmDialog(null, Want to exit? ); JOptinPane.showConfirmDialog(null, Want to exit?,0,3); JOptinPane.showConfirmDialog(null, Are you sure to delete,1,2);

Return Value of JOptionPane dialog Value returned by Input Dialog: ShowInputDialog() returns a string value which can be directly assigned on a string type variable. You may use parse () method to convert it into other data types like int or float etc. Once value has been converted on a variable, it can be used in the application. String n=joptionpane.showinputdialog(null, Enter Name? ); String age=joptionpane.showinputdialog(null, Enter Age? ); int a=integer.parseint(age);

Return Value of JOptionPane dialog Value returned by Confirm & Option Dialog: Sometimes it is required to check the response of user i.e. which button is pressed, so that application can respond accordingly. Both showconfirmdialog() and showoptiondialog() returns int type value which can be compared with the following constants to determine the status of button pressed by the user. Returned Value JOptionPane.YES_OPTION JOptionPane.OK_OPTION JOptionPane.NO_OPTION JOptionPane.CANCEL_OPTION JOptionPane.CLOSE_OPTION Indication YES button is pressed OK button is pressed NO button is pressed CANCEL button is pressed User closed the dialog using X button int ans=joptionpane.showconfirmdialog(null, Want to exit? ); If (ans==joptionpane.yes_option) System.exit(0);

JTable Swing Control Sometimes it is required to represent information in tabular form. Java provides JTable swing control to handle data in a table. A table consists of certain rows and columns. Table Roll 1 2 Name Amit Ajay Marks Properties & Methods of JTable control: 80 90 Grade A table model works behind JTable control which contains source data for JTable. Java provides multiple Table model, but DefaultTableModel is commonly used. B A Cell Method int getcolumncount() int getrowcount() Object getvalueat(row,col) Description Returns the number of column in the table Returns the number of rows in the table Returns value of given row & column of the table The most commonly used properties are Font, Foreground, Tool Tip Text and Enabled etc.

Designing a Simple Table 1. Create an application and attach a JFrame (Form). 2. Attach Table control to the frame

Designing a Simple Table 3. Right click on the Table control and select Table Contents..

Designing a Simple Table 3. Select Column tab 4. Rename all column Titles like Roll, Name, Marks and Grade etc.

Designing a Simple Table 5. Select Row tab 6. Set Count as 0 Now attach Button controls on the Form and write TODO code in ActionPerformed event for the specific functionality.

Working with JTable Insert the following import statement at the beginning. import javax.swing.table.*; Obtain table s model in a DefaultTableModel object as per the following (Suppose tm is an identifier and jtable1 is table)- DefaultTableModel tm=(defaulttablemodel) jtable1.getmodel(); Adding Rows 1. Create an object array and put values (directly or using TextFields) in the order in which jtable is designed. object myrow[ ]= {5, Mukesh Kumar,60, B }; object myrow[ ]= {jtextfield1.gettext(), jtextfield2.gettext(), jtextfield3.gettext(), jtextfield4.gettext()}; 2. Add object array in TableModel by using addrow() method. tm.addrow(myrow); Deleting Rows To delete a row, you may call removerow() method with row number to be deleted. tm.removerow(2);

Accessing Cell Values in the Application Once records have been added in a table, you can access cell value directly using Object type variable. // Example - to get sum of a column of the table /* Asume a Table (jtable1) contains Roll, Name, Marks and Grade column*/ /*The following code can be added in TODO section of a button*/ int row = jtable1.getrow(); int sum=0; Object val= new Object(); for (int i=0; i<row ; i++) { val=jtable.getvalueat(i,2); sum = sum + Integer.parseInt(val); } JOptionPane.showMessageDialog(null, Sum of Marks: +sum);