Download presentation
Presentation is loading. Please wait.
Published byGodwin Bruce Modified over 9 years ago
1
CSC 243 – Java Programming, Spring, 2009 Week 9 Java’s Event Infrastructure
2
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.
3
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); – }
4
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.
5
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.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.