Проблема устранена, если кому-то интересно, это то, чего не хватало.birthform.setCommandListener(this);
в функции getBirthForm () отсутствовал, так же, как и getLoginForm()
, отсутствовал loginform.setCommandListener (this) ;.Вот фиксированные коды
package BadisApp;
import java.io.IOException;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import java.util.Vector;
public class BadisMidlet extends MIDlet implements CommandListener {
//=========== FIELDS ========================
private LoginForm loginform; // The login form
private NotifyBirth birthform; // Birth Notification form
private Vector birthType;
private Vector gender;
//========= PROPERTIES ======================
/**
* create the login form
* @return Login form
*/
public LoginForm getLoginForm() {
if (loginform == null) {
loginform = new LoginForm("Sign In", this);
loginform.setCommandListener(this);
}
return loginform;
}
/**
* Create the birth notification form
* @return birthform
*/
public NotifyBirth getBirthForm() {
if (birthform == null) {
birthform = new NotifyBirth("Birth Notification", this.birthType, this.gender, this);
birthform.setCommandListener (this);} вернуть форму рождения;}
//======= CONSTRUCTOR ===============//
public BadisMidlet() {
gender = new Vector();
gender = getGender();
birthType = new Vector();
birthType = getBirthType();
loginform = getLoginForm();
birthform = getBirthForm();
}
//========== METHODS ================//
/**
* Create the dispaly Object
*/
public Display getDisplay() {
return Display.getDisplay(this);
}
/**
* populate the gender option
* @return gender Vector
*/
public Vector getGender() {
Vector vector = new Vector();
vector.addElement("== Choose ==");
vector.addElement("Male");
vector.addElement("Female");
return vector;
}
public Vector getBirthType() {
Vector v = new Vector();
v.addElement("== Choose ==");
v.addElement("Still Born");
v.addElement("Live Birth");
return v;
}
/**
* Switches the current screen to a new screen.
* @return void
*/
public void switchDisplay(Alert alert, Displayable newDisplayable) {
Display display = getDisplay();
if (alert == null) {
display.setCurrent(newDisplayable);
} else {
display.setCurrent(alert, newDisplayable);
}
}
/**
* Start the app by switching to the login form
*/
public void startBadisApp() {
switchDisplay(null, birthform);
}
/**
* Safely Exit the Midlet
*/
public void exitBadisApp() {
destroyApp(true);
notifyDestroyed();
}
public void commandAction(Command command, Displayable displayable) {
//======== COMMANDS FOR LOGIN FORM ==============
if (displayable == loginform) {
if (command == loginform.getCmdLogin()) {
// switchDisplay(null, birthform);
} else if (command == loginform.getCmdExit()) {
//Run exitBadisApp()
this.exitBadisApp();
}
} else if(displayable == birthform){
if(command == birthform.getCmdSave()){
System.out.print("nvnbvn");
// try {
// birthform.InsertData();
// } catch (IOException ex) {
// ex.printStackTrace();
// }
}
}
}
public void startApp() {
startBadisApp();
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
}
и это класс NotifyBirth
package BadisApp;
import java.io.*;
import javax.microedition.lcdui.*;
import java.util.Vector;
import javax.microedition.io.*;
public class NotifyBirth extends Form {
//=============Fields=======
private Command cmdExit;
private Command cmdSave;
private TextField childFname;
private TextField childMname;
private TextField childLname;
private DateField childDOB;
private ChoiceGroup birthType; // Hai au amekufa
private ChoiceGroup childGender;
private TextField Bwt; // born with weight
private TextField placeOfBirth; // Hospital name
private TextField motherFname;
private TextField motherMname;
private TextField motherLname;
private TextField residence;
//============ Properties ========
public Command getCmdExit() {
if (cmdExit == null) {
cmdExit = new Command("Exit", Command.EXIT, 2);
}
return cmdExit;
}
public Command getCmdSave() {
if (cmdSave == null) {
cmdSave = new Command("Save", Command.OK, 2);
}
return cmdSave;
}
public TextField getChildFirstName() {
if (childFname == null) {
childFname = new TextField("First Name", "", 30, TextField.ANY);
}
return childFname;
}
public TextField getChildMiddleName() {
if (childMname == null) {
childMname = new TextField("Middle Name", "", 30, TextField.ANY);
}
return childMname;
}
public TextField getChildLastName() {
if (childLname == null) {
childLname = new TextField("Last Name", "", 30, TextField.ANY);
}
return childLname;
}
public DateField getChildDOB() {
if (childDOB == null) {
childDOB = new DateField("Date Of Birth", DateField.DATE);
}
return childDOB;
}
public ChoiceGroup getBirthType() {
if (birthType == null) {
birthType = new ChoiceGroup("Birth Type", Choice.POPUP);
}
return birthType;
}
public ChoiceGroup initBirthType(Vector bType) {
if (birthType != null) {
//Load the birthtype option
for (int i = 0; i < bType.size(); i++) {
birthType.append((String) bType.elementAt(i), null);
}
}
return birthType;
}
public ChoiceGroup initGender(Vector gender) {
if (childGender != null) {
//Load the gender option
for (int i = 0; i < gender.size(); i++) {
childGender.append((String) gender.elementAt(i), null);
}
}
return childGender;
}
public ChoiceGroup getChildGender() {
if (childGender == null) {
childGender = new ChoiceGroup("Gender", Choice.POPUP);
}
return childGender;
}
public TextField getBornWithWeight() {
if (Bwt == null) {
Bwt = new TextField("Born With Weight (in grams)", "", 10, TextField.DECIMAL);
}
return Bwt;
}
public TextField getPlaceOfBirth() {
if (placeOfBirth == null) {
placeOfBirth = new TextField("Place Of Birth", "", 30, TextField.ANY);
}
return placeOfBirth;
}
public TextField getMotherFirstName() {
if (motherFname == null) {
motherFname = new TextField("Mother First Name", "", 20, TextField.ANY);
}
return motherFname;
}
public TextField getMotherMiddleName() {
if (motherMname == null) {
motherMname = new TextField("Mother Middle Name", "", 20, TextField.ANY);
}
return motherMname;
}
public TextField getMotherLastName() {
if (motherLname == null) {
motherLname = new TextField("Mother Last Name", "", 20, TextField.ANY);
}
return motherLname;
}
public TextField getResidence() {
if (residence == null) {
residence = new TextField("Residence", "", 30, TextField.ANY);
}
return residence;
}
public void InsertData() throws IOException {
HttpConnection httpConn = null;
String phpUrl = "http://127.0.0.1/badis/index.php/report/trial/";
InputStream inputStream = null;
OutputStream outputStream = null;
StringBuffer buffer = null;
try {
// Open an HTTP Connection object
httpConn = (HttpConnection) Connector.open(phpUrl);
// Setup HTTP Request to POST
httpConn.setRequestMethod(HttpConnection.POST);
httpConn.setRequestProperty("User-Agent", "Profile/MIDP-1.0 Confirguration/CLDC-1.0");
httpConn.setRequestProperty("Accept_Language", "en-US");
//Content-Type is must to pass parameters in POST Request
httpConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
outputStream = httpConn.openDataOutputStream();
String child = "child=" + childFname;
outputStream.write(child.getBytes());
buffer = new StringBuffer();
inputStream = httpConn.openDataInputStream();
int chr;
while ((chr = inputStream.read()) != -1) {
buffer.append((char) chr);
}
// Web Server just returns the birthday in mm/dd/yy format.
System.out.println(child + "'s First Name is " + buffer.toString());
} finally{
if(httpConn != null){
httpConn.close();
}
if(outputStream != null){
outputStream.close();
}
if(inputStream != null){
inputStream.close();
}
}
}
//============= CONSTRUCT ========
public NotifyBirth(String title, Vector bType, Vector gender, BadisMidlet parent) {
super(title);
//Create Commands
cmdExit = getCmdExit();
cmdSave = getCmdSave();
childFname = getChildFirstName();
childMname = getChildMiddleName();
childLname = getChildLastName();
childDOB = getChildDOB();
childGender = getChildGender();
childGender = initGender(gender);
Bwt = getBornWithWeight();
placeOfBirth = getPlaceOfBirth();
birthType = getBirthType();
birthType = initBirthType(bType);
residence = getResidence();
motherFname = getMotherFirstName();
motherMname = getMotherMiddleName();
motherLname = getMotherLastName();
//add to form
this.addCommand(cmdExit);
this.addCommand(cmdSave);
this.append(childFname);
this.append(childMname);
this.append(childLname);
this.append(childDOB);
this.append(birthType);
this.append(childGender);
this.append(Bwt);
this.append(motherFname);
this.append(motherMname);
this.append(motherLname);
this.append(placeOfBirth);
this.append(residence);
}
}
Счастливого кодирования ..
Приветствия