Unit 3 Graphical User Interface (GUI) Dr. Magdi AMER.

Slides:



Advertisements
Similar presentations
1 Event Listeners Some Events and Their Associated Event Listeners Act that Results in the EventListener Type User clicks a button, presses Enter while.
Advertisements

Chapter 16 GUI Programming Basics GUI Overview Event-Driven Programming Basics GUI Classes and Packages A Simple Window Program JFrame Class Java Components.
GUI. Swing Programs Four basic types of Top Level Window – JFrame, a top level window decorated like a native window – JWindow, an undecorated stand-alone.
Graphical User Interfaces
Basic Java – Interface design. Understand: How to use TextPad for Java How to define classes and objects How to create a GUI interface How event-driven.
Graphical User Interfaces Java’s AWT and Swing APIs.
Graphical User Interfaces (Part IV)
Java Software Development Paradigm Lecture # 12. Basics of GUI.
Examples. // A simple Frame with Rectangle Inside import java.awt.*; import javax.swing.*; import java.awt.geom.*; // For Shapes class rectComponent extends.
Drawing in a frame – Java GUI
Graphic User Interfaces Layout Managers Event Handling.
Problem Solving 6 GUIs and Event Handling ICS-201 Introduction to Computing II Semester 071.
Graphical User Interfaces, 2D Graphics & Game Programming.
1 Chapter 8 Objects and Classes Lecture 2 Prepared by Muhanad Alkhalisy.
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.
Things to mention public static void main(String [] args) –The starting point for a free-standing Java application (i.e. one not run from the DrJava interactions.
Introduction to Java Classes, events, GUI’s. Understand: How to use TextPad How to define a class or object How to create a GUI interface How event-driven.
Java Swing Recitation – 11/(20,21)/2008 CS 180 Department of Computer Science, Purdue University.
Event Driven Programming and GUIs Part 3 CS221 – 4/15/09.
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
Gui Interfaces a la Swing Up to speed with Swing by Steven Gutz is a good source It don’t mean a thing if it ain’t got that swing Duke Ellington.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 16 Java Fundamentals Java2 Graphical User Interfaces.
Graphical User Interfaces (GUIs) GUI: An application that uses graphical objects to interact with users GUI applications consist of: –Events: A user or.
IEEM 110 Computing in Industrial Applications Basic User Interface in Java.
Chapter 7 GUI design. So far this semester Have programmed in a stop and wait mode Program displays dialog box and waits for user to respond This was.
GUI and Event-Driven Programming Recitation – 3/6/2009 CS 180 Department of Computer Science, Purdue University.
More on Creating GUIs in Java using Swing David Meredith Aalborg University.
PROGRAMMING REVIEW Lab 2 EECS 448 Dr Fengjun Li and Meenakshi Mishra.
Java Programming Chapter 10 Graphical User Interfaces.
1 Event Driven Programming wirh Graphical User Interfaces (GUIs) A Crash Course © Rick Mercer.
Java Programming: From Problem Analysis to Program Design, Second Edition1  Learn about basic GUI components.  Explore how the GUI components JFrame,
Applets and Frames CS 21a: Introduction to Computing I First Semester,
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.
Graphical User Interface CSI 1101 N. El Kadri. Plan - agenda Graphical components Model-View-Controller Observer/Observable.
Java GUI CSCE 190 – Java Instructor: Joel Gompert Mon, July 26, 2004.
1 Event Driven Programs Rick Mercer. 2 So what happens next?  You can layout a real pretty GUI  You can click on buttons, enter text into a text field,
1 Outline 1 Introduction 2 Overview of Swing Components 3 JLabel 4 Event Handling 5 TextFields 6 How Event Handling Works 7 JButton 8 JCheckBox and JRadioButton.
Graphic User Interface. Graphic User Interface (GUI) Most of us interact with computers using GUIs. GUIs are visual representations of the actions you.
Graphics and Event-Driven Programming in Java John C. Ramirez Department of Computer Science University of Pittsburgh.
MSc Workshop - © S. Kamin, U. ReddyLect 3 - GUI -1 Lecture 3 - Graphical User Interfaces r GUI toolkits in Java API r JFrame r GUI components.
MT311 Java Application Development and Programming Languages Li Tak Sing ( 李德成 )
Applets and Frames. Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L14: GUI Slide 2 Applets Usually.
1 / 67 COP 3503 FALL 2012 SHAYAN JAVED LECTURE 14 Programming Fundamentals using Java 1.
Lec.10 (Chapter 8 & 9) GUI Jiang (Jen) ZHENG June 27 th, 2005.
CS1054: Lecture 21 - Graphical User Interface. Graphical User Interfaces vs. Text User Interface.
Java GUI. Graphical User Interface (GUI) a list a button a text field a label combo box checkbox.
Computer Programming with JAVA Chapter 7. Event-Driven Programming Using the AWT Event-Driven Programming GUIs and the AWT Simple Window Interfaces Components,
Chapter 7Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Chapter 7 l Event-Driven Programming »GUIs and the AWT l Simple Window.
Introduction to GUI in 1 Graphical User Interface 2 Nouf Almunyif.
Introduction to Java Chapter 9 - Graphical User Interfaces and Applets1 Chapter 9 Graphical User Interfaces and Applets.
CIS Intro to JAVA Lecture Notes Set 8 9-June-05.
Review_6 AWT, Swing, ActionListener, and Graphics.
Ajmer Singh PGT(IP) JAVA IDE Programming - I. Ajmer Singh PGT(IP) GUI (Graphical User Interface) It is an interface that uses a graphic entities along.
Graphical User Interfaces Tonga Institute of Higher Education.
Chapter 14: Introduction to Swing Components. Objectives Understand Swing components Use the JFrame class Use the JLabel class Use a layout manager Extend.
JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN © 2012 Pearson Education, Inc., Upper Saddle River,
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
Graphical User Interface (GUI)
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 28.1 Java Speech API 28.2 Downloading and.
Advanced Topics on Graphical User Interfaces CardLayout JTabbedPane JFrame.
Introduction to GUI Programming in Java: Frames, Simple Components, and Layouts.
5-1 GUIs and Events Rick Mercer. 5-2 Event-Driven Programming with Graphical user Interfaces  Most applications have graphical user interfaces to respond.
CIS 270—Application Development II Chapter 11—GUI Components: Part I.
Java Visual Applications CSIS 3701: Advanced Object Oriented Programming.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 7 ( Book Chapter 14) GUI and Event-Driven Programming.
Modular Event Handling
Graphical User Interface (pronounced "gooey")
Ellen Walker Hiram College
CiS 260: App Dev I Chapter 6: GUI and OOD.
Graphical User Interface
Presentation transcript:

Unit 3 Graphical User Interface (GUI) Dr. Magdi AMER

Java library has a class JFrame that implements the methods necessary to create a window on any operating system (Windows, Mac and UNIX). JFrame is generic. It does not have the features that we need (labels, buttons, etc). In real life, when we have a factory and we want to modify it’s product, we do not destroy the factory and build a new one, we simply add the machines that we need. Dr. Magdi Amer2 JFrame

Similarly, in OOP, when we want to modify the behavior of a class, we extend the class. This means that we take all the method of the class into the new one (without having to write the code again) so we can modify a method or add a new method. Dr. Magdi Amer3 Extending JFrame

Dr. Magdi Amer4 Simple Window

A window must extend the class JFrame. JFrame handle all the complexity of creating a window on any OS (remember same java code runs on any operating system. setSize ( 400, 140 ); – Creates a window width = 400, height = 140 setVisible( true ); – Makes the window visible. Dr. Magdi Amer5 Simple Window

Dr. Magdi Amer6

To add a title to the window, we use the code – super(title); – This code uses the constructor of the parent class JFrame. – Calling the constructor of the parent class is a good programming practice, and it may be sometimes necessary. Dr. Magdi Amer7 Simple Window

Dr. Magdi Amer8

GridLayout layout = new GridLayout(4,1);  Creates a layout of 4 rows and 1 column. Container c = getContentPane(); c.setLayout(layout );  Gets the main container of the window and assign to it the grid container Dr. Magdi Amer9 Advanced Window

JPanel p1 = new JPanel(); JPanel p2 = new JPanel(); JPanel p3 = new JPanel(); JPanel p4 = new JPanel(); c.add(p1); c.add(p2); c.add(p3); c.add(p4);  Creates 4 panels (containers) and place them on the window. Each will be placed on a new row. Dr. Magdi Amer10 Advanced Window

p1.add(new JLabel("First")); p2.add(new JLabel("Second")); p3.add(new JLabel("Third")); p4.add(new JLabel("Forth"));  Creates 4 labels and put each label on a panel. Dr. Magdi Amer11 Advanced Window

Dr. Magdi Amer12

JPanel p4 = new JPanel(); c.add(p4); p4.add(new JButton(“Forth")); When a button is placed on a panel  It takes its best fit size c.add(new JButton(“Third")); When a button is placed directly on the window  It expands to take all of the area Dr. Magdi Amer13 Advanced Window

Dr. Magdi Amer14 Event Based System

Dr. Magdi Amer15 Event Based System

this.addWindowListener(new MyWindowAdaptor()); Place an event listener to listen to events generated by the window. If we are interested in handling a specific event, we implement the method that handles this event. Public class MyWindowAdaptor extends WindowAdapter WindowAdapter  class responsible for handling all events of a window public void windowClosing(WindowEvent event) { System.exit(0); } Handles the window closing event and closes the application Dr. Magdi Amer16 Event Based System

Dr. Magdi Amer17 Handling the events of a button

Dr. Magdi Amer18 Handling the events of a button

TextFieldHandler handler = new TextFieldHandler(this); button.addActionListener(handler); Creates an event handler that is associated with a button public class TextFieldHandler implements ActionListener { protected MyFrame myFrame; public TextFieldHandler(MyFrame myFrame) { super(); this.myFrame = myFrame; } Creates an action listener and stores a reference to the window that it controls. Dr. Magdi Amer19 Handling the events of a button

public void actionPerformed(ActionEvent e) { String txt = myFrame.text1.getText(); JOptionPane.showMessageDialog(null, txt); } } Reads the text entered in the text field and displays the text in a popup. Dr. Magdi Amer20 Handling the events of a button

Dr. Magdi Amer21 Building Rich Interface

Dr. Magdi Amer22 Handling the events of a text field

Dr. Magdi Amer23 Handling the events of a text field

Dr. Magdi Amer24 Using a radio button

Dr. Magdi Amer25 Handling the events of a Radio Button

Dr. Magdi Amer26 Using a check box

Dr. Magdi Amer27 Handling the events of a check box

Dr. Magdi Amer28 Using a combo box

Dr. Magdi Amer29 Handling the events of a combo box

Dr. Magdi Amer30 Using Menus

Dr. Magdi Amer31 Using CardLayout

Dr. Magdi Amer32 Creating Panels

Dr. Magdi Amer33 Handling a menu event

Dr. Magdi Amer34 Handling a menu event

Dr. Magdi Amer35 2D Graphics