?? screenmanager.java
字號:
package com.jmobilecore.ui.core;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;
import java.util.Stack;
/**
* This class provides access to the MIDlet's environment
* and supports navigation among the screens.
*
* @author Greg Gridin
*/
public class ScreenManager {
/**
* A stack of the path to the currently-displayed screen.
*/
protected static Stack screens = new Stack();
/**
* Current midlet
* @see #setMIDlet
*/
protected static MIDlet application = null;
/**
* Reference to Display object that is unique to this MIDlet
* @see #setMIDlet
*/
protected static Display display = null;
/**
* Sets the current MIDlet. If a MIDlet calls this method then environmental
* information which can only be accessed via the MIDlet object, such as the
* {@link javax.microedition.lcdui.Display javax.microedition.lcdui.Display},
* will be accessible to other objects via this class.
*
* @param midlet The midlet
*/
public static void setMIDlet(MIDlet midlet) {
application = midlet;
display = Display.getDisplay(midlet);
}
/**
* Returns the current MIDlet.
*
* @return The current MIDlet if {@link #setMIDlet} was previously
* called, else <code>null</code>.
*/
public static MIDlet getMIDlet() {
return application;
}
/**
* Gets the Display object associated with the midlet. This may allow another
* object, such as an {@link Component Component}, to use
* environment information which is accessible only via a MIDlet object. For
* example, the following code in
{@link #beep beep} causes the handset to emit a beep.
* <pre><code>
* if ( ScreenManager.getDisplay() != null )
* AlertType.WARNING.playSound( ScreenManager.getDisplay() );
* </code></pre>
*
* @return The Display object for the MIDlet, or null if the MIDlet has not
* previously called {@link #setMIDlet setMIDlet}
*/
public static Display getDisplay() {
return display;
}
/**
* Causes the handset to emit a beep if {@link #setMIDlet setMIDlet} has
* been previously called.
*/
public static void beep(AlertType alert) {
if (display != null)
alert.playSound(display);
}
/**
* Display a new screen, and the new screen supports going back to the
* previous screen.
*
* @param newScreen The new screen to display
*/
public static void goForward(Displayable newScreen) {
screens.push(newScreen);
getDisplay().setCurrent(newScreen);
}
/**
* Replaces the currently displayed screen to the new displayed screen.
*
* @param newScreen The new replacement screen to display
*/
public static void replaceScreen(Displayable newScreen) {
if (!screens.empty()) screens.pop();
screens.push(newScreen);
getDisplay().setCurrent(newScreen);
}
/**
* Makes the previously displayed screen the currently displayed screen.
*/
public static void goBack() {
if (!screens.empty()) {
screens.pop();
if (!screens.empty()) {
getDisplay().setCurrent((Displayable) screens.peek());
}
}
}
/**
* Gets the current screen (the screen at the top of the stack).
*
* @return the current screen as <code>Displayable</code> object
*/
public static Displayable getCurrentScreen() {
Displayable current = null;
if (!screens.empty()) {
current = (Displayable) screens.peek();
}
return current;
}
/**
* Goes back to the first (home) screen.
*/
public static void goHome() {
Displayable home = null;
while (!screens.empty()) {
home = (Displayable) screens.pop();
}
getDisplay().setCurrent(home);
screens.push(home);
}
/**
* Shows alert message and backs to current scrren
*
* @param title The title for alert screen
* @param text The alert message
* @param delay How long the alert will be displayed, If delay is <code>Alert.FOREVER</code> then
* alert will be visible until user dismisses it
* @param type The alert type
* @see javax.microedition.lcdui.Alert
*/
public static void showAlert(String title, String text, int delay, AlertType type) {
showAlert(title, text, delay, type, getCurrentScreen());
}
/**
* Shows alert message and moves to specified scrren
*
* @param title The title for alert screen
* @param text The alert message
* @param delay How long the alert will be displayed, If delay is <code>Alert.FOREVER</code> then
* alert will be visible until user dismisses it
* @param type The alert type
* @param next The next screen
* @see javax.microedition.lcdui.Alert
*/
public static void showAlert(String title, String text, int delay, AlertType type, Displayable next) {
Alert currentAlert = new Alert(title);
currentAlert.setTimeout(delay);
currentAlert.setString(text);
currentAlert.setType(type);
display.setCurrent(currentAlert, next);
}
/**
* Resets screen stack
*/
public static void resetScreens() {
screens.removeAllElements();
}
/**
* Default destructor. Helps VM to perform garbage collection
*/
public static void destructor() {
screens.removeAllElements();
screens = null;
display = null;
application = null;
}
} // class ScreenManager
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -