Source of Rotator.java


  1: // Fig. 27.14: Rotator.java
  2: // A JavaBean that rotates advertisements.
  3: package com.deitel.jhtp6.jsp.beans;
  4: 
  5: public class Rotator 
  6: {
  7:    private String images[] = { "images/advjHTP1.jpg",
  8:       "images/cppHTP4.jpg", "images/iw3HTP2.jpg",
  9:       "images/jwsFEP1.jpg", "images/vbnetHTP2.jpg" };
 10:       
 11:    private String links[] = {
 12:       "http://www.amazon.com/exec/obidos/ASIN/0130895601/" + 
 13:          "deitelassociatin",
 14:       "http://www.amazon.com/exec/obidos/ASIN/0130384747/" + 
 15:          "deitelassociatin",
 16:       "http://www.amazon.com/exec/obidos/ASIN/0130308978/" + 
 17:          "deitelassociatin",
 18:       "http://www.amazon.com/exec/obidos/ASIN/0130461342/" + 
 19:          "deitelassociatin",
 20:       "http://www.amazon.com/exec/obidos/ASIN/0130293636/" + 
 21:          "deitelassociatin" };
 22:          
 23:    private int selectedIndex = 0;
 24: 
 25:    // returns image file name for current ad  
 26:    public String getImage()
 27:    {
 28:       return images[ selectedIndex ];
 29:    } // end method getImage
 30: 
 31:    // returns the URL for ad's corresponding Web site
 32:    public String getLink()
 33:    {
 34:       return links[ selectedIndex ];
 35:    } // end method getLink
 36: 
 37:    // update selectedIndex so next calls to getImage and 
 38:    // getLink return a different advertisement
 39:    public void nextAd()
 40:    {
 41:       selectedIndex = ( selectedIndex + 1 ) % images.length;
 42:    } // end method nextAd
 43: } // end class Rotator
 44: 
 45: 
 46:  /**************************************************************************
 47:  * (C) Copyright 1992-2005 by Deitel & Associates, Inc. and               *
 48:  * Pearson Education, Inc. All Rights Reserved.                           *
 49:  *                                                                        *
 50:  * DISCLAIMER: The authors and publisher of this book have used their     *
 51:  * best efforts in preparing the book. These efforts include the          *
 52:  * development, research, and testing of the theories and programs        *
 53:  * to determine their effectiveness. The authors and publisher make       *
 54:  * no warranty of any kind, expressed or implied, with regard to these    *
 55:  * programs or to the documentation contained in these books. The authors *
 56:  * and publisher shall not be liable in any event for incidental or       *
 57:  * consequential damages in connection with, or arising out of, the       *
 58:  * furnishing, performance, or use of these programs.                     *
 59:  *************************************************************************/