CSC 243 – Java Programming, Spring, 2009 Week 9 Java’s Event Infrastructure.

Slides:



Advertisements
Similar presentations
An Introduction to Programming General Concepts. What is a program? A program is an algorithm expressed in a programming language. programming language.
Advertisements

Exception Handling. Background In a perfect world, users would never enter data in the wrong form, files they choose to open would always exist, and code.
Written by: Dr. JJ Shepherd
Exceptions Don’t Frustrate Your User – Handle Errors KR – CS 1401 Spring 2005 Picture – sysprog.net.
Exception Handling Chapter 15 2 What You Will Learn Use try, throw, catch to watch for indicate exceptions handle How to process exceptions and failures.
Exceptions and Exception Handling Carl Alphonce CSE116 March 9, 2007.
Exceptions1 Syntax, semantics, and pragmatics. Exceptions2 Syntax, semantics, pragmatics Syntax –How it looks, i.e. how we have to program to satisfy.
Exceptions and Exception Handling Carl Alphonce CSE116.
CSI 3120, Exception handling, page 1 Exception and Event Handling Credits Robert W. Sebesta, Concepts of Programming Languages, 8 th ed., 2007 Dr. Nathalie.
(c) University of Washington11-1 CSC 143 Java More on Exceptions Reading: Ch. 15.
Exceptions and Exception Handling (1) Carl Alphonce CSE116.
Exception Handling. Background The fact that software modules should be robust enough to work under every situation. The exception handling mechanism.
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
Slides prepared by Rose Williams, Binghamton University Chapter 17 Swing I.
Event-Driven Programming Event:  A signal to the program that something has happened.  It can be triggered either by external user actions, such as mouse.
Chapter 11 Exception Handling and Event Handling.
Chapter 11: Handling Exceptions and Events J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Fourth.
Chapter 7 Improving the User Interface
1 Exception and Event Handling (Based on:Concepts of Programming Languages, 8 th edition, by Robert W. Sebesta, 2007)
Programming Paradigms Imperative programming Functional programming Logic programming Event-driven programming Object-oriented programming A programming.
220 FINAL TEST REVIEW SESSION Omar Abdelwahab. INHERITANCE AND POLYMORPHISM Suppose you have a class FunClass with public methods show, tell, and smile.
1 Event Driven Programming wirh Graphical User Interfaces (GUIs) A Crash Course © Rick Mercer.
CSC 520 – Advanced Object Oriented Programming, Fall, 2010 Thursday, September 2, Week 4 Design by Contract, Java Exceptions, Eventing, Finding the Classes,
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. C H A P T E R T E N Event-Driven Programming.
Exceptions1 Syntax, semantics, and pragmatics. Exception create If (some error){ throw new SomeException(”some message”); } Exceptions2.
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,
Exceptions Syntax, semantics, and pragmatics Exceptions1.
C H A P T E R T E N Event-Driven Programming Programming Languages – Principles and Paradigms by Allen Tucker, Robert Noonan.
Java Programming: Guided Learning with Early Objects
CSC 243 – Java Programming, Spring, 2014 March 2014 Week 6ish, Exceptions.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 14 Event-Driven Programming.
Advanced Object- Oriented Programming Programming Right from the Start with Visual Basic.NET 1/e 14.
Chapter 8 - Additional Inheritance Concepts and Techniques1 Chapter 8 Additional Inheritance Concepts and Techniques.
Chapter 12 Handling Exceptions and Events. Chapter Objectives Learn what an exception is Become aware of the hierarchy of exception classes Learn about.
Introduction to Java Beans CIS 421 Web-based Java Programming.
Object Oriented Programming.  Interface  Event Handling.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 27 JavaBeans and.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 11 Handling Exceptions and Events.
1 An Exception is… An unusual, often unpredictable event, detectable by software or hardware, that requires special processing An exception handler is.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 32 JavaBeans and Bean.
5 Event Handling Interactive Programming Suggested Reading Interaction: Events and Event Handling, Supplemental Text for CPSC 203 Distributed this term.
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,
1 Event Handling – Lecture 4 Prepared by: Ahmad Ramin Rahimee Assistant Professor ICTI.
Lecture10 Exception Handling Jaeki Song. Introduction Categories of errors –Compilation error The rules of language have not been followed –Runtime error.
MIT AITI 2004 Swing Event Model Lecture 17. The Java Event Model In the last lecture, we learned how to construct a GUI to present information to the.
5-1 GUIs and Events Rick Mercer. 5-2 Event-Driven Programming with Graphical user Interfaces  Most applications have graphical user interfaces to respond.
12-Jun-16 Event loops. 2 Programming in prehistoric times Earliest programs were all “batch” processing There was no interaction with the user Input Output.
Event Driven (Asynchronous) Programming. Event handling in Unity Subclass a class that contains event handling methods, and then override those methods.
Exception testing Aistis Karkauskas, IFM-2/2. Introduction  Exceptions – anomalous or exceptional events requiring special processing – often changing.
1 Event Driven Programming with Graphical User Interfaces (GUIs) A Crash Course © Rick Mercer.
Exceptions in the Java programming language J. W. Rider.
Chapter 32 JavaBeans and Bean Events
Written by: Dr. JJ Shepherd
Chapter 36 JavaBeans and Bean Events
Event Loops and GUI Intro2CS – weeks
Java Programming: From Problem Analysis to Program Design,
Miscellaneous Topics #6: Polygons GUI Components and Event Handlers
Chapter 15 Event-Driven Programming and Animations
Designing with Java Exception Handling
Chapter 12 Exception Handling and Text IO
Event loops 17-Jan-19.
Graphical User Interfaces in Java Event-driven programming
Programming in C# Lesson 5. Exceptions..
SE-1021 Software Development 2
Designing with Java Exception Handling
Tonga Institute of Higher Education
Exception and Event Handling
Java Programming: From Problem Analysis to Program Design, 4e
CSC 243 – Java Programming, Fall, 2008
System Models Bina Ramamurthy 9/7/2019 B.Ramamurthy.
Presentation transcript:

CSC 243 – Java Programming, Spring, 2009 Week 9 Java’s Event Infrastructure

A Chained Exception A chained Exceptions tacks a detail message onto an underlying cause Exception. – } catch (GameException queryx) { – throw new GameToMidiException ( – “Error querying Scrabble game”, queryx); Used to prepend a context-specific message to an Exception thrown from a called method. Your assignment 2 must throw a chained GameToMidiException for any GameException or exception from the javax.sound.midi library that you catch.

Custom Exceptions A custom Exception inherits, directly or indirectly, from java.lang.Exception. – public class GameToMidiException extends Exception { – public GameToMidiException(String text) { – super(text); – } – public GameToMidiException(String text, Throwable cause) { // Constructor for the chained exception. – super(text, cause); – }

Event-driven Programming Event-driven program is not driven by a sequence of imperative program statements. Instead, a program constructs a set of event handlers that can respond to external events. User interface actions (mouse click, key click, timer, …) State change in an event-driven simulation The program then connects the event sources to the its events handlers, waits for events. An event source later sends an event object.

Java Event Mechanisms Interface java.util.EventListener tags an Object that implements that interface as an Object that can handle an event. Most of the library EventListeners are handlers for GUI events. Class java.util.EventObject is a helper base class that provides some storage for an event. Many of these are GUI oriented as well. Event sources do not have a special interface.