Lecture 18: Events; Cool Applets Yoni Fridman 7/30/01 7/30/01.

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

What Was I Thinking??. Key Terms 1. Control 1. Control 2. Design Mode 2. Design Mode 3. Event 3. Event 4. Form 4. Form 5. Interface 5. Interface 6. Properties.
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.
CS7026 jQuery Events. What are Events?  jQuery is tailor-made to respond to events in an HTML page.  Events are actions that can be detected by your.
ITEC220 GUI Lecture – Part 2 References  Java Software Solutions,” by Lewis & Loftus  Chapter 7  Chapter 8  Chapter 9  Java Foundations-Introduction.
Event Handling Events and Listeners Timers and Animation.
Chapter Day 10. © 2007 Pearson Addison-Wesley. All rights reserved4-2 Agenda Day 10 Questions from last Class?? Problem set 2 posted  10 programs from.
COMP 14: Applets June 21, 2000 Nick Vallidis. Announcements zP6 is due Friday.
Event Handling. In this class we will cover: Keyboard Events Mouse Events Focus Events Action Interface Multicasting.
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.
Chapter Day 9. © 2007 Pearson Addison-Wesley. All rights reserved4-2 Agenda Day 8 Questions from last Class?? Problem set 2 posted  10 programs from.
ELC 312 Day 16. © 2004 Pearson Addison-Wesley. All rights reserved Agenda Questions? Capstone Proposals Due Problem set 3 Corrected  Poor performance.
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 
Welcome to CIS 083 ! Events CIS 068.
Field Trip #26 Create a Find a Word Puzzle in Java By Keith Lynn.
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.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Graphical User Interfaces Revisited Material from Chapters
Chapter 5: Enhancing Classes Presentation slides for Java Software Solutions Foundations of Program Design Second Edition by John Lewis and William Loftus.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Event Driven Programming, The.
Java GUI’s are event driven, meaning they generate events when the user interacts with the program. Typical events are moving the mouse, clicking a mouse.
Session 11 Border Layout, using Panels, Introduction to PinBallGame.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 14 Event-Driven Programming.
Chapter 10: Applets and Advanced Graphics The Applet Class The Applet Class The HTML Tag The HTML Tag Passing Parameters to Applets Passing Parameters.
7/3/00SEM107- © Kamin & ReddyClass 11 - Events - 1 Class 11 - Events r A couple of odds & ends m Component sizes  switch statement r Event types r Catching.
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 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.
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.
MSc Workshop - © S. Kamin, U.Reddy Lect 4 - Events - 1 Lecture 4 – Event Handling r Painting r Event types r Catching different event types.
COMP 321 Week 2. Outline Event-Driven Programming Events, Event Sources, Event Listeners Button and Timer Events Mouse Events, Adapters.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 12 Event-Driven Programming.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 21.1 Test-Driving the Painter Application.
Understand the difference between applets and applications Identify meaningful applet resources for academic subjects Create and demonstrate a basic Java.
Object Oriented Programming.  Interface  Event Handling.
Agenda Introduction. Event Model. Creating GUI Application. Event Examples.
COSC 4126 User Interaction User Interaction capturing and responding to input events.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4: Events Programming with Alice and Java First Edition by John Lewis.
(c) by Elizabeth Sugar Boese.1 Chapter 6 Events - Lecture Slides.
Creating User Interfaces Event-Driven Programming.
Graphical User Interfaces A Graphical User Interface (GUI) in Java is created with at least three kinds of objects: –components, events, and listeners.
1 Event Handling – Lecture 4 Prepared by: Ahmad Ramin Rahimee Assistant Professor ICTI.
Rina System development with Java Instructors: Rina Zviel-Girshin Lecture 10.
1/18H212Mouse and Timer Events H212 Introduction to Software Systems Honors Lecture #16: Mouse and Timer Events October 26, 2015.
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.
1 Chapter 3 Event-Driven Programming. 2 Objectives F To explain the concept of event-driven programming (§12.2). F To understand event, event source,
CSI 3125, Preliminaries, page 1 Event Handling. CSI 3125, Preliminaries, page 2 Event Handling An Event Change in the state of an object is known as event.
Mouse Events GUI. Types of Events  Below, are some of the many kinds of events, swing components generate. Act causing EventListener Type User clicks.
Swing GUI Components So far, we have written GUI applications which can ‘ draw ’. These applications are simple, yet typical of all Java GUI applications.
1 Lecture 8: User Interface Components with Swing.
JavaScript Events Java 4 Understanding Events Events add interactivity between the web page and the user You can think of an event as a trigger that.
Jaeki Song ISQS6337 JAVA Lecture 10 Applets. Jaeki Song ISQS6337 JAVA Applet Applets run within the Web browser environment –Applets bring dynamic interaction.
JavaScript Events. Understanding Events Events add interactivity between the web page and the user Events add interactivity between the web page and the.
Prepared by: Dr. Abdallah Mohamed, AOU-KW Unit7: Event-driven programming 1.
Chapter 5: Enhancing Classes Presentation slides for Java Software Solutions Foundations of Program Design Second Edition by John Lewis and William Loftus.
Events and Event Handling
Chapter 12 Event-Driven Programming
Advanced User Interfaces
Processing Timer Events
Programming in Java Event Handling
GUI Event Handling Nithya Raman.
Event Driven Programming
The mouse controls the movement of the pointer on your screen.
Chapter 15 Event-Driven Programming and Animations
Web Design & Development Lecture 12
Tonga Institute of Higher Education
ITEC220 GUI Lecture – Part 2 References
Presentation transcript:

