Show InputUI.java syntax highlighted
/**
* Copyright (c) 2004
* Helsinki Institute of Physics
* see LICENSE file for details
*
* InputUI.java
* Created on Mar 7, 2004
*/
package fi.hip.gb.client;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.TextBox;
import javax.microedition.lcdui.TextField;
/**
* Component for asking input from the user. Used
* by initializing and waiting until {@link InputUI#getMessage()}
* returns.
* <p>
* If the user pushes the OK button, {@link InputUI#getMessage()}
* returns the typed message. After the Back button
* is pressed {@link InputUI#getMessage()} returns null.
* <p>
* This class takes care of putting it on the screen
* and restoring the old screen back.
*
* @author Juho Karppinen
*/
public class InputUI extends TextBox implements CommandListener {
/** button pressed by the user, zero by default */
private int commandType;
/**
* Creates component for asking textual input from the user.
*
* @param label the text presented to the user
* @param okButton label for the OK button
*/
public InputUI(String label, String okButton) {
super(label, "", 200, TextField.ANY);
addCommand(new Command(okButton, Command.OK, 1));
addCommand(new Command("Back", Command.CANCEL, 1));
setCommandListener( this );
MIDui.next(this);
}
/**
* Blocks until the user has typed the message and
* pressed the OK or BACK buttons. Restores
* the old screen back to visible.
* <p>
* Notice: this method MUST be called from separate
* thread since it blocks the until user clicks
* the button.
*
* @return string message or null if user has canceled.
*/
public String getMessage() {
while(commandType == 0) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
}
}
MIDui.back(true);
if(commandType == Command.OK) {
return getString();
}
return null;
}
/*
* @see javax.microedition.lcdui.CommandListener#commandAction(javax.microedition.lcdui.Command, javax.microedition.lcdui.Displayable)
*/
public void commandAction(Command c, Displayable disp) {
commandType = c.getCommandType();
}
}
See more files for this project here