0

Hi
Am making a project that has multiple MIDlets. I have borrowed heavily from this project http://www.javaworld.com/javaworld/jw-01-2002/jw-0118-midp.html
I want to create a MIDlet that has an online user database, that users use to send views to a TV station.
I have seen the above project but that is for high end phones like Palms.
I want to create a single jar file that does all the above. The main problem is having multiple MIDlets that low-end phones cannot (or rather I haven't been able to know how) call from other MIDlets. How do I go about it???

Any views will be of help
Thanks guys

5
Contributors
10
Replies
11
Views
8 Years
Discussion Span
Last Post by Vishnu Sarasan
Featured Replies
  • 1

    Few things for start [LIST=1] [*]I split your single file of nearly 600 lines into multiple files as they should be organized [*]in Java Microedition there is no String method as equalsIgnoreCase() please follow [URL="http://72.5.124.55/javame/reference/apis/jsr118/index.html"]JME API[/URL] more closely or you can write such method for your self, it is not … Read More

0

Linked tutorial is 7 years old so if high-end devices used that time are now more likely out of stock and not used any more. Any of current low-end devices can do more then these "high-end".

As for your problem you need to provide better explanation as only thing I understand is you want to provide similar functionality which is easily done with the help of the tutorial.
I have no clue what you saying about multiple MIDlets as there is only one MIDlet that is running requests through HTTP to connect to servlet in order to retrieve data from database.

0

Thanks for the reply.
The reason I said Multiple midlets is because there are three different .java files. Now, I wanted to know how to place all the three in one .jar file that can be deployed to the s40 phone.(When I just place them together in the same midlet file in the SDK it says they should be in different midlets.)
Better still, if I could get source code with similar functionality in one .java file, it would be easier for me to go through and compile to one .jar file.
Thanks and hope to here from you soon.

0

Put your code in ZIP/RAR and upload it with next post so I can have look what is going on. The above is not standard behaviour.

PS: To attach document to post you need to be in Advanced Editing mode (click Go Advanced button bellow editing area) and the when you scroll bellow you will see Manage Attachments. Through this you can attach it

0

Hi
Here attached find the .java file I am trying to create but doesnt seem to work.
I have also included the LoginExample from which I hav borrowed alot from.
Please check it out for me and advice on any corrections or suggestions.
Thanks

Attachments
package MyProject;

import java.io.*;
import java.util.*;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.io.*;
import java.io.IOException;


public class MyProject extends MIDlet implements CommandListener
{


 private TextField username;
 private TextField password;
 private TextField repeatpassword;
 private TextField phoneno;
 private TextField comment;
 //private TextField curdate;
 //private TextField curtime;

 public String ti;
 public String entrydate;
 private String result;
 private String URLR;
 private String URLL;
 private String URLC;


private Command cmLogin;
private Command cmLoginF;
private Command cmSubmitregister;
private Command cmSubmitcomment;
private Command cmRegisterF;
private Command cmExit;
private Form lForm;
private Form mForm;
private Form CForm;


  public MyProject()  {


            lForm = new Form("Login");

            username = new TextField("Username:", "", 12, TextField.ANY | TextField.ANY);
            password = new TextField("Password:", "", 12, TextField.ANY | TextField.PASSWORD);

            /* Calendar logincalenda = Calendar.getInstance();
            logincalenda.setTime(new Date());

            int monthc = logincalenda.get(Calendar.MONTH) + 1;
            int datec = logincalenda.get(Calendar.DATE);
            int yearc = logincalenda.get(Calendar.YEAR);

            String entryDate = "" + yearc + "-" + monthc + "-" + datec;
            curdate.setString(entryDate);

            int h = logincalenda.get(Calendar.HOUR_OF_DAY);
            int m = logincalenda.get(Calendar.MINUTE);
            int s = logincalenda.get(Calendar.SECOND);
            String thetime = (h < 10 ? "0" : "") + h + "." + (m < 10 ? "0" : "") + m + "." + (s < 10 ? "0" : "") + s;
            curtime.setString(thetime);
            
            curdate = new TextField("Date:", "", 12, TextField.ANY | TextField.UNEDITABLE); //date
            curtime = new TextField("Time:", "", 12, TextField.ANY | TextField.UNEDITABLE); //time

            */

            lForm.append(username);
            lForm.append(password);
            //lForm.append(curdate);
            //lForm.append(curtime);

            cmLogin = new Command("Submit",Command.SCREEN,1);
            cmRegisterF = new Command("Register",Command.SCREEN,1);
            
            
            lForm.addCommand(cmRegisterF);
            lForm.addCommand(cmLogin);
            lForm.setCommandListener(this);

            
            
            mForm = new Form("Register");

            username = new TextField("Username:", "", 12, TextField.ANY | TextField.ANY);
            phoneno = new TextField("Phone No.:", "", 12, TextField.ANY | TextField.ANY);
            password = new TextField("Password:", "", 12, TextField.ANY | TextField.PASSWORD);
            repeatpassword = new TextField("Confirm password:", "", 12, TextField.ANY | TextField.PASSWORD);
           // curdate = new TextField("Date:", "", 12, TextField.ANY | TextField.UNEDITABLE); //date
           // curtime = new TextField("Time:", "", 12, TextField.ANY | TextField.UNEDITABLE); //time


            mForm.append(username);
            mForm.append(phoneno);
            mForm.append(password);
            mForm.append(repeatpassword);
            //mForm.append(curdate);
            //mForm.append(curtime);

            cmSubmitregister = new Command("Submit",Command.SCREEN,1);
            cmExit = new Command("Exit",Command.SCREEN,1);
            
            mForm.addCommand(cmExit);
            mForm.addCommand(cmSubmitregister);
            mForm.setCommandListener(this);


            CForm = new Form("Send your Comment");

            username = new TextField("Username:", "", 12, TextField.ANY | TextField.ANY);
            //curdate = new TextField("Date:", "", 12, TextField.ANY | TextField.UNEDITABLE); //date
            //curtime = new TextField("Time:", "", 12, TextField.ANY | TextField.UNEDITABLE); //time
            comment = new TextField("Your Comment:", "", 460, TextField.ANY | TextField.ANY);

            CForm.append(username);
            CForm.append(password);
            CForm.append(repeatpassword);
            //CForm.append(curdate);
            //CForm.append(curtime);
            CForm.append(comment);

            cmSubmitcomment = new Command("Submit",Command.SCREEN,1);
            cmExit = new Command("Exit",Command.SCREEN,1);

            CForm.addCommand(cmExit);
            CForm.addCommand(cmSubmitcomment);
            CForm.setCommandListener(this);
            
  }

  public void destroyApp( boolean unconditional ){

  }

  public void startApp(){
   
    Display.getDisplay(this).setCurrent(lForm);

  }

  public void pauseApp(){

  }

 public void validatePassword() {

    try{

         String pass=password.getString();
         String pass2=repeatpassword.getString();

        if (pass.equals(pass2)){

            submitR();
            
        }

        else{

             tryRAgain();
        }


    }
    catch(Exception j){
       System.err.println(j.getMessage());
    }
 }

/*
  public void showMsg(){

        try {


            //   Alert success = new Alert("Regisration Successful", "Your Registration Process is completed!", null, AlertType.INFO);

            username.setString("");
            password.setString("");
            repeatpassword.setString("");

            showmenu2();

            // Display.getDisplay(this).setCurrent( vForm);
            //Display.getDisplay(this).setCurrent(TARGForm);
        }
        catch (IOException ex) {
            ex.printStackTrace();
        }

           // Display.getDisplay(thi2me+s).setCurrent( vForm);
             //Display.getDisplay(this).setCurrent(TARGForm);


  }
 */

  public void tryRAgain() {
      
   Alert error = new Alert("Registration Error", "Passwords don't match", null, AlertType.ERROR);
   
    username.setString("");
    phoneno.setString("");
    password.setString("");
    repeatpassword.setString("");
    
    Display.getDisplay(this).setCurrent(error, mForm);
  }
/*public void tryLAgain() {
    
   Alert error = new Alert("Login Error", "Please try again", null, AlertType.ERROR);

    username.setString("");
    password.setString("");
    
    Display.getDisplay(this).setCurrent(error, lForm);
    
  }
*/
  public void commandAction(Command c, Displayable d) {

      if (c == cmExit) {

         Display.getDisplay(this).setCurrent(mForm);
		destroyApp(true);
		notifyDestroyed();
    }
      else if (c == cmLoginF) {

         Display.getDisplay(this).setCurrent(lForm);
		//destroyApp(false);
		//notifyDestroyed();
    }
     else if (c == cmRegisterF) {

         Display.getDisplay(this).setCurrent(mForm);
		//destroyApp(false);
		//notifyDestroyed();
    }
     else if (c == cmLogin){

         Thread thl = new Thread(){

            public void run(){

                try {

                submitL();

                }

               catch (Exception e){
                    System.err.println(e.getMessage());
                }
            }
        };

        thl.start();
     }

     else if (c == cmSubmitregister){

         Thread thr = new Thread(){

            public void run(){

                try {

                validatePassword();

                }

               catch (Exception e){
                    System.err.println(e.getMessage());
                }
            }
        };

        thr.start();
     }
      else if (c == cmSubmitcomment){

         Thread thc = new Thread(){

            public void run(){

                try {

                submitC();

                }

               catch (Exception e){
                    System.err.println(e.getMessage());
                }
            }
        };

        thc.start();
     }

  }
/*
    public void showmenu() throws IOException{

    //SECOND MENU STARTS
        try{
    //Display.getDisplay(this).setCurrent(TARGForm);
            Display.getDisplay(this).setCurrent(BForm);
    //display.setCurrent(vForm);
        }
        catch(Exception j){
            j.printStackTrace();
        }
    }
     public void showmenu2() throws IOException{

    //SECOND MENU STARTS
        try{
    //Display.getDisplay(this).setCurrent(TARGForm);
            Display.getDisplay(this).setCurrent(mForm);
    //display.setCurrent(vForm);
        }
        catch(Exception j){
            j.printStackTrace();
        }
    }
*/

 private void submitR() throws IOException {

  HttpConnection http = null;
  InputStream is = null;
  boolean ret = false;
  StringBuffer sb = null;

     URLR =  "http://www.emobilis-server.com/mkaburu/phone/MyProject/register.php" + "?" +
                                "user=" + username.getString() + "&" +
                                "pass=" + password.getString() + "&" +
                                "phoneno=" + phoneno.getString();




     try {

			http = (HttpConnection) Connector.open(URLR);
			// set the request method as GET
			http.setRequestMethod(HttpConnection.GET);
			// server response
			if (http.getResponseCode() == HttpConnection.HTTP_OK)
			{
				sb = new StringBuffer();
				int ch;
				is = http.openInputStream();
				while ((ch = is.read()) != -1)
					sb.append((char) ch);
			}
			else
			{
				System.out.println("Network error");

		}
  }
  catch( Exception e )
        {
            System.err.println(e.getMessage());
  			}



    finally
		{
			if (is != null)
				is.close();
			if (sb != null)
				result = sb.toString();

			else
				//networkError();
			if (http != null)
				http.close();
		}



      if (result.equalsIgnoreCase(""))
      {
          String x;

          x =result.trim();
          if (x.equals("0"))
          {
          Alert error = new Alert("Registration Unsuccessful", "Please try again", null, AlertType.ERROR);

           username.setString("");
           phoneno.setString("");
           password.setString("");
           repeatpassword.setString("");
           
          Display.getDisplay(this).setCurrent(error, mForm);
          }
          else if(x.equals("1"))
          {
            Alert info = new Alert("Successful Registration", "Proceed to login", null, AlertType
1

Few things for start

  1. I split your single file of nearly 600 lines into multiple files as they should be organized
  2. in Java Microedition there is no String method as equalsIgnoreCase() please follow JME API more closely or you can write such method for your self, it is not difficult.
  3. Provided URL for connection is not working so you better set it up before you do anything else (few tips in configuration of your server and PHP can be found here on Sony Ericsson, I never try it so I cannot comment. However my preference would be to use Java enabled server so I can talk to servlet directly then messing around with some other web implementations). Because of the issue with URL not being set up I couldn't test this application any futher

MIDlet - MyProject.java

package myProject;

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

import myProject.screens.LoginScreen;

public class MyProject extends MIDlet{

    public String ti;
    public String entrydate;
    public String result;

    private Display display;


    public MyProject() {

        /* Calendar logincalenda = Calendar.getInstance();
        logincalenda.setTime(new Date());

        int monthc = logincalenda.get(Calendar.MONTH) + 1;
        int datec = logincalenda.get(Calendar.DATE);
        int yearc = logincalenda.get(Calendar.YEAR);

        String entryDate = "" + yearc + "-" + monthc + "-" + datec;
        curdate.setString(entryDate);

        int h = logincalenda.get(Calendar.HOUR_OF_DAY);
        int m = logincalenda.get(Calendar.MINUTE);
        int s = logincalenda.get(Calendar.SECOND);
        String thetime = (h < 10 ? "0" : "") + h + "." + (m < 10 ? "0" : "") + m + "." + (s < 10 ? "0" : "") + s;
        curtime.setString(thetime);

        curdate = new TextField("Date:", "", 12, TextField.ANY | TextField.UNEDITABLE); //date
        curtime = new TextField("Time:", "", 12, TextField.ANY | TextField.UNEDITABLE); //time

        */

    }

    public void startApp() {
        if(display == null){
            display = Display.getDisplay(this);
        }
        LoginScreen lForm = new LoginScreen(this);
        display.setCurrent(lForm);

    }

    public void pauseApp() {}

    public void destroyApp(boolean unconditional) {}
/*
  public void showMsg(){

        try {


            //   Alert success = new Alert("Regisration Successful", "Your Registration Process is completed!", null, AlertType.INFO);

            username.setString("");
            password.setString("");
            repeatpassword.setString("");

            showmenu2();

            // Display.getDisplay(this).setCurrent( vForm);
            //Display.getDisplay(this).setCurrent(TARGForm);
        }
        catch (IOException ex) {
            ex.printStackTrace();
        }

           // Display.getDisplay(thi2me+s).setCurrent( vForm);
             //Display.getDisplay(this).setCurrent(TARGForm);
  }
 */

/*
    public void showmenu() throws IOException{

    //SECOND MENU STARTS
        try{
    //Display.getDisplay(this).setCurrent(TARGForm);
            Display.getDisplay(this).setCurrent(BForm);
    //display.setCurrent(vForm);
        }
        catch(Exception j){
            j.printStackTrace();
        }
    }
     public void showmenu2() throws IOException{

    //SECOND MENU STARTS
        try{
    //Display.getDisplay(this).setCurrent(TARGForm);
            Display.getDisplay(this).setCurrent(mForm);
    //display.setCurrent(vForm);
        }
        catch(Exception j){
            j.printStackTrace();
        }
    }
*/
}

LoginScreen.java

package myProject.screens;

/**
 * Created by IntelliJ IDEA.
 * User: Peter
 * Date: 20-Sep-2009
 * Time: 10:06:27
 */
import java.io.InputStream;
import java.io.IOException;

import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;
import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.TextField;

import myProject.MyProject;

public class LoginScreen extends Form implements CommandListener{

    private TextField username;
    private TextField password;
    private Command cmLogin;
    private Command cmRegister;
    private MyProject myProject;
    private String URLL;
    private String result;

    public LoginScreen(MyProject myProject){
        super("Login Screen");
        this.myProject = myProject;
        init();
    }

    private void init(){
        username = new TextField("Username:", "", 12, TextField.ANY);
        password = new TextField("Password:", "", 12, TextField.PASSWORD);
        append(username);
        append(password);

        cmLogin = new Command("Login", Command.SCREEN, 1);
        cmRegister = new Command("Register", Command.SCREEN, 1);


        addCommand(cmRegister);
        addCommand(cmLogin);
        setCommandListener(this);
    }

    public void commandAction(Command c, Displayable d){
        if(c == cmRegister){
            RegistrationScreen registrationScreen = new RegistrationScreen(myProject);
            Display.getDisplay(myProject).setCurrent(registrationScreen);
        }
        else if (c == cmLogin) {

            Thread thl = new Thread() {

                public void run() {

                    try {
                        submitLogin();
                    }

                    catch (Exception e) {
                        System.err.println(e.getMessage());
                    }
                }
            };

            thl.start();
        }
    }

    private void submitLogin() throws IOException {

        HttpConnection http = null;
        InputStream is = null;
        boolean ret = false;
        StringBuffer sb = null;

        URLL = "http://www.emobilis-server.com/mkaburu/phone/MyProject/login.php" + "?" +
                "user=" + username.getString() + "&" +
                "pass=" + password.getString();


        try {

            http = (HttpConnection) Connector.open(URLL);
            // set the request method as GET
            http.setRequestMethod(HttpConnection.GET);
            // server response
            if (http.getResponseCode() == HttpConnection.HTTP_OK) {
                sb = new StringBuffer();
                int ch;
                is = http.openInputStream();
                while ((ch = is.read()) != -1)
                    sb.append((char) ch);
            }
            else {
                System.out.println("Network error");

            }
        }
        catch (Exception e) {
            System.err.println(e.getMessage());
        }


        finally {
            if (is != null)
                is.close();
            if (sb != null)
                result = sb.toString();

            else
                //networkError();
                if (http != null)
                    http.close();
        }


        if (result.equals("")) {
            String x;

            x = result.trim();
            if (x.equals("0")) {
                Alert error = new Alert("Login Incorrect", "Please enter correct username and password", null, AlertType.ERROR);

                username.setString("");
                password.setString("");

                Display.getDisplay(myProject).setCurrent(error, this);
            }

            else if (x.equals("1")) {
                Alert info = new Alert("Login Success", "Proceed to comment", null, AlertType.INFO);
                CommentScreen CForm = new CommentScreen(myProject);
                Display.getDisplay(myProject).setCurrent(info, CForm);
            }

            //BForm.append((result));
            //BForm.append("INSERTION ERROR!");


        }
    }
}

RegistrationScreen.java

package myProject.screens;

/**
 * Created by IntelliJ IDEA.
 * User: Peter
 * Date: 20-Sep-2009
 * Time: 10:27:25
 */
import java.io.InputStream;
import java.io.IOException;

import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;
import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.TextField;

import myProject.MyProject;

public class RegistrationScreen extends Form implements CommandListener{

    private MyProject myProject;
    private TextField username;
    private TextField password;
    private TextField repeatpassword;
    private TextField phoneno;
    private Command cmSubmitregister;
    private Command cmExit;
    private String URLR;
    private String result;

    public RegistrationScreen(MyProject myProject){
        super("Registration Form");
        this.myProject = myProject;
        init();
    }

    private void init(){
        username = new TextField("Username:", "", 12, TextField.ANY);
        phoneno = new TextField("Phone No.:", "", 12, TextField.ANY);
        password = new TextField("Password:", "", 12, TextField.PASSWORD);
        repeatpassword = new TextField("Confirm password:", "", 12, TextField.PASSWORD);

        append(username);
        append(phoneno);
        append(password);
        append(repeatpassword);

        cmSubmitregister = new Command("Register", Command.SCREEN, 1);
        cmExit = new Command("Exit", Command.SCREEN, 1);

        addCommand(cmExit);
        addCommand(cmSubmitregister);
        setCommandListener(this);
    }

    public void commandAction(Command c, Displayable d){
        if(c == cmExit){
            myProject.destroyApp(true);
            myProject.notifyDestroyed();
        }
        else if (c == cmSubmitregister) {

            Thread thr = new Thread() {
                public void run() {
                    try {
                        validatePassword();
                    }
                    catch (Exception e) {
                        System.err.println(e.getMessage());
                    }
                }
            };
            thr.start();
        }
    }

    private void validatePassword() {

        try {

            String pass = password.getString();
            String pass2 = repeatpassword.getString();

            if (pass.equals(pass2)) {
                submitR();
            }
            else {
                tryRAgain();
            }
        }
        catch (Exception j) {
            System.err.println(j.getMessage());
        }
    }

    private void submitR() throws IOException {

        HttpConnection http = null;
        InputStream is = null;
        boolean ret = false;
        StringBuffer sb = null;

        URLR = "http://www.emobilis-server.com/mkaburu/phone/MyProject/register.php" + "?" +
                "user=" + username.getString() + "&" +
                "pass=" + password.getString() + "&" +
                "phoneno=" + phoneno.getString();


        try {

            http = (HttpConnection) Connector.open(URLR);
            // set the request method as GET
            http.setRequestMethod(HttpConnection.GET);
            // server response
            if (http.getResponseCode() == HttpConnection.HTTP_OK) {
                sb = new StringBuffer();
                int ch;
                is = http.openInputStream();
                while ((ch = is.read()) != -1)
                    sb.append((char) ch);
            }
            else {
                System.out.println("Network error");

            }
        }
        catch (Exception e) {
            System.err.println(e.getMessage());
        }


        finally {
            if (is != null)
                is.close();
            if (sb != null)
                result = sb.toString();

            else
                //networkError();
                if (http != null)
                    http.close();
        }


        if (result.equals("")) {
            String x;

            x = result.trim();
            if (x.equals("0")) {
                Alert error = new Alert("Registration Unsuccessful", "Please try again", null, AlertType.ERROR);

                username.setString("");
                phoneno.setString("");
                password.setString("");
                repeatpassword.setString("");

                Display.getDisplay(myProject).setCurrent(error, this);
            }
            else if (x.equals("1")) {
                Alert info = new Alert("Successful Registration", "Proceed to login", null, AlertType.INFO);
                LoginScreen lForm = new LoginScreen(myProject);
                Display.getDisplay(myProject).setCurrent(info, lForm);
            }

            //BForm.append((result));
            //BForm.append("INSERTION ERROR!");


        }
    }

    private void tryRAgain() {

        Alert error = new Alert("Registration Error", "Passwords don't match", null, AlertType.ERROR);

        username.setString("");
        phoneno.setString("");
        password.setString("");
        repeatpassword.setString("");
        LoginScreen mForm = new LoginScreen(myProject);
        Display.getDisplay(myProject).setCurrent(error, mForm);
    }
}

CommentScreen.java

package myProject.screens;

/**
 * Created by IntelliJ IDEA.
 * User: Peter
 * Date: 20-Sep-2009
 * Time: 10:57:13
 */
import java.io.InputStream;
import java.io.IOException;

import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;
import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.TextField;

import myProject.MyProject;

public class CommentScreen extends Form implements CommandListener{

    private MyProject myProject;
    private TextField username;
    private TextField comment;
    private TextField password;
    private TextField repeatpassword;
    private Command cmSubmitcomment;
    private Command cmExit;
    private String URLC;
    private String result;

    public CommentScreen(MyProject myProject){
        super("Send your Comment");
        this.myProject = myProject;
        init();
    }

    private void init(){

        username = new TextField("Username:", "", 12, TextField.ANY);
        //curdate = new TextField("Date:", "", 12, TextField.ANY | TextField.UNEDITABLE); //date
        //curtime = new TextField("Time:", "", 12, TextField.ANY | TextField.UNEDITABLE); //time
        comment = new TextField("Your Comment:", "", 460, TextField.ANY);
        password = new TextField("Password:", "", 12, TextField.PASSWORD);
        repeatpassword = new TextField("Confirm password:", "", 12, TextField.PASSWORD);

        append(username);
        append(password);
        append(repeatpassword);
        //CForm.append(curdate);
        //CForm.append(curtime);
        append(comment);

        cmSubmitcomment = new Command("Submit", Command.SCREEN, 1);
        cmExit = new Command("Exit", Command.SCREEN, 1);

        addCommand(cmExit);
        addCommand(cmSubmitcomment);
        setCommandListener(this);
    }

    public void commandAction(Command c, Displayable d){
        if(c == cmExit){
            myProject.destroyApp(true);
            myProject.notifyDestroyed();
        }
        else if (c == cmSubmitcomment) {

            Thread thc = new Thread() {

                public void run() {

                    try {
                        submitC();
                    }
                    catch (Exception e) {
                        System.err.println(e.getMessage());
                    }
                }
            };
            thc.start();
        }
    }

    private void submitC() throws IOException {

        HttpConnection http = null;
        InputStream is = null;
        boolean ret = false;
        StringBuffer sb = null;

        URLC = "http://www.emobilis-server.com/mkaburu/phone/MyProject/comment.php" + "?" +
                "user=" + username.getString() + "&" +
                "comment=" + comment.getString();


        try {

            http = (HttpConnection) Connector.open(URLC);
            // set the request method as GET
            http.setRequestMethod(HttpConnection.GET);
            // server response
            if (http.getResponseCode() == HttpConnection.HTTP_OK) {
                sb = new StringBuffer();
                int ch;
                is = http.openInputStream();
                while ((ch = is.read()) != -1)
                    sb.append((char) ch);
            }
            else {
                System.out.println("Network error");

            }
        }
        catch (Exception e) {
            System.err.println(e.getMessage());
        }


        finally {
            if (is != null)
                is.close();
            if (sb != null)
                result = sb.toString();

            else
                //networkError();
                if (http != null)
                    http.close();
        }


        if (result.equals("")) {
            String x;

            x = result.trim();
            if (x.equals("0")) {
                Alert error = new Alert("Submission Error", "Please try again", null, AlertType.ERROR);
                Display.getDisplay(myProject).setCurrent(error, this);
            }

            else if (x.equals("1")) {
                Alert info = new Alert("Submission Success", "Thank you for your comment and support", null, AlertType.INFO);
                Display.getDisplay(myProject).setCurrent(info, this);
            }

            //BForm.append((result));
            //BForm.append("INSERTION ERROR!");


        }
    }
}
Votes + Comments
Making it count !
0

Peter you are a savior !!!
Thanks alot. Let me work on the URL pages and tweek the errors. Our school server had some problem.
Thanks again.

0

Thankyou peter...... its gr8 sapmple for biginners....

pls do post such basic things....that would be usefull for biginers....

if you provide the email id..its easy to communicate


Dj&Jayesh

0

i want to call midlet . i have 4 midlet. in one midlet i create menu by usin list with Radio button . i want to call another midlet by click on radio button how can i call another midlet by clicking on radio button plz reply me........

Edited by peter_budo: removed email

0

i want to call midlet . i have 4 midlet. in one midlet i create menu by usin list with Radio button . i want to call another midlet by click on radio button how can i call another midlet by clicking on radio button plz reply me........

If you can not be bothered reading above suggestions and do some coding to show case your issue, then I'm not interested in helping

0

Thanks alot Peter..Great work..Keep going...If u don't mind please give me your email id..Iam a fresher in J2ME..

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.