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.

Slides:



Advertisements
Similar presentations
Introduction to Java 2 Programming
Advertisements

Graphic User Interfaces Layout Managers Event Handling.
Fall 2007CS 225 Graphical User Interfaces Event Handling Appendix C.
Unit 091 Introduction to GUI Programming Introduction to User Interfaces Introduction to GUI Programming GUI Design Issues GUI Programming Issues Java.
Slides prepared by Rose Williams, Binghamton University Chapter 17 Swing I.
Slides prepared by Rose Williams, Binghamton University Chapter 17 Swing I.
Creating a GUI with Swing. Introduction Very useful link: Swing – is a part of JFC (Java Foundation.
Unit 111 Java GUI Components and Events  Learning Outcomes oDistinguish between GUI components and containers. oIdentify and distinguish top-level containers.
1 GUI Elements in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
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.
CPSC150 Week 12 Graphical User Interfaces Chapter 11.
GUI Programming in Java Tim McKenna GUI Programming Concepts l conventional programming: sequence of operations is determined by the program.
CC1007NI: Further Programming Week 5 Dhruba Sen Module Leader (Islington College)
Introduction to Java Swing “We are the sultans of swing” – Mark Knopfler.
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 
1 Java GUI programming. 2 On event-driven programming a user interface combines three functions: input, output, and data handling in batch-oriented processing.
GUI Programming in Java
Java Programming Chapter 10 Graphical User Interfaces.
ACM/JETT Workshop - August 4-5, ExceptionHandling and User Interfaces (Event Delegation, Inner classes) using Swing.
Welcome to CIS 083 ! Events CIS 068.
Java Swing, Events and MVC Optional Readings: Eckel’s Thinking in Java: Chap 14 (
Object Oriented Programming Ders 11: Interfaces Mustafa Emre İlal
MIT AITI 2003 Lecture 17. Swing - Part II. The Java Event Model Up until now, we have focused on GUI's to present information (with one exception) Up.
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.
Objectives of This Session
Chapter 9: Visual Programming Basics Object-Oriented Program Development Using Java: A Class-Centered Approach.
Session 27 Swing vs. AWT. AWT (Abstract Window ToolKit) It is a portable GUI library for stand-alone applications and/or applets. The Abstract Window.
GUIs in Java Swing, Events CS2110, SW Development Methods Readings: MSD, Chapter 12 Lab Exercise.
Ch 3-4: GUI Basics Java Software Solutions Foundations of Program Design Sixth Edition by Lewis & Loftus Coming up: GUI Components.
 2002 Prentice Hall, Inc. All rights reserved Introduction Graphical User Interface (GUI) –Gives program distinctive “look” and “feel” –Provides.
1 CSC111H Graphical User Interfaces (GUIs) Introduction GUIs in Java Understanding Events A Simple Application The Containment Hierarchy Layout Managers.
– 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.
CS Lecture 00 Swing overview and introduction Lynda Thomas
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.
Java Programming: Advanced Topics 1 Components and Facilities for Rich Graphical User Interfaces Chapter 7.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
The Abstract Window Toolkit (AWT) supports Graphical User Interface (GUI) programming. AWT features include: a rich set of user interface components; a.
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.
Week 6: Basic GUI Programming Concepts in Java Example: JFrameDemo.java container : a screen window/applet window/panel that groups and arranges components.
CIS Intro to JAVA Lecture Notes Set 8 9-June-05.
Creating a Window. A basic window in Java is represented by an object of the class Window in the package java.awt.
JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN © 2012 Pearson Education, Inc., Upper Saddle River,
Slides prepared by Rose Williams, Binghamton University ICS201 Lecture 15 : Swing III King Fahd University of Petroleum & Minerals College of Computer.
Lecture # 6 Graphical User Interface(GUI). Introduction A graphical user interface (GUI) presents a user- friendly mechanism for interacting with an application.
Java Swing, Events Readings: Just Java 2: Chap 19 & 21, or Eckel’s Thinking in Java: Chap 14 Slide credits to CMPUT 301, Department of Computing Science.
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
Swing GUI Components So far, we have written GUI applications which can ‘ draw ’. These applications are simple, yet typical of all Java GUI applications.
Lesson 28: More on the GUI button, frame and actions.
1 Lecture 8: User Interface Components with Swing.
Jozef Goetz Credits: Copyright  Pearson Education, Inc. All rights reserved. expanded by J. Goetz, 2016.
CIS 270—Application Development II Chapter 11—GUI Components: Part I.
Chapter 6 Building Java GUIs. MVC Model View Controller The model passes its data to the view for rendering The view determines which events are passed.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 7 ( Book Chapter 14) GUI and Event-Driven Programming.
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 7 Event-Driven Programming and Basic GUI Objects.
A Quick Java Swing Tutorial
Lecture 15 Basic GUI programming
CSC 205 Programming II Lecture 5 AWT - I.
Graphical User Interfaces
Welcome To java
Provision for GUIs in Java
Provision for GUIs in Java
Ellen Walker Hiram College
Event Driven Programming and Graphical User Interface
Graphical User Interface
Presentation transcript:

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 rudimentary AWT components are “heavyweight” in that have nonrudimentary native peers, which in this sense have “extra baggage.”

3 Overview Swing set components are “lightweight” for the most part in that they do not have native peers but are rather rendered using primitive graphics constructs such as lines and shaded regions. The Swing set has only four “heavyweight” components: JApplet, JFrame, JDialog, and JWindow.

4 Overview In the Swing set, JComponent s and their descendants are “lightweight.” The Swing set’s JComponent class extends the AWT’s Component class. Many AWT components (e.g., Button ) have Swing set equivalents (e.g., JButton ).

5 Event-driven programming Modern windows systems have an event- driven programming model. –An application in this model typically has a GUI to facilitate interaction. –User-generated actions such as mouse clicks generate events, which the system queues and then dispatches to event-handling procedures or “callbacks.”

6 Java event model The AWT and Swing set support an event- delegation model: –An event source such as a button can generate events. –An event listener is an object registered with the source to be notified when an event occurs. –A listener provides a callback to which an Event argument is passed.

7 Java event model An event listener implements a particular interface to signal that the listener is prepared to handle particular types of events. –For instance, listeners of button clicks and menu selections implement the ActionListener interface.

8 Java event model Event interfaces declare methods that, when defined by event listeners, serve as callbacks for particular events. –For instance, the ActionListener interface declares the method public void actionPerformed( ActionEvent );

9 Java event model The basic classes for event handling reside in the java.awt.event package. The Swing set augments this package with specialized event classes, e.g., classes to handle events on Swing set components such as JTree s.

10 Graphics basics Components and containers are at the core of Java graphics: –A component is a prebuilt part such as a button, a checkbox, a list, or a menu. –A container is a component that can embed other components. –Because containers are components, components can be nested inside of others.

11 Graphics basics A container has a layout manager that determines how embedded components are organized and arranged. –For instance, a FlowLayout arranges components such as buttons and labels in a left- to-right and top-to-bottom fashion.

12 Graphics basics The basic AWT top-level window is the Frame, and the basic Swing set top-level window is the JFrame. Java windows are constructed as invisible. A window can be made visible by invoking its show() method or its setVisible method with an argument of true.

13 Graphics basics The AWT and Swing set have a rich library of basic components such as buttons, labels, checkboxes, menu bars, menus (docked and popup), menu items, tool bars, and lists. The AWT and Swing set provide dialog windows of different types and modalities.

14 Model-View-Controller The Swing set has a model-view-controller architecture. –The model contains state information about a component. For instance, a scrollbar’s model stores information about the thumb’s position. –The view renders the component visually. –The controller handles event-driven interactions between the model and the view.

15 Model-View-Controller In the Swing set, basic components such as buttons do not expose their model. More advanced components such as JTree s and JTable s expose their models as properties (e.g., each has a public getModel() method). The Swing set integrates the view and controller as the UIDelegate.

16 Pluggable look and feel The Swing set supports PLAF or Pluggable Look and Feel for components. –Through PLAF, the same components can be rendered in the same style regardless of the underlying platform. –AWT components, by contrast, are rendered differently on different platforms.

17 Graphics context A graphics context is an object that encapsulates information used in drawing operations, e.g., line width and style. The AWT abstract Graphics class is the superclass for various graphics contexts. A graphics context is passed as an argument to the paint method, which can contain arbitrary drawing and display code.

18 Summary of Java graphics Because Java provides standard packages and classes for graphics, applications that use graphics remain portable. The relatively simple AWT package supports basic graphics and event handling. The Swing set augments and extends the basics supplied in the AWT package.