Implementing the Graphics3DProperties class

This class displays a list of the properties of the JSR-184 implementation. This is provided as an aid for developers, since in most cases users won't need to know such details.

  1. Create the Graphics3DProperties class file.

  2. Import the required classes.

    import java.util.Enumeration;
    import java.util.Hashtable;
    import javax.microedition.lcdui.*;
    import javax.microedition.m3g.*;
    
  3. Write the below code to create the Graphics3DProperties class, set it to extend List and to implement CommandListener. The getProperties method retrieves implementation specific properties.

    For more information, see getProperties in the M3G API specification.

    class Graphics3DProperties
      extends List
      implements CommandListener
    {
      private final Maze3DMIDlet midlet;
      Graphics3DProperties(Graphics3D g3d, Maze3DMIDlet midlet)
      {
        super("Graphics 3D Properties", List.IMPLICIT);
        this.midlet = midlet;
        Hashtable props = g3d.getProperties();
        Enumeration propKeys = props.keys();
        while (propKeys.hasMoreElements())
        {
          Object key = propKeys.nextElement();
          append(key.toString() + ": " + props.get(key).toString(), null);
        }
        // some entries are too long
        setFitPolicy(List.TEXT_WRAP_ON);
        addCommand(new Command("Back", Command.BACK, 1));
        setCommandListener(this);
      }
    
  4. Create a method that indicates if a command event has occurred.

      public void commandAction(Command command, Displayable displayable)
      {
        midlet.showMenu();
      }
    }