www.pudn.com > StockManager.rar > StockManager.java


//StockManager.java 
 
import javax.microedition.midlet.*; 
import javax.microedition.lcdui.*; 
import java.io.IOException; 
import java.util.*; 
 
public class StockManager extends MIDlet implements Controller 
{ 
	private RMSStockStore _rmsgs = null; 
	private Display _display = null; 
	private Stack _screenStack = null; 
 
    public StockManager() 
    { 
		_rmsgs = new RMSStockStore(); 
		_screenStack = new Stack(); 
 
		nextScreen( new WelcomeScreen( (Controller) this) ); 
	} 
 
    public void startApp() 
    { 
    } 
 
    /** 
     * Pause is a no-op since there are no background activities or 
     * record stores that need to be closed. 
     */ 
    public void pauseApp() {} 
 
    /** 
     * Destroy must cleanup everything not handled by the garbage collector. 
     * In this case there is nothing to cleanup. 
     */ 
    public void destroyApp(boolean unconditional) {} 
 
	private Display getDisplay() 
	{ 
		if ( _display == null) 
		{ 
			_display = Display.getDisplay(this); 
		} 
 
		return _display; 
	} 
 
	// for interface controller 
	public StockDatabase getStockDatabase() 
	{ 
		return (StockDatabase) _rmsgs; 
	} 
 
	public Displayable currentScreen() 
	{ 
		return getDisplay().getCurrent(); 
	} 
 
	public void nextScreen(Displayable display) 
	{ 
		Displayable currentScreen = getDisplay().getCurrent(); 
 
		if ( currentScreen != null) 
		{ 
			_screenStack.push( currentScreen ); 
		} 
 
		getDisplay().setCurrent( display); 
	} 
 
	public void lastScreen() 
	{ 
		Displayable display = null; 
 
		if ( !_screenStack.empty() ) 
		{ 
			display = (Displayable) _screenStack.pop(); 
		} 
		else 
		{ 
			display = new WelcomeScreen( (Controller) this ); 
		} 
 
		getDisplay().setCurrent( display); 
	} 
 
	private void printStack(String message, Stack stack) 
	{ 
		Enumeration elements = stack.elements(); 
 
		System.out.println(message); 
		String subMessage = message.substring(0,2); 
 
		while ( elements.hasMoreElements() ) 
		{ 
			System.out.println("\t"+ subMessage +":"+ elements.nextElement().toString() ); 
		} 
	} 
}