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

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.

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.

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

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

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!");


        }
    }
}
commented: Making it count ! +5

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.

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

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........

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.