 2001 Prentice Hall, Inc. All rights reserved. 1 Appendix D – Elevator Events and Listener Interfaces Outline D.1 Introduction D.2 Events D.3Listeners.

Slides:



Advertisements
Similar presentations
1 Event Listeners Some Events and Their Associated Event Listeners Act that Results in the EventListener Type User clicks a button, presses Enter while.
Advertisements

 2002 Prentice Hall. All rights reserved. Chapter 9: Servlets Outline 9.1 Introduction 9.2 Servlet Overview and Architecture Interface Servlet and.
 2003 Prentice Hall, Inc. All rights reserved. Chapter 15 – Exception Handling Outline 15.1 Introduction 15.2 Exception-Handling Overview 15.3 Exception-Handling.
 2002 Prentice Hall, Inc. All rights reserved. Chapter 14 – Exception Handling Outline 14.1 Introduction 14.2 When Exception Handling Should Be Used 14.3.
 2003 Prentice Hall, Inc. All rights reserved. 1 Appendix F – Elevator View Outline F.1Introduction F.2Class Objects F.3Class Constants F.4Class Constructor.
Dale Roberts GUI Programming using Java - Mouse Events Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 27 - Java Object-Oriented Programming Outline.
Inheritance. In this chapter, we will cover: The concept of inheritance Extending classes Overriding superclass methods Working with superclasses that.
Object-Oriented Programming with Java The Java Event Model Lecture 5.
Java Keywords CSE 115 Spring Purpose This set of slides contains a running list of the keywords that we have talked about so far this semester and.
1 Evan Korth New York University Inheritance and Polymorphism Professor Evan Korth New York University.
1 Evan Korth New York University Inheritance and Polymorphism Professor Evan Korth New York University.
UML Class Diagram: class Rectangle
Inheritance and Subclasses in Java CS 21a: Introduction to Computing I Department of Information Systems and Computer Science Ateneo de Manila University.
 2003 Prentice Hall, Inc. All rights reserved. Outline 12.1 Introduction 12.2 Graphics Contexts and Graphics Objects 12.3 Color Control 12.4 Font Control.
Inheritance using Java
1 Object Oriented Analysis and Design. 2 Object-Oriented Analysis  Statement of what our client wants Object-Oriented Design  How to provide it using.
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to Classes and Objects Outline Introduction Classes, Objects, Member Functions and Data.
220 FINAL TEST REVIEW SESSION Omar Abdelwahab. INHERITANCE AND POLYMORPHISM Suppose you have a class FunClass with public methods show, tell, and smile.
Chapter 11 Inheritance and Composition. Chapter Objectives Learn about inheritance Learn about subclasses and superclasses Explore how to override the.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 20.1 Test-Driving the Screen Saver Application.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 2 1 Java Inheritance.
 2000 Deitel & Associates, Inc. All rights reserved. Optional Case Study - Chapter 5 Outline 5.1 Introduction 5.2 Collaborations 5.3 Creating Collaborations.
 2000 Deitel & Associates, Inc. All rights reserved. Optional Case Study - Chapter 7 Outline 7.1 Introduction 7.2 Overview of Simulation Implementation.
 2000 Deitel & Associates, Inc. All rights reserved. Optional Case Study - Chapter 4 Outline 4.1 Introduction 4.2 Class Operations 4.3 Creating Class.
 2000 Deitel & Associates, Inc. All rights reserved. Optional Case Study - Chapter 3 Outline 3.1 Introduction 3.2 Class Attributes 3.3 Statechart Diagrams.
Dale Roberts GUI Programming using Java - Event Handling Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer.
 2002 Prentice Hall, Inc. All rights reserved Introduction Graphical User Interface (GUI) –Gives program distinctive “look” and “feel” –Provides.
 2002 Prentice Hall, Inc. All rights reserved. Appendix H – Elevator Model Outline H.1 Introduction H.2 Class ElevatorModel H.3Classes Location and Floor.
