home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Java / SlideShow / Sources (complete) / PlayPauseButton.java < prev    next >
Encoding:
Java Source  |  2000-09-28  |  2.0 KB  |  76 lines  |  [TEXT/CWIE]

  1. public class PlayPauseButton extends RolloverButton
  2. {
  3.     //Declare and define constants
  4.     //Insert "PlayPauseButton Constants"
  5.     public static final String PLAY_UP_IMAGE = "play up";
  6.     public static final String PLAY_DOWN_IMAGE = "play down";
  7.     public static final String PLAY_ROLLOVER_IMAGE = "play rollover";
  8.     public static final String PAUSE_UP_IMAGE = "pause up";
  9.     public static final String PAUSE_DOWN_IMAGE = "pause down";
  10.     public static final String PAUSE_ROLLOVER_IMAGE = "pause rollover";
  11.     
  12.     public static final int PLAY_STATE = 0;
  13.     public static final int PAUSE_STATE = 1;
  14.     
  15.     public void initImages()
  16.     {
  17.         //Initialize images and set the state for the PlayPauseButton
  18.         //Insert "PlayPauseButton initImages"
  19.         addImage("images/play.jpg", PLAY_UP_IMAGE);
  20.         addImage("images/playa.jpg", PLAY_DOWN_IMAGE);
  21.         addImage("images/playb.jpg", PLAY_ROLLOVER_IMAGE);
  22.         addImage("images/pause.jpg", PAUSE_UP_IMAGE);
  23.         addImage("images/pausea.jpg", PAUSE_DOWN_IMAGE);
  24.         addImage("images/pauseb.jpg", PAUSE_ROLLOVER_IMAGE);
  25.  
  26.         setState(PLAY_STATE);
  27.     }
  28.     
  29.     /**
  30.      * Sets the state of the PlayPauseButton.
  31.      * @param the state to use.
  32.      * @see #PLAY_STATE
  33.      * @see #PAUSE_STATE
  34.      */
  35.     public void setState(int state)
  36.     {
  37.         //Handle switching states
  38.         //Insert "PlayPauseButton setState"
  39.         switch (state)
  40.         {
  41.             case PLAY_STATE:
  42.                 upImage = PLAY_UP_IMAGE;
  43.                 downImage = PLAY_DOWN_IMAGE;
  44.                 rolloverImage = PLAY_ROLLOVER_IMAGE;
  45.                 setActionCommand("" + PLAY_STATE);
  46.                 this.state = state;
  47.                 refreshImage();
  48.                 break;
  49.             case PAUSE_STATE:
  50.                 upImage = PAUSE_UP_IMAGE;
  51.                 downImage = PAUSE_DOWN_IMAGE;
  52.                 rolloverImage = PAUSE_ROLLOVER_IMAGE;
  53.                 setActionCommand("" + PAUSE_STATE);
  54.                 this.state = state;
  55.                 refreshImage();
  56.                 break;
  57.         }
  58.     }
  59.     
  60.     /**
  61.      * Gets the state of the PlayPauseButton.
  62.      * @return the state currently in use.
  63.      * @see #PLAY_STATE
  64.      * @see #PAUSE_STATE
  65.      */
  66.     public int getState()
  67.     {
  68.         //Return the current state
  69.         //Insert "PlayPauseButton getState"
  70.         return state;
  71.     }    
  72.  
  73.     //Declare data members
  74.     //Insert "PlayPauseButton data members"
  75.     protected int state;
  76. }