FileDocCategorySizeDatePackage
Hanoi.javaAPI DocJ2ME MIDP 2.02616Thu Nov 07 12:02:20 GMT 2002example.hanoi

Hanoi

public class Hanoi extends javax.microedition.midlet.MIDlet implements javax.microedition.lcdui.CommandListener, Runnable

Fields Summary
private Thread
m_Hanoi
private HanoiCanvas
m_Canvas
private javax.microedition.lcdui.Display
m_Display
private javax.microedition.lcdui.Command
solveCommand
private javax.microedition.lcdui.Command
stopCommand
private javax.microedition.lcdui.Command
resetCommand
private javax.microedition.lcdui.Command
exitCommand
Constructors Summary
public Hanoi()

	super();

	// Set up the user interface
	m_Display = Display.getDisplay(this);
	m_Canvas  = new HanoiCanvas(this);

	m_Canvas.setCommandListener(this);
	m_Canvas.addCommand(solveCommand);
	m_Canvas.addCommand(exitCommand);
    
Methods Summary
public voidcommandAction(javax.microedition.lcdui.Command c, javax.microedition.lcdui.Displayable d)

	if (c == exitCommand) {
	    destroyApp(false);
	    notifyDestroyed();
	} else if (c == solveCommand) {
	    if (!m_Canvas.isSolving()) {
		m_Canvas.solve();
	    }
	    m_Canvas.removeCommand(solveCommand);
	    m_Canvas.addCommand(stopCommand);
	} else if (c == stopCommand) {
            m_Canvas.stop();
	    m_Canvas.removeCommand(stopCommand);
	    m_Canvas.addCommand(resetCommand);
	} else if (c == resetCommand) {
	    m_Canvas.resetTowers();
	    m_Canvas.removeCommand(resetCommand);
	    m_Canvas.addCommand(solveCommand);
	}
    
public voiddestroyApp(boolean force)

	m_Canvas.exit();
	m_Hanoi = null;
	m_Display.setCurrent(null);
    
public voidpauseApp()

	m_Canvas.exit();
	m_Hanoi = null;
    
public voidrun()

        do {
	    synchronized(m_Canvas) {
		try {
		    m_Canvas.wait();
		} catch (InterruptedException ie) {
		    continue;               // Go back through while(true) loop
		}

		while (m_Canvas.isSolving()) {
		    m_Canvas.updateInfo();
		}
		if (!m_Canvas.isSolving()) {
		    m_Canvas.removeCommand(stopCommand);
		    m_Canvas.addCommand(resetCommand);
		}
	    }
        }
        while(!m_Canvas.isExiting());
	m_Canvas = null;
    
public voidstartApp()

	m_Display.setCurrent(m_Canvas);
        if(m_Hanoi == null)  {
            m_Hanoi = new Thread(this);
            m_Hanoi.start();
        }