Show Logging.java syntax highlighted
/**
* Copyright (c) 2004
* Helsinki Institute of Physics
* see LICENSE file for details
*
* Logging.java
* Created on Feb 8, 2004
*/
package fi.hip.gb.client;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.StringItem;
import javax.microedition.lcdui.TextField;
/**
* Logging screen and routines.
*
* @author Juho Karppinen
*/
public class Logging extends Form implements CommandListener {
/** login name */
private TextField tfUserName =
new TextField("User name: ", "", 32, TextField.ANY);
/** login password */
private TextField tfPassword =
new TextField("Password: ", "", 32, TextField.PASSWORD);
public Logging() {
super("Login to the server");
append(new StringItem("info:", "Login to the server"));
append(tfUserName);
append(tfPassword);
addCommand(new Command("Login", Command.OK, 1));
addCommand(new Command("Cancel", Command.BACK, 1));
setCommandListener(this);
String username = Configs.readString(Configs.INDEX_LOGINNAME);
if(username == null)
username = MIDui.instance.getAppProperty("UserName");
tfUserName.setString(username);
}
/**
* Gets the login name of the user
* @return user name
*/
public String getLoginName() {
return tfUserName.getString();
}
/**
* Login to the server using values of the UI fields.
* Returns back to main form if loggin succeeded, otherwise
* shows the exception and retry
*/
private void logging() {
MIDui.next(new ProgressForm("Logging user " + tfUserName.getString()));
new Thread( new Runnable() {
public void run() {
try {
MIDui.getClient().login(
tfUserName.getString(),
tfPassword.getString());
// save the username for next time
Configs.storeString(Configs.INDEX_LOGINNAME, tfUserName.getString());
// should re-execute the command but just go back to start
MIDui.showMainForm();
} catch (Exception e) {
MIDui.showException("Logging failed", e);
}
}
}).start();
}
/*
* @see javax.microedition.lcdui.CommandListener#commandAction(javax.microedition.lcdui.Command, javax.microedition.lcdui.Displayable)
*/
public void commandAction(Command c, Displayable disp) {
if (c.getCommandType() == Command.OK) {
if(tfPassword.getString().length() >= 6)
logging();
else
MIDui.showAlert("Password too short",
"Password must be at least 6 characters",
AlertType.CONFIRMATION);
} else {
MIDui.back(true);
}
}
}
See more files for this project here