1 OOP : main concepts Polymorphism. 2 OOP : main concepts  The main concepts:  In a superclass –public members Accessible anywhere program has a reference.
Dale Roberts Object Oriented Programming using Java - OOD to OOP: ATM Case Study Dale Roberts, Lecturer Computer Science, IUPUI
Chapter 12 1 TOPIC 13B l Buttons and Action Listeners Window Interfaces Using Swing Objects.
Alice in Action with Java Chapter 14 Events and GUIs.
 2002 Prentice Hall, Inc. All rights reserved. Appendix I – Elevator View Outline I.1Introduction I.2Class Objects I.3Class Constants I.4Class Constructor.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 21.1 Test-Driving the Painter Application.
 2003 Prentice Hall, Inc. All rights reserved. Appendix E – Elevator Model Outline E.1 Introduction E.2 Class ElevatorSimulation E.3Classes Location and.
Introduction to GUI in 1 Graphical User Interface 2 Nouf Almunyif.
Outline Creating Subclasses Overriding Methods Class Hierarchies Visibility Designing for Inheritance Inheritance and GUIs The Timer Class Copyright ©
Chapter 13 ATM Case Study Part 2: Implementing an Object-Oriented Design Java How to Program, 8/e (C) 2010 Pearson Education, Inc. All rights reserved.
 2006 Doan Van Ban, IOIT. All rights reserved. 1 Case Study: E levator System Simulation Program Goal –Software simulator application –N-floor elevator.
Chapter 8 Inheritance. 2  Review of class relationships  Uses – One class uses the services of another class, either by making objects of that class.
Encapsulation, Inheritance, Composition. Class Methods Can be either void or return Can have parameters or not Must be static Should be public Know how.
Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved. 1 Chapter 15 Event-Driven Programming and.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 27.1 Test-Driving the Drawing Shapes Application.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 4 – Completing the Inventory Application.
Inheritance and Subclasses CS 21a. 6/28/2004 Copyright 2004, by the authors of these slides, and Ateneo de Manila University. All rights reserved L16:
Elevator Example.
A cannon game ?. Simple version angle from command line, one shot only Coordinate system is “upside-down”: Use dy(int) method to transform y coordinate:
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 32 JavaBeans and Bean.
Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved. 1 Chapter 15 Event-Driven Programming and.
1 Entity Callbacks and Listeners When you execute EntityManager methods like persist( ), merge( ), remove( ), and find( ), or when you execute EJB QL queries,
Class Diagrams Revisited. Parameterized Classes Parameterized Classes - are used to represent relationships between templates.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Outline Creating Subclasses Overriding Methods Class Hierarchies Inheritance.
 2002 Prentice Hall. All rights reserved. Page 1 Inheritance: Object-Oriented Programming Outline 9.1 Introduction 9.2 Superclasses and Subclasses 9.3.
 2000 Deitel & Associates, Inc. All rights reserved. Optional Case Study - Chapter 6 Outline 6.1 Introduction 6.2 Implementation: Visibility 6.3 Implementation:
