Implement dynamic layer
arcgissamples\display\AddDynamicLayerCommand.java
/* Copyright 2012 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.carto.Map;
import com.esri.arcgis.controls.BaseCommand;
import com.esri.arcgis.controls.HookHelper;

public class AddDynamicLayerCommand extends BaseCommand{
  private static final long serialVersionUID = 1L;
  private HookHelper hookHelper=null;
  private IDynamicMap dynamicMap=null;
  private Map map=null;
    
  public AddDynamicLayerCommand(){
    this.category = "Add Dynamic Layer";
    this.caption = "Add Dynamic Layer";
    this.message ="Add Dynamic Layer";
    this.toolTip ="Add Dynamic Layer";
    this.name ="MyDynamicDisplayApp_AddDynamicLayerCmd";    

  }
  
  public void onCreate(Object hook) {
    if (hook == null)
          return;

        try {
      if (hookHelper == null)
          hookHelper = new HookHelper();
           hookHelper.setHookByRef(hook);
          
    } catch (Exception e) {
      System.out.println("Exception in AddDynamicLayerCommand#onCreate");
      e.printStackTrace();
    }
    
  }
  
  /*
   * @see com.esri.arcgis.controls.BaseCommand#isEnabled()
   * The command will be enabled only if the map is in dynamic mode
   */
  @Override
  public boolean isEnabled() {
    try {
      dynamicMap=(IDynamicMap)hookHelper.getFocusMap();
      if (dynamicMap==null)
        return false;
      else{
        return dynamicMap.isDynamicMapEnabled();
      }
    } catch (Exception e) {
      System.out.println("Exception:AddDynamicLayerCmd#isEnabled");
    e.printStackTrace();
    }
    return false;
  }

  public void onClick(){
     
    try {
      map=(Map)hookHelper.getFocusMap();
      MyDynamicLayer layer=new MyDynamicLayer();  
      map.addLayer(layer);
    } catch (Exception e) {
      System.out.println("Exception:AddDynamicLayerCmd#onClick");
      e.printStackTrace();
    }
  }
}