|
/*-------------------------------------------------- * GetNpost.java * * Use GET or POST to communicate with a Java servlet. * The servlet will search a database for the balance * of an account. * * Example from the book: Core J2ME Technology * Copyright John W. Muchow http://www.CoreJ2ME.com * You may use/modify for any non-commercial purpose *-------------------------------------------------*/ import javax.microedition.midlet.*; import javax.microedition.lcdui.*; import javax.microedition.io.*; import java.io.*; public class GetNpost extends MIDlet implements CommandListener { private Display display; // Reference to Display object private Form fmMain; // The main form private Alert alError; // Alert to error message private Command cmGET; // Request method GET private Command cmPOST; // Request method Post private Command cmExit; // Command to exit the MIDlet private TextField tfAcct; // Get account number private TextField tfPwd; // Get password private StringItem siBalance;// Show account balance private String errorMsg = null; public GetNpost() { display = Display.getDisplay(this); // Create commands cmGET = new Command("GET", Command.SCREEN, 2); cmPOST = new Command("POST", Command.SCREEN, 3); cmExit = new Command("Exit", Command.EXIT, 1); // Textfields tfAcct = new TextField("Account:", "", 5, TextField.NUMERIC); tfPwd = new TextField("Password:", "", 10, TextField.ANY | TextField.PASSWORD); // Balance string item siBalance = new StringItem("Balance: $", ""); // Create Form, add commands & componenets, listen for events fmMain = new Form("Account Information"); fmMain.addCommand(cmExit); fmMain.addCommand(cmGET); fmMain.addCommand(cmPOST); fmMain.append(tfAcct); fmMain.append(tfPwd); fmMain.append(siBalance); fmMain.setCommandListener(this); } public void startApp() { display.setCurrent(fmMain); } public void pauseApp() { } public void destroyApp(boolean unconditional) { } |