SUBCLASSES - JAVA. The Purpose of Subclasses Class Farm String getOwner() void setOwner(String s) int getSize() void setSize(int s) Class DairyFarm String.
Java Programming: Guided Learning with Early Objects Chapter 9 Inheritance and Polymorphism.
Java Interfaces CS 21a: Introduction to Computing I Department of Information Systems and Computer Science Ateneo de Manila University (see Chapter 9 of.
Elevator Example. Problem GSU schedules to upgrade all the campus elevators in 6 months. Due to incompatibility with the new hardware, the current software.
GUI Programming using Java - Event Handling
Lecture 15 Basic GUI programming
Optional Case Study - Chapter 4
UML Class Diagram: class Rectangle
Chapter 9 Object-Oriented Programming: Inheritance
Inheritance, Polymorphism, and Interfaces. Oh My
GUI Programming using Java - Mouse Events
Java Programming, Second Edition
Chapter 12 - Graphics and Java 2D
Presentation transcript:

 2001 Prentice Hall, Inc. All rights reserved. 1 Appendix D – Elevator Events and Listener Interfaces Outline D.1 Introduction D.2 Events D.3Listeners D.4Artifacts Revisited

 2001 Prentice Hall, Inc. All rights reserved. 2 D.1 Introduction Event handling –Object register as “listeners” for events The class of that object must implement a “listener” interface

 2001 Prentice Hall, Inc. All rights reserved. 3 D.2 Events Figures D.1-D.7 contain system events –Each event inherits from class ElevatorSimulationEvent

 2001 Prentice Hall, Inc. All rights reserved. Outline ElevatorSimulat ionEvent.java ElevatorSimulat ion-Event superclass for events in the elevator simulation model. Line 8 Line 11 Line 14 1 // ElevatorSimulationEvent.java 2 // Basic event packet in Elevator simulation 3 package com.deitel.jhtp5.elevator.event; 4 5 // Deitel packages 6 import com.deitel.jhtp5.elevator.model.*; 7 8 public class ElevatorSimulationEvent { 9 10 // Location where ElevatorSimulationEvent was generated 11 private Location location; // source Object that generated ElevatorSimulationEvent 14 private Object source; // ElevatorSimulationEvent constructor sets Location 17 public ElevatorSimulationEvent( Object source, Location location ) 18 { 19 setSource( source ); 20 setLocation( location ); 21 } 22 Class ElevatorSimulationEvent is the superclass for all events in elevator simulation case study Location object represents where the event was generated (e.g., Floor or Elevator ) Object source represents the actual Object that generated the event

 2001 Prentice Hall, Inc. All rights reserved. Outline ElevatorSimulat ionEvent.java ElevatorSimulat ion-Event superclass for events in the elevator simulation model. 23 // set ElevatorSimulationEvent Location 24 public void setLocation( Location eventLocation ) 25 { 26 location = eventLocation; 27 } // get ElevatorSimulationEvent Location 30 public Location getLocation() 31 { 32 return location; 33 } // set ElevatorSimulationEvent source 36 private void setSource( Object eventSource ) 37 { 38 source = eventSource; 39 } // get ElevatorSimulationEvent source 42 public Object getSource() 43 { 44 return source; 45 } 46 }

 2001 Prentice Hall, Inc. All rights reserved. Outline BellEvent.java BellEvent ElevatorSimulat ion-Event subclass indicating that the Bell has rung. Lines // BellEvent.java 2 // Indicates that Bell has rung 3 package com.deitel.jhtp5.elevator.event; 4 5 // Deitel packages 6 import com.deitel.jhtp5.elevator.model.*; 7 8 public class BellEvent extends ElevatorSimulationEvent { 9 10 // BellEvent constructor 11 public BellEvent( Object source, Location location ) 12 { 13 super( source, location ); 14 } 15 } BellEvent sent when Bell has rung

 2001 Prentice Hall, Inc. All rights reserved. Outline ButtonEvent.jav a ButtonEvent ElevatorSimulat ion-Event subclass indicating that a Button has changed state. Lines // ButtonEvent.java 2 // Indicates that a Button has changed state 3 package com.deitel.jhtp5.elevator.event; 4 5 // Deitel packages 6 import com.deitel.jhtp5.elevator.model.*; 7 8 public class ButtonEvent extends ElevatorSimulationEvent { 9 10 // ButtonEvent constructor 11 public ButtonEvent( Object source, Location location ) 12 { 13 super( source, location ); 14 } 15 } ButtonEvent sent when Button as been pressed or reset

 2001 Prentice Hall, Inc. All rights reserved. Outline DoorEvent.java DoorEvent ElevatorSimulat ion-Event subclass indicating that a Door has changed state. Lines // DoorEvent.java 2 // Indicates that a Door has changed state 3 package com.deitel.jhtp5.elevator.event; 4 5 // Deitel packages 6 import com.deitel.jhtp5.elevator.model.*; 7 8 public class DoorEvent extends ElevatorSimulationEvent { 9 10 // DoorEvent constructor 11 public DoorEvent( Object source, Location location ) 12 { 13 super( source, location ); 14 } 15 } DoorEvent sent when Door has opened or closed

 2001 Prentice Hall, Inc. All rights reserved. Outline ElevatorMoveEve nt.java ElevatorMove- Event Elevator- ModelEvent subclass indicating on which Floor the Elevator has either arrived or departed. Lines // ElevatorMoveEvent.java 2 // Indicates on which Floor the Elevator arrived or departed 3 package com.deitel.jhtp5.elevator.event; 4 5 // Deitel packages 6 import com.deitel.jhtp5.elevator.model.*; 7 8 public class ElevatorMoveEvent extends ElevatorSimulationEvent { 9 10 // ElevatorMoveEvent constructor 11 public ElevatorMoveEvent( Object source, Location location ) 12 { 13 super( source, location ); 14 } 15 } ElevatorMoveEvent sent when Elevator arrives at or departs from Floor

 2001 Prentice Hall, Inc. All rights reserved. Outline LightEvent.java LightEvent ElevatorModel- Event subclass indicating on which Floor the Light has changed state. Lines // LightEvent.java 2 // Indicates on which Floor the Light has changed state 3 package com.deitel.jhtp5.elevator.event; 4 5 // Deitel packages 6 import com.deitel.jhtp5.elevator.model.*; 7 8 public class LightEvent extends ElevatorSimulationEvent { 9 10 // LightEvent constructor 11 public LightEvent( Object source, Location location ) 12 { 13 super( source, location ); 14 } 15 } LightEvent sent when Light has been turned on or off

 2001 Prentice Hall, Inc. All rights reserved. Outline PersonMoveEvent.java PersonMoveEvent ElevatorModel- Event subclass indicating that a Person has moved. Lines 8-26 Line 11 1 // PersonMoveEvent.java 2 // Indicates that a Person has moved 3 package com.deitel.jhtp5.elevator.event; 4 5 // Deitel packages 6 import com.deitel.jhtp5.elevator.model.*; 7 8 public class PersonMoveEvent extends ElevatorSimulationEvent { 9 10 // identifier of Person sending Event 11 private int ID; // PersonMoveEvent constructor 14 public PersonMoveEvent( Object source, Location location, 15 int identifier ) 16 { 17 super( source, location ); 18 ID = identifier; 19 } // return identifier 22 public int getID() 23 { 24 return( ID ); 25 } 26 } PersonMoveEvent sent when Person performs an action in simulation ID for identifying the Person that sent the event

 2001 Prentice Hall, Inc. All rights reserved. 12 D.3 Listeners Figures D.8-D.14 contain listener interfaces –Interface methods receive as arguments various events

 2001 Prentice Hall, Inc. All rights reserved. Outline BellListener.ja va BellListener method when Bell has rung. Line 8 1 // BellListener.java 2 // Method invoked when Bell has rung 3 package com.deitel.jhtp5.elevator.event; 4 5 public interface BellListener { 6 7 // invoked when Bell has rungs 8 public void bellRang( BellEvent bellEvent ); 9 } Method invoked when Bell has rung

 2001 Prentice Hall, Inc. All rights reserved. Outline ButtonListener. java ButtonListener methods when Button has been either pressed or reset. Lines // ButtonListener.java 2 // Methods invoked when Button has been either pressed or reset 3 package com.deitel.jhtp5.elevator.event; 4 5 public interface ButtonListener { 6 7 // invoked when Button has been pressed 8 public void buttonPressed( ButtonEvent buttonEvent ); 9 10 // invoked when Button has been reset 11 public void buttonReset( ButtonEvent buttonEvent ); 12 } Methods invoked when Button has been pressed or reset

 2001 Prentice Hall, Inc. All rights reserved. Outline DoorListener.ja va DoorListener methods when Door has either opened or closed. Lines // DoorListener.java 2 // Methods invoked when Door has either opened or closed 3 package com.deitel.jhtp5.elevator.event; 4 5 public interface DoorListener { 6 7 // invoked when Door has opened 8 public void doorOpened( DoorEvent doorEvent ); 9 10 // invoked when Door has closed 11 public void doorClosed( DoorEvent doorEvent ); 12 } Methods invoked when Door has been opened or closed

 2001 Prentice Hall, Inc. All rights reserved. Outline ElevatorMoveLis tener.java ElevatorMove- Listener methods when Elevator has either departed from or arrived on a Floor. Lines // ElevatorMoveListener.java 2 // Methods invoked when Elevator has either departed or arrived 3 package com.deitel.jhtp5.elevator.event; 4 5 public interface ElevatorMoveListener { 6 7 // invoked when Elevator has departed 8 public void elevatorDeparted( ElevatorMoveEvent moveEvent ); 9 10 // invoked when Elevator has arrived 11 public void elevatorArrived( ElevatorMoveEvent moveEvent ); 12 } Methods invoked when Elevator has arrived at or departed from a Floor

 2001 Prentice Hall, Inc. All rights reserved. Outline LightListener.j ava LightListener method for when Light has either turned on or off. Lines // LightListener.java 2 // Methods invoked when Light has either turned on or off 3 package com.deitel.jhtp5.elevator.event; 4 5 public interface LightListener { 6 7 // invoked when Light has turned on 8 public void lightTurnedOn( LightEvent lightEvent ); 9 10 // invoked when Light has turned off 11 public void lightTurnedOff( LightEvent lightEvent ); 12 } Methods invoked when Light has been turned on or off

 2001 Prentice Hall, Inc. All rights reserved. Outline PersonMoveListe ner.java PersonMove- Listener methods when Person has moved. Lines // PersonMoveListener.java 2 // Methods invoked when Person moved 3 package com.deitel.jhtp5.elevator.event; 4 5 public interface PersonMoveListener { 6 7 // invoked when Person has been instantiated in model 8 public void personCreated( PersonMoveEvent moveEvent ); 9 10 // invoked when Person arrived at elevator 11 public void personArrived( PersonMoveEvent moveEvent ); // invoked when Person departed from elevator 14 public void personDeparted( PersonMoveEvent moveEvent ); // invoked when Person pressed Button 17 public void personPressedButton( 18 PersonMoveEvent moveEvent ); // invoked when Person entered Elevator 21 public void personEntered( PersonMoveEvent moveEvent ); // invoked when Person exited simulation 24 public void personExited( PersonMoveEvent moveEvent ); 25 } Methods invoked when Person performs an action

 2001 Prentice Hall, Inc. All rights reserved. Outline ElevatorSimulat ionListener.jav a ElevatorSimulat ion-Listener allows the model to send all events to the view. Lines // ElevatorSimulationListener.java 2 // Listener for ElevatorView from ElevatorModel 3 package com.deitel.jhtp5.elevator.event; 4 5 // ElevatorSimulationListener inherits all Listener interfaces 6 public interface ElevatorSimulationListener extends BellListener, 7 ButtonListener, DoorListener, ElevatorMoveListener, 8 LightListener, PersonMoveListener { 9 } Convenience interface that extends all listener interfaces

 2001 Prentice Hall, Inc. All rights reserved. 20 D.4 Artifacts Revisited Artifacts diagram for events –Artifacts in package event Each artifact maps to a class in Figure D.1-D.14 –ElevatorView.java aggregates package event In Java, class ElevatorView imports package event –Package model aggregates package event In Java, each class in model imports package event

 2001 Prentice Hall, Inc. All rights reserved. 21 Fig. D.15 Artifacts for package event. BellEvent.java file event BellListener.java > ButtonEvent.java > ButtonListener.java > DoorEvent.java > DoorListener.java > ElevatorMoveEvent.java > ElevatorMoveListener.java > ElevatorSimulationEvent.java > ElevatorSimulationListener.java > LightEvent.java > LightListener.java > PersonMoveEvent.java > PersonMoveListener.java > view ElevatorView.java > 1 model > BellEvent.java