Code sample: Adding a compass field to an application

import net.rim.device.api.lbs.compass.*;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.container.MainScreen;

public class CompassFieldDemo extends UiApplication
{
    public static final void main(String[] args)
	   {
		      new CompassFieldDemo().enterEventDispatcher();
	   }
	
	   public CompassFieldDemo()
	   {
		      pushScreen(new CompassFieldDemoScreen());
	   }
	
	   private class CompassFieldDemoScreen extends MainScreen
	   {
		      CompassGLField _compField;
		
		      public CompassFieldDemoScreen()
		      {
			         setTitle("CompassFieldDemo");
            
            // Create and add the compass field.
			         _compField = new CompassGLField();
			         add(_compField);
		      }
		
		      public boolean onClose()
		      {
            // Close the compass field to release its resources.
			         _compField.close();
            close();
			         return true;
		      }
	   }
}

Was this information helpful? Send us your comments.