Computer Science [3] Java Programming II - Laboratory Course Lab 4: Common GUI Event Types and Listener Interfaces Layout Mangers Faculty of Engineering.

Slides:



Advertisements
Similar presentations
Introduction to Java 2 Programming
Advertisements

Java GUI building with the AWT. AWT (Abstract Window Toolkit) Present in all Java implementations Described in (almost) every Java textbook Adequate for.
Graphic User Interfaces Layout Managers Event Handling.
F27SB2 Programming Languages
1 Chapter 7 Graphics and Event Handling. 2 Overview The java.awt and javax.swing packages and their subpackages support graphics and event handling. Many.
Event Handling. In this class we will cover: Basics of event handling The AWT event hierarchy Semantic and low-level events in the AWT.
Chapter 11 Exception Handling and Event Handling.
Advanced Java Class GUI – part 1. Intro to GUI GUI = Graphical User Interface -- “Gooey” Just because it’s “gooey” does not mean you may write messy code.
Graphical User Interface (GUI) Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
1 GUI Elements in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
GUI Layout Managers Arkadiusz Edward Komenda. Outline Components and Containers Layout Managers Flow Layout Grid Layout Border Layout Nested Containers.
Chapter 13: Advanced GUIs and Graphics J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
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.
Graphical User Interface (GUI) Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
A.k.a. GUI’s.  If you want to discuss your Lab 2 grade come see me this week. ◦ Office: 436 ERB. One hour prior to class ◦ Open to Appointments MWF 
Java Programming Chapter 10 Graphical User Interfaces.
20-753: Fundamentals of Web Programming Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 16: Java Applets & AWT Fundamentals of Web Programming.
Chapter 13 Advanced GUIs and Graphics. Chapter Objectives Learn about applets Explore the class Graphics Learn about the class Font Explore the class.
Welcome to CIS 083 ! Events CIS 068.
Java Software Solutions Lewis and Loftus Chapter 10 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Graphical User Interfaces --
Java Programming: From Problem Analysis to Program Design, 4e Chapter 12 Advanced GUIs and Graphics.
Graphical User Interface CSI 1101 N. El Kadri. Plan - agenda Graphical components Model-View-Controller Observer/Observable.
Java Software Solutions Lewis and Loftus Chapter 10 Copyright 1997 by John Lewis and William Loftus. All rights reserved. 1 Graphical User Interfaces --
Java Programming: Advanced Topics 1 Common Elements of Graphical User Interfaces Chapter 6.
Dale Roberts GUI Programming using Java - Event Handling Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer.
Slides prepared by Rose Williams, Binghamton University ICS201 Lecture 13 : Swing I King Fahd University of Petroleum & Minerals College of Computer Science.
Graphical User Interface Components: Part 1 Chapter 11.
 2002 Prentice Hall, Inc. All rights reserved Introduction Graphical User Interface (GUI) –Gives program distinctive “look” and “feel” –Provides.
– Advanced Programming P ROGRAMMING IN Lecture 21 Introduction to Swing.
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.
1 Unit 5 GUI Aum Amriteshwaryai Namah. 2 Overview Shall learn how to reuse the graphics classes provided by Java for constructing Graphical User Interface.
Graphics and Event-Driven Programming in Java John C. Ramirez Department of Computer Science University of Pittsburgh.
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 12 1 TOPIC 13B l Buttons and Action Listeners Window Interfaces Using Swing Objects.
Object Oriented Programming Engr. M. Fahad Khan Lecturer, Software Engineering Department University of Engineering & Technology, Taxila.
Java Applets: GUI Components, Events, Etc. Ralph Westfall June, 2010.
Introduction to Java Beans CIS 421 Web-based Java Programming.
Java Programming Applets. Topics Write an HTML document to host an applet Understand simple applets Use Labels with simple AWT applets Write a simple.
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.
Event Handling. 2 GUIs are event driven –Generate events when user interacts with GUI e.g., moving mouse, pressing button, typing in text field, etc.
The Abstract Window Toolkit (AWT) supports Graphical User Interface (GUI) programming. AWT features include: a rich set of user interface components; a.
Object Oriented Programming.  Interface  Event Handling.
GUI DYNAMICS Lecture 11 CS2110 – Fall GUI Statics and GUI Dynamics  Statics: what’s drawn on the screen  Components buttons, labels, lists, sliders,
Computer Science [3] Java Programming II - Laboratory Course Lab 4 -1 : Introduction to Graphical user interface GUI Components Faculty of Engineering.
1 Layout Managers Layout managers –Provided for arranging GUI components –Provide basic layout capabilities –Processes layout details –Programmer can concentrate.
 Figure illustrates a hierarchy containing many event classes from the package java.awt.event.  Used with both AWT and Swing components.  Additional.
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
1 Lecture 8: User Interface Components with Swing.
1 Graphical User Interfaces Introduction zUsers have become accustomed to using a graphical user interface (GUI) through which they interact with a program.
Jozef Goetz Credits: Copyright  Pearson Education, Inc. All rights reserved. expanded by J. Goetz, 2016.
CSC 205 Programming II Lecture 7 AWT – Event Handling & Layout.
GUIs & Event-Driven Programming Chapter 11 Review.
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 7 Event-Driven Programming and Basic GUI Objects.
GUI Programming using Java - Event Handling
CSC 205 Programming II Lecture 5 AWT - I.
Welcome To java
Java FX: Scene Builder.
Chapter 9: Graphical User Interfaces
Aum Amriteshwaryai Namah
Java Events. Java Events Important definitions Overridden method Class vs. abstract class vs. interface Event Handling Definition Main components Windows.
Layout Managers Layout Manager—an object that decides how components will be arranged in a container Some types of layout managers: BorderLayout FlowLayout.
Responding to Events Event Handling in Java
GUI Programming III: Events
Chap 7. Building Java Graphical User Interfaces
Chapter 13: Advanced GUIs and Graphics
Graphical User Interfaces -- Introduction
Graphical User Interface
Presentation transcript:

