package drivers;

import java.util.*;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

import java3d.*;

/**
 * A simple example of immediate mode rendering using the
 * Mobile 3D Graphics API for J2ME
 *
 * @author  Prof. David Bernstein, James Madison University
 * @version 1.0
 */
public class CubeDriver extends MIDlet implements CommandListener
{
    Animator       animator;
    CubeCanvas     canvas;
    Timer          timer;

    /**
     * Default Constructor
     */
    public CubeDriver() 
    {
        // Construct the Displayable
        canvas = new CubeCanvas();
        canvas.setCommandListener(this);
        
        // Construct the Timer
        timer = new Timer();
        
        // Construct the Timer "callback"
        animator = new Animator(canvas);
    }

    
    /**
     * Handle commandAction events
     * (required by CommandListener)
     *
     * @param c   The Command
     * @param d   The Displayable that generated the event
     */
    public void commandAction(Command c, Displayable d) 
    {
        if (c.getCommandType() == Command.EXIT) 
        {
            destroyApp(true);
        }
    }    

    /**
     * Destroy this MIDlet
     */
    public void destroyApp(boolean unconditional) 
    {
    }
    
    
    /**
     * Entry point
     */
    public void startApp() 
    {
        Display.getDisplay(this).setCurrent(canvas);
        timer.schedule(animator, 0, 40 );
    }

    /**
     * Pause this MIDlet
     */
    public void pauseApp() 
    {
    }

    
}