CS 178: Programming with Multimedia Objects Aditya P. Mathur Professor of Computer Sciences Purdue University, West Lafayette Sept 9, 2004 Last update:

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

Mari Göransson - KaU - Datavetenskap - DAVD11 1 Java Event Handling --
TCU CoSc Programming with Java Handling Events.
Java Programming, 3e Concepts and Techniques Chapter 4 Decision Making and Repetition with Reusable Objects.
Jan Event Handling -1.1 Yangjun Chen Dept. Business Computing University of Winnipeg.
CS 180 Problem Solving and Object Oriented Programming Fall 2011 Notes for Week 10: Oct 24-28, 2011 Aditya Mathur Department of Computer Science Purdue.
Java Programming, 3e Concepts and Techniques Chapter 5 Arrays, Loops, and Layout Managers Using External Classes.
Event Handling Events and Listeners Timers and Animation.
Lecture 24 Applets. Introduction to Applets Applets should NOT have main method but rather init, stop, paint etc They should be run through javac compiler.
CS 178: Programming with Multimedia Objects Aditya P. Mathur Professor of Computer Sciences Purdue University, West Lafayette Sept 20, 2004 Last update:
Chapter 13: Advanced GUIs and Graphics J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
10.1 AWT The AWT classes Users today expect a Graphical User Interface (GUI) Improves application usability Difficult to implement cross-platform.
More on Creating GUIs in Java using Swing David Meredith Aalborg University.
Io package as Java’s basic I/O system continue’d.
Chapter 13 Advanced GUIs and Graphics. Chapter Objectives Learn about applets Explore the class Graphics Learn about the class Font Explore the class.
Java Programming, 3e Concepts and Techniques Chapter 3 Section 65 – Manipulating Data Using Methods – Java Applet.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 12 Advanced GUIs and Graphics.
1 CSC111H Graphical User Interfaces (GUIs) Introduction GUIs in Java Understanding Events A Simple Application The Containment Hierarchy Layout Managers.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 6 Decisions and Conditions.
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,
By: Stag and Fish; Party Animals.  Radio buttons are a way of letting users choose only one option of a list.
Java Event Handling CSIS 3701: Advanced Object Oriented Programming.
Dale Roberts GUI Programming using Java - Event Handling Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer.
MT311 Java Application Development and Programming Languages Li Tak Sing ( 李德成 )
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.
GUIs in Java Swing, Events CS2110, SW Development Methods Readings: MSD, Chapter 12 Lab Exercise.
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.
{ Dating Service ActionHandler Listener class details.
Chapter 12 1 TOPIC 13B l Buttons and Action Listeners Window Interfaces Using Swing Objects.
MSc Workshop - © S. Kamin, U.Reddy Lect 4 - Events - 1 Lecture 4 – Event Handling r Painting r Event types r Catching different event types.
CS 178: Programming with Multimedia Objects Aditya P. Mathur Professor of Computer Sciences Purdue University, West Lafayette August 25, 2004 Last update:
12/5/00SEM107, Kamin & ReddyReview - 34 Events Event types Catching different event types Getting information from components and events Distinguishing.
Java Applets: GUI Components, Events, Etc. Ralph Westfall June, 2010.
6c – Function Procedures Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming.
Interactive Programs Java API. Terminology Event—an action or occurrence, not part of a program, detected by the program. Events can be Event—an action.
CS-1020 Dr. Mark L. Hornick 1 Event-Driven Programming.
Java Applet Basics (2). The Body Mass Index Calculator.
CS 101 Test 2 Study Guide Acronyms RAD - Rapid Application Development IDE - Integrated Development Environment GUI - Graphical User Interface VB - Visual.
Object Oriented Programming.  Interface  Event Handling.
Agenda Introduction. Event Model. Creating GUI Application. Event Examples.
May 12, 1998CS102-01Lecture 7-3 Building GUIs in Java I CS Lecture 7-3 A picture's worth a thousand words.
Java Programming, 2E Introductory Concepts and Techniques Chapter 4 Decision Making and Repetition with Reusable Objects.
Kim B. Bruce, Andrea Danyluk & Tom Murtagh Williams College † Partially supported by NSF CCLI grant DUE Java: An Eventful Approach An innovative.
CS 180 Problem Solving and Object Oriented Programming Fall 2010 Notes for Week 11: Nov 1-5, 2010 Aditya Mathur Department of Computer Science Purdue University.
Chapter 6© copyright Janson Industries Java ▮ Comparing Strings/Objects ▮ Conditional logic ▮ if/else ▮ switch ▮ More GUI ▮ Check boxes ▮ Item listeners.
CS 178: Programming with Multimedia Objects Aditya P. Mathur Professor of Computer Sciences Purdue University, West Lafayette August 27, 2004 Last update:
Chapter 14: Introduction to Swing Components. Objectives Understand Swing components Use the JFrame class Use the JLabel class Use a layout manager Extend.
Graphical User Interfaces (GUI). PART ONE About GUI’s.
CS 180 Problem Solving and Object Oriented Programming Fall 2010 Notes for Week 9: Oct 18-22, 2010 Aditya Mathur Department of Computer Science Purdue.
CS 180 Problem Solving and Object Oriented Programming Fall 2010 Notes for Week 10: Oct 25-29, 2010 Aditya Mathur Department of Computer Science Purdue.
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,
Events (Chapter 11) Java Certification Study Group January 25, 1999 Mark Roth.
1 Event Handling – Lecture 4 Prepared by: Ahmad Ramin Rahimee Assistant Professor ICTI.
Event Handling CS 21a: Introduction to Computing I First Semester,
Java Programming Fifth Edition Chapter 13 Introduction to Swing Components.
GUI Programming using Java - Event Handling
Introduction Many Java application use a graphical user interface or GUI (pronounced “gooey”). A GUI is a graphical window or windows that provide interaction.
CSC 205 Programming II Lecture 5 AWT - I.
CompSci 230 S Programming Techniques
Chapter 4 The If…Then Statement
A First Look at GUI Applications Radio Buttons and Check Boxes
Responding to Events Event Handling in Java
A First Look at GUI Applications
Lecture 09 Applets.
Programming in Java Event Handling
Event Handling CS 21a: Introduction to Computing I
Introduction to Event Handling
Exception Handling and Event Handling
Chapter 5 Processing Input with Applets
Advanced GUIs and Graphics
Presentation transcript:

CS 178: Programming with Multimedia Objects Aditya P. Mathur Professor of Computer Sciences Purdue University, West Lafayette Sept 9, 2004 Last update: September 9, 2004 Events, if statement

Course Introduction  Aditya P. Mathur Learning Objectives What is an ActionListener? What is a event? What is an ItemListener? How to do things based on some condition? A simple “survey” applet

Course Introduction  Aditya P. Mathur Event Types An action, e.g. clicking a button, selecting an item in a checkbox, checking or unchecking a box. Event types: Action event: For example occurs when a button is clicked, double clicking an item in a List of items, selection of a MenuItem, pressing of the key in a TextField.. Item event: Occurs when the user clicks a CheckBox, CheckBoxMenuItem, a Choice item, or a List item. Several other event types will be discussed later.

Course Introduction  Aditya P. Mathur Handling Events Events generated by components such as Buttons and Checkboxes, are handled by Listeners. The actionPerformed method in the ActionListener class handles the action events. The input to each method is an event. The itemStateChanged method in the ItemListener class handles the item events.

Course Introduction  Aditya P. Mathur ActionListener and actionPerformed public void myApplet extends Applet implements ActionListener { To allow an applet to respond to action events, make sure you add “implements ActionListener” as follows to the applet declaration:

Course Introduction  Aditya P. Mathur ItemListener and itemStateChanged public void myApplet extends Applet implements ItemListener { To allow an applet to respond to item events, make sure you add “implements ItemListener” as follows to the applet declaration:

Course Introduction  Aditya P. Mathur Processing Action and Item events public void myApplet extends Applet implements ItemListener, ActionListener { To allow an applet to respond to item and action events, make sure you add “implements ItemListener, ActionListener” as follows to the applet declaration:

Course Introduction  Aditya P. Mathur The actionPerformed method public void actionPerformed (ActionEvent e) The actionPerformed method is declared as follows: Note that e is an input parameter. It is of type ActionEvent. Its value tells us the source of the event e.g. which button was clicked.

Course Introduction  Aditya P. Mathur Identifying the action event Object source = e.getSource(); The getSource method is used to obtain the source of an action event. For example will return the name of the button that was clicked.

Course Introduction  Aditya P. Mathur Associating an action command yesButton.setActionCommand(“INCREMENT”) An action command is a string. You can associate an action command with any button. For example: associates the action command INCREMENT with the yesButton.

Course Introduction  Aditya P. Mathur Retrieving the action command String eventCode =e.getActionCommand(); The action command associated with a button can be obtained as follows: sets the value of the eventCode variable to the action command associated with the event that occured.

Course Introduction  Aditya P. Mathur Processing an action event First step: Identify the source of event Second step: Process the event using appropriate code.

Course Introduction  Aditya P. Mathur The itemStateChanged method public void itemStateChanged (ItemEvent e) The itemStateChanged method is declared as follows: Note that e is an input parameter. It is of type ItemEvent. Its value tells us the source of the event e.g. which CheckBox was checked

Course Introduction  Aditya P. Mathur Identifying the item event Object source = e.getSource(); The getSource method is used to obtain the source of an item event (same as for the action event). For example will return the name of the CheckBox that was clicked.

Course Introduction  Aditya P. Mathur Associating an “item” command An “item” command is not associated with an item such as a CheckBox.

Course Introduction  Aditya P. Mathur Processing an item event First step: Identify the source of the event. Second step: Process the event using appropriate code.

Course Introduction  Aditya P. Mathur The if statement The if statement allows selective execution of Java statements. For example: if (customer.Age>60) { processSeniorCitizen(customer); } checks the age of a customer object and invokes the processSeniorCitizen() method only if the age is greater than 60.

Course Introduction  Aditya P. Mathur The if statement: format The if statement allows selective execution of Java statements. For example: if (condition) { sequence of Java statements separated by semicolon. There is no limit on the number of statements in this sequence. }

Course Introduction  Aditya P. Mathur Conditions A condition is any expression that evaluates to true or false. Here are some examples: age<65 speed>55 speed>65 && age<18 speed>65 && drinking age and speed are integer variables. drinking is a boolean variable. Compound condition using AND (&&)

Course Introduction  Aditya P. Mathur Relational and boolean operators Relational operators:, =, <> Boolean operators: && (and), || (or), ! (not) More details? Read Chapter 6 of the text.