Computer Science [3] Java Programming II - Laboratory Course Lab 4: Common GUI Event Types and Listener Interfaces Layout Mangers Faculty of Engineering & IT Software Engineering Department Eng.Omar Al-Nahal Eng.Omar Al-Nahal

2 Event-Driven Programming b Programs with GUIs must respond to events, generated by GUI components, that indicate that specific actions have occurred. b A special category of classes, called listeners, wait for events to occur. b Therefore, a GUI program is composed of: the code that presents the GUI to the userthe code that presents the GUI to the user the listeners that wait for events to occurthe listeners that wait for events to occur the specific code that is executed when events occur.the specific code that is executed when events occur.

3 Event-Driven Programming b b There is a listener interface defined for each event type b b Each listener interface contains the abstract methods required to respond to specific events b b A listener class implements a particular listener interface b b Listeners are "added" to a particular GUI component b b When a component generates an event, the method corresponding to that event is executed in the listener

4 The GUI Program Model Listeners Program- specific GUI Event effects Add listeners Handle events

Common GUI Event Types and Listener Interfaces For each event-object type, there is typically a corresponding event- listener interface. An event listener for a GUI event is an object of a class that implements one or more of the event-listener interfaces from packages java.awt.event & javax.swing.event. Many of the event-listener types are common to both Swing and AWT components. Such types are declared in package java.awt.event To Make an Interactive GUI Program To make an interactive GUI program, you need: Components - buttons, windows, menus, etc. Events - mouse clicked, window closed, button clicked, etc. and event handlers (methods) Event listeners (interfaces) and event handlers (methods) - listen for events to be trigged, and then perform actions to handle them.

Event-Handling Model (1) ActionEvent AdjustmentEvent TextEvent ComponentEvent ItemEvent ContainerEvent FocusEvent PaintEvent WindowEvent InputEvent KeyEvent MouseEvent CLASS some event classes in package java.awt.event

Event-Handling Model (2) b b Three parts of the event-handling mechanism event source: the GUI component with which the user interacts event object: encapsulated information about the occurred event event listener: an object which is notified by the event source when an event occurs, and provides responds to the event b b The programmer must perform two tasks to process a GUI event 1.register an event listener An object of a class that implements one or more of the event-listener interfaces from packages java.awt.event and javax.swing.event 2.implement an event handling method Event-listener interface of package java.awt.event

8 Lists b b A list, in the Java GUI sense, is used to display a list selectable strings. b b A list component can contain any number of strings and can be instantiated to allow multiple selections within it. b b The size of the list is specified by the number of visible rows or strings within it. b b A scrollbar will automatically appear on the right side of a list if the number of items exceed the visible area.   A list is defined by the List class See List.java

9 Scrollbars b A scrollbar is a slider that indicates a relative position or quantity. b They are automatic on text areas and list components, but can be used independently. b The position of the slider in the range corresponds to a particular numeric value in a range associated with the scrollbar.  A scrollbar is defined by the Scrollbar class

10 Layout Managers   There are five predefined layout managers in the java.awt package: Flow layout Border layout Grid layout Card layout Grid bag layout b b Each container has a particular layout manager associated with it by default. b b A programmer can also create custom layout managers

11 Flow Layout b b Components are placed in a row from left to right in the order in which they are added. b b A new row is started when no more components can fit in the current row. b b The components are centered in each row by default. b b The programmer can specify the size of both the vertical and horizontal gaps between the components. b b Flow layout is the default layout for panels and applets See Flow.java

12 Grid Layout b b Components are placed in a grid with a user-specified number of columns and rows b b Each component occupies exactly one grid cell b b Grid cells are filled left to right and top to bottom b b All cells in the grid are the same size b Defines five locations each of which a component or components can be added North, South, East, West, and Center Border Layout See Grid.java See Border.java

13 Border Layout North South West East Center Sample: Color, ShowColor, Font, Menu212,Color ShowColorFontMenu212 Painter, PanelDemo, LinesRectsOvals, PainterPanelDemoLinesRectsOvals LookAndFeelDemo, BoxLayoutDemo, JDesktopPaneLookAndFeelDemo BoxLayoutDemoJDesktopPane

For More InformationSupplemental Reading For More Information - Supplemental Reading