Lecture 18: Events; Cool Applets Yoni Fridman 7/30/01 7/30/01

OutlineOutline ä Events ä Event actions ä Firing an event ä Listening to an event ä Mouse events ä Mouse motion events ä Components ä Cool applets ä Events ä Event actions ä Firing an event ä Listening to an event ä Mouse events ä Mouse motion events ä Components ä Cool applets

EventsEvents ä An event is an action triggered by the user, such as a mouse click or a key press. ä When an event occurs, an object is created that contains information about that event. ä There are several different classes of events. ä For example, if the mouse is clicked, an object of the class MouseEvent is created. ä This object contains the x and y coordinates of where the mouse was when it was clicked. ä But how is an event object created? ä An event is an action triggered by the user, such as a mouse click or a key press. ä When an event occurs, an object is created that contains information about that event. ä There are several different classes of events. ä For example, if the mouse is clicked, an object of the class MouseEvent is created. ä This object contains the x and y coordinates of where the mouse was when it was clicked. ä But how is an event object created?

EventsEvents ä Certain objects (like applets, buttons, menus, etc.) generate event objects when an event occurs. We say that they fire an event. ä Other objects, called listeners, wait for an event to be fired and then respond. ä Certain objects (like applets, buttons, menus, etc.) generate event objects when an event occurs. We say that they fire an event. ä Other objects, called listeners, wait for an event to be fired and then respond. Generator This object fires an event Listener This object waits for and responds to an event The generator passes the event object to the listener Event

Mouse Events ä There are five events of the MouseEvent class: ä Mouse pressed – the mouse button is pressed down. ä Mouse released – the mouse button is let go of. ä Mouse clicked – the mouse button is pressed and then released. ä Mouse entered – the mouse pointer is moved over a component. ä Mouse exited – the mouse pointer is moved off of a component.  To use these events, we have to add implements MouseListener to our class definition. ä There’s a method to listen for each of these events – we must provide a definition for each, even if it has an empty body, and pass it a MouseEvent argument. ä There are five events of the MouseEvent class: ä Mouse pressed – the mouse button is pressed down. ä Mouse released – the mouse button is let go of. ä Mouse clicked – the mouse button is pressed and then released. ä Mouse entered – the mouse pointer is moved over a component. ä Mouse exited – the mouse pointer is moved off of a component.  To use these events, we have to add implements MouseListener to our class definition. ä There’s a method to listen for each of these events – we must provide a definition for each, even if it has an empty body, and pass it a MouseEvent argument.

Mouse Motion Events ä There are two events of the MouseMotionEvent class: ä Mouse moved – the mouse is moved. ä Mouse dragged – the mouse is moved while the mouse button is held down.  To use these events, we have to add implements MouseMotionListener to our class definition.  If we use both mouse events and mouse motion events, we add implements MouseListener, MouseMotionListener. ä The methods for these events also take an argument of type MouseEvent. ä There are two events of the MouseMotionEvent class: ä Mouse moved – the mouse is moved. ä Mouse dragged – the mouse is moved while the mouse button is held down.  To use these events, we have to add implements MouseMotionListener to our class definition.  If we use both mouse events and mouse motion events, we add implements MouseListener, MouseMotionListener. ä The methods for these events also take an argument of type MouseEvent.

ComponentsComponents ä In Java, a component is a visual object that reacts to user input. ä Button ä Check box ä Scroll bar ä Button ä Check box ä Scroll bar ä List ä Choice ä List ä Choice

ComponentsComponents ä To add a component to your applet you first have to create a panel that will hold all the components: ä Panel myPanel = new Panel(); ä Then create the component: ä Button playButton = new Button(“Play”); ä Then set the component’s characteristics: ä playButton.setForeground(Color.black); ä playButton.setBackground(Color.lightGray); ä And finally add the component to the panel: ä panel.add(playButton); ä To add a component to your applet you first have to create a panel that will hold all the components: ä Panel myPanel = new Panel(); ä Then create the component: ä Button playButton = new Button(“Play”); ä Then set the component’s characteristics: ä playButton.setForeground(Color.black); ä playButton.setBackground(Color.lightGray); ä And finally add the component to the panel: ä panel.add(playButton);

HomeworkHomework ä None officially, but start studying for the final if you haven’t yet.