lecture24-applets

lecture24-applets - Lecture 24: Event Programming; Applets...

Info iconThis preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon
Lecture 24: Event Programming; Applets CS 170, Section 000 December 2009 1 December 2009 12/1/2009 CS170, Section 000, Fall 2009 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Lecture Plan ± Events (essentials, Ch. 11, 15) pplets h. 17) ¾ Applets (Ch. 17) ± Life of an applet raphical User Interfaces (GUI) in Java ± Graphical User Interfaces (GUI) in Java ± Programming GUI Events ± Homework 8 CS170, Section 000, Fall 2009 2
Background image of page 2
Review: What is an interface? Interface is to specify behavior for objects py j For example, we can specify that the objects are comparable, edible, cloneable using appropriate interfaces such as Comparable, dible nd loneable Edible, and Cloneable You can create an instance from a class that plements an interface implements an interface You can use an interface as a data type for a variable, as the result of casting, and so on. 3
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Example1: The Cloneable Interfaces A class that implements the Cloneable interface declares that its objects can be copied using the clone() method defined in the Object class. package java.lang; public interface Cloneable { } 4
Background image of page 4
Implementing Cloneable Interface Declare a custom class that implements the Cloneable interface public class House implements Cloneable { p p private int id; private double area; private java.util.Date whenBuilt; public Object clone() { //overrides Object’s clone() method try { eturn uper clone ); /Object’s clone mplem return super.clone(); //Object s clone implem. } catch (CloneNotSupportedException ex) { return null; } } 5 House.java
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Shallow vs. Deep Copy House house1 = new House( 1, 1750.50, new Date(“1/1/2009”) ); ouse house2 = (House house1 clone(); House house2 = (House) house1.clone(); house1. area = 3000; house1.whenBuilt = new Date(“1/1/1900”); house2.area = ? house2.whenBuilt=? house1: House id = 1 1 Memory area = 1750.50 whenBuilt whenBuilt: Date date object contents house2 = house1.clon ) 1750.50 reference ouse ouse .c o e() house1: House id = 1 Memory 6 area = 1750.50 whenBuilt 1 1750.50 reference
Background image of page 6
Event Programming ent programming Event programming the flow of the program is determined by user actions (mouse clicks, key presses) or messages om other programs from other programs. Components ent sources: user interface components or other Event sources: user interface components or other sources that generate the events Events: user actions or other events Event listener: reactions on events
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Events An event can be defined as a type of signal to the program that something has happened. The event is generated by external user actions such as mouse movements, mouse icks, and keystrokes, or by the operating clicks, and keystrokes, or by the operating system or program activities, such as a mer 8 timer.
Background image of page 8
The Role of Event Listeners • Role of an event listener is similar to Fred and George easley’s “ xtendable ars” om arry otter Weasley s Extendable Ears from Harry Potter • Suppose that you wanted to use these magical listeners to detect events like mouse clicks.
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 10
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 49

lecture24-applets - Lecture 24: Event Programming; Applets...

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online