Implement dynamic layer
arcgissamples\display\ToggleDynamicDisplayCommand.java
/* Copyright 2010 ESRI
* 
* All rights reserved under the copyright laws of the United States
* and applicable international laws, treaties, and conventions.
* 
* You may freely redistribute and use this sample code, with or
* without modification, provided you include the original copyright
* notice and use restrictions.
* 
* See the use restrictions.
* 
*/
package arcgissamples.display;

import com.esri.arcgis.carto.IDynamicMap;
import com.esri.arcgis.controls.BaseCommand;
import com.esri.arcgis.controls.HookHelper;


public class ToggleDynamicDisplayCommand extends BaseCommand {

  private static final long serialVersionUID = 1L;
  private HookHelper hookHelper = null;
  private IDynamicMap dynamicMap = null;

  public ToggleDynamicDisplayCommand() {
    //Set the properties of the command
    this.category = "Toggle dynamic display";
    this.caption = "Toggle dynamic mode";
    this.message = "Toggle dynamic mode on and off";
    this.toolTip = "Toggle dynamic mode";
    this.name = "MyDynamicDisplayApp_ToggleDynamicDisplayCmd";
    this.enabled=true;

  }

  public void onCreate(Object hook) {
    if (hook == null)
      return;
    try {
      hookHelper = new HookHelper();
      hookHelper.setHookByRef(hook);
      
    } catch (Exception e) {
      System.out.println("Exception:ToggleDynamicDisplay#onCreate");
      e.printStackTrace();
    }

  }

  /*
   * @see com.esri.arcgis.controls.BaseCommand#onClick()
   * This method toggles the dynamic mode for the map
   */
  public void onClick() {
    try {
      dynamicMap = (IDynamicMap) hookHelper.getFocusMap();
      if (dynamicMap==null){
        System.out.println("The current display does not support dynamic mode");
      }
      //switch in and out of dynamic mode
      if (dynamicMap.isDynamicMapEnabled()) {
        dynamicMap.setDynamicMapEnabled(false);
      } else {
        dynamicMap.setDynamicMapEnabled(true);
      }
    } catch (Exception e) {
      System.out.println("Exception:ToggleDynamicDisplay#onClick");
      e.printStackTrace();
    }

  }
  /*
   * @see com.esri.arcgis.controls.BaseCommand#isChecked()
   * This method displays the command as "pushed in" 
   * when the map is in dynamic display mode
   */
  public boolean isChecked() {
    if (dynamicMap == null)
      return false;
    try {
      return dynamicMap.isDynamicMapEnabled();
    } catch (Exception e) {
      System.out.println("Exception:ToggleDynamicDisplay#isChecked");
      e.printStackTrace();
    }
    return false;
  }

}