Web hosting compare - 708 Graphical User Interface Components: Part 1 Chapter

708 Graphical User Interface Components: Part 1 Chapter 12 98 99 // other methods implementing PersonMoveListener 100 public void personCreated( 101 PersonMoveEvent event ) {} 102 103 public void personArrived( 104 PersonMoveEvent event ) {} 105 106 public void personExited( 107 PersonMoveEvent event ) {} 108 109 public void personDeparted( 110 PersonMoveEvent event ) {} 111 112 public void personPressedButton( 113 PersonMoveEvent event ) {} 114 115 } // end anonymous inner class 116 ); 117 } // end ElevatorController constructor 118 } Fig. 12.30 Class ElevatorControllerprocesses user input (part 3 of 3). Lines 53 and 71 of methods actionPerformeddisable the respective JButtons to prevent the user from creating more than one Personper Floor. Lines 78 116 of class ElevatorController declare an anonymous PersonMoveListener that registers with the ElevatorModel to reenable the JButtons. Method personEntered (lines 82 97) of the PersonMoveListener reenables the JButton associated with the Floor that the Elevator services after the Personhas entered the Elevator, the user may place another Personon the Floor. We mentioned in Section 9.23 that classes Elevatorand Floorinherited attribute capacity from superclass Location in Appendix H, we were going to use this attribute to prevent more than one Person from occupying a Location. However, the PersonMoveListener s method personEntered in class ElevatorControllerprevents the user from creating more than one Personper Floor. Therefore, we have negated the need for attribute capacityin class Location. Figure 12.32 is the modified class diagram of Fig. 9.18 removing this attribute. 1 // ElevatorConstants.java 2 // Constants used between ElevatorModel and ElevatorView 3 package com.deitel.jhtp4.elevator; 4 5 public interface ElevatorConstants { 6 7 public static final String FIRST_FLOOR_NAME = “firstFloor”; 8 public static final String SECOND_FLOOR_NAME = “secondFloor”; 9 public static final String ELEVATOR_NAME = “elevator”; 10 } Fig. 12.31 Interface ElevatorConstantsprovides Locationname constants. Copyright 1992 2002 by Deitel & Associates, Inc. All Rights Reserved. 7/7/01

Leave a Reply