Week 6: Basic GUI Programming Concepts in Java Example: JFrameDemo.java container : a screen window/applet window/panel that groups and arranges components.

Slides:



Advertisements
Similar presentations
Event handling and listeners What is an event? user actions and context event sources and listeners Why should my programs be event- driven? User interaction.
Advertisements

Programming in Java; Instructor:John Punin Graphics and Graphical User Interfaces1 Programming in Java Graphics and Graphical User Interfaces.
Mouse Listeners We continue our examination of GUIs by looking at how to interact with the mouse –Just as Java creates Events when the user interacts with.
CS18000: Problem Solving and Object-Oriented Programming.
TCU CoSc Programming with Java Handling Events.
Managing Input Events in Swing Week 5 Workshop Lyn Bartram.
User Interface Design CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
Dale Roberts GUI Programming using Java - Mouse Events Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer.
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.
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 Events and Listeners Timers and Animation.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 14 GUI and Event-Driven Programming.
1 Gui Programming (Part I) Graphical User Interfaces (Part I) l Introduction to events. l A Brief history. l Event sources and listeners. l The delegation.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 14 GUI and Event-Driven Programming.
Creating a GUI with Swing. Introduction Very useful link: Swing – is a part of JFC (Java Foundation.
1 lecture 12Lecture 13 Event Handling (cont.) Overview  Handling Window Events.  Event Adapters Revisited.  Introduction to Components and Containers.
GUI Event Handling Nithya Raman. What is an Event? GUI components communicate with the rest of the applications through events. The source of an event.
10.1 AWT The AWT classes Users today expect a Graphical User Interface (GUI) Improves application usability Difficult to implement cross-platform.
Events in Java Swing Chris North cs3724: HCI. Typical command line program Non-interactive Linear execution program: main() { code; }
GUI Programming in Java Tim McKenna GUI Programming Concepts l conventional programming: sequence of operations is determined by the program.
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
Software Construction Lecture 10 Frameworks
Chapter 11 Java AWT Part I: Mouse Events (Optional) Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by S.N. Kamin,
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 GUI CSCE 190 – Java Instructor: Joel Gompert Mon, July 26, 2004.
Java GUIs and Graphics CNS Outline  Introduction  Events  Components  Layout managers  Drawing  Introduction  Events  Components  Layout.
Java Programming: Advanced Topics 1 Common Elements of Graphical User Interfaces Chapter 6.
GUIs in Java Swing, Events CS2110, SW Development Methods Readings: MSD, Chapter 12 Lab Exercise.
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.
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.
CS Lecture 00 Swing overview and introduction Lynda Thomas
COMP 321 Week 2. Outline Event-Driven Programming Events, Event Sources, Event Listeners Button and Timer Events Mouse Events, Adapters.
EE2E1. JAVA Programming Lecture 6 Event handling and building user interfaces with Swing.
Pravin Yannawar, DOCS, NMU Jalgaon. Basic Java : Event handling in AWT and Swing 2 Objectives of This Session Explain the Event handling mechanism & demonstrate.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
For (int i = 1; i
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 21.1 Test-Driving the Painter Application.
UID – Event Handling and Listeners Boriana Koleva
Java GUI. Graphical User Interface (GUI) a list a button a text field a label combo box checkbox.
Object Oriented Programming.  Interface  Event Handling.
Agenda Introduction. Event Model. Creating GUI Application. Event Examples.
GUIs Graphical User Interfaces. Everything coming together Known: – Inheritance – Interfaces – Abstract classes – Polymorphism – Exceptions New: – Events.
MT311 Java Application Development and Programming Languages Li Tak Sing ( 李德成 )
What Is an Event? Events – Objects that describe what happened Event sources – The generator of an event Event handlers – A method that receives an event.
Event Handling H_Func(Event) { } Event Receiver Object Source Object Registration.
Event Handling and Listeners in SWING The practice of event handling.
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
1 Lecture 8: User Interface Components with Swing.
Event Driven (Asynchronous) Programming. Event handling in Unity Subclass a class that contains event handling methods, and then override those methods.
Prepared by: Dr. Abdallah Mohamed, AOU-KW Unit7: Event-driven programming 1.
Java Swing What is swing? Swing is a ”Lightweight” GUI ToolKit for Java Different from AWT / SWT Toolkits for GUIs Few lines of code to produce GUI elements.
Lecture 15 Basic GUI programming
Events and Event Handling
Welcome To java
CHAPTER Reacting to the user.
Advanced User Interfaces
Computer Science 209 Graphics and GUIs.
GUI Event Handling Nithya Raman.
Event Driven Programming and Graphical User Interface
Introduction to Computing Using Java
GUI Programming using Java - Mouse Events
Web Design & Development Lecture 12
Week 8 Swing NetBeans GUI Builder
Events, Event Handlers, and Threads
Presentation transcript:

Week 6: Basic GUI Programming Concepts in Java Example: JFrameDemo.java container : a screen window/applet window/panel that groups and arranges components component: an object with visual representation Swing containers: JFrame, JApplet, JPanel AWT containers: Frame, Applet, Panel

Week 6: Basic GUI Programming Concepts in Java Java components: GUI elements such as buttons and scrollbars Windows: controls Unix: widgets Swing components: JButton, JScrollbar AWT components: Button, Scrollbar

Week 6: Basic GUI Programming Concepts in Java AWT(JDK 1.0, 1.1): java.awt.* - heavyweight components that rely on native GUI system Swing(Java 2): javax.swing.* - lightweight components that do not rely on native GUI

Week 6: Basic GUI Programming Concepts in Java basic programming steps - declare a container and components - add components to a container - register event listeners (i.e. objects that encapsulate event handlers) with the components and the container - create event listeners API documentation: inheritance hierarchy - java.awt.Container - java.awt.Component - javax.swing.JComponent (and subclasses) - javax.swing.JFrame - javax.swing.JApplet

Week 6: Basic GUI Programming Concepts in Java event-driven programming - a piece of code (i.e. event handler ) is attached to a GUI component - an event handler is executed when an event is activated / fired l Java: The Delegation Event Model

Week 6: Event Handling event source: a GUI component that generates / fires an event event: a user interaction(e.g. a click on the button) event listener: an object that has encapsulated event handlers to react to an event

Week 6: Event Handling l the delegation event model - a GUI element “delegates” the processing of an event to another piece of code - the event source generates/fires an event and “sends” it to event listeners

Week 6: Event Handling l the delegation event model - event listeners must be registered with an event source in order to receive notification Example: JButtonDemo.java, JButtonDemo2.java

Week 6: Event Handling programming procedure - write a class that implements an Listener interface - create an instance of this class (i.e. an event listener) - register the listener with a GUI component: add Listener ( )

Week 6: Event Handling l a listener interface has a list of standard event handlers (i.e. methods) API documentation - java.awt.event - event classes - listener interfaces - adapter classes

Week 6: Event Handling different ways of coding the event listeners - use of another top-level class: JButtonDemo - anonymous inner classes: JButtonDemo2, JFrameDemo, JFrameDemo2 - use of an adapter class: JFrameDemo4 - use of an existing class: JFrameDemo5

Week 6: Handling of Mouse Events MouseListener mousePressed( ), mouseClicked( ) mouseReleased( ), mouseEntered( ) mouseExited( ) MouseMotionListener mouseDragged( ), mouseMoved( ) l MouseAdapter, MouseMotionAdapter Example: MouseDemo.java

Week 6: Event Handling l one listener for multiple event sources Example: ActionApplet2.java Example: Time32Applet.java (Deitel & Deitel, p. 349/405)