×

Discussion Board

Results 1 to 12 of 12
  1. #1
    Registered User
    Join Date
    Sep 2008
    Posts
    16

    commandButtons? help pls

    I am using netbeans ide 5.5 , i have created forms up to the Output form, the next output is the graph which i am creating in canvas..

    my question is, i have shown the Back and Main Menu button on my canvas, what code should i use, to make it work? "back" to go back to my last form from Netbeans, and "Main Menu" to go back to the main menu from My netbeans..

    So my java files are: myMidlet.java and Canvas.java

    help me pls? i am really new on j2me..

    someone pls? Thanks guys!

  2. #2
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Thumbs up Re: commandButtons? help pls

    Hey chinito15,
    do not worry ...
    You must be having the following code snippets -

    @ Two commands
    @ main menu implementation
    @ The part of the canvas that you want to show on the back command..

    Follow like this,
    @ Create the both commands
    @ Add the commands on the form,
    @ set the form as current displayable item,
    @ set the command listener on the form
    @ implement a method called as commandlistner(),it takes two params,display and command

    make your code like this,inside this method,

    if (command == back)
    {
    //set the current display what want on the action,
    }
    if(command == main-menu)
    {
    //set the current display as the main menu }
    }
    I hope that you can do it,these liens can help you,
    if you still can not do this then follow the code example
    public class TooManyCommands extends MIDlet implements CommandListener
    {
    private Display display; // Reference to Display object for this MIDlet
    private Form fmMain; // The main Form
    private TextBox tbAction; // Textbox to show when user selects upload/download
    private Command cmExit; // Exit the MIDlet
    private Command cmBack; // Go "back" to the main form
    private Command cmUload; // "upload" data - no real action done
    private Command cmDload; // "download" data - no real action done

    public TooManyCommands()
    {
    display = Display.getDisplay(this);

    cmExit = new Command("Exit", Command.EXIT, 1);
    cmBack = new Command("Back", Command.BACK, 1);
    cmUload = new Command("Upload", Command.SCREEN, 2);
    cmDload = new Command("Download", Command.SCREEN, 3);

    // Create the Form, add Commands, listen for events
    fmMain = new Form("Core J2ME");
    fmMain.addCommand(cmExit);
    fmMain.addCommand(cmUload);
    fmMain.addCommand(cmDload);
    fmMain.setCommandListener(this);

    // Create a Textbox, add Command, listen for events
    tbAction = new TextBox("Process Data", "Upload/download data ", 25, 0);
    tbAction.addCommand(cmBack);
    tbAction.setCommandListener(this);
    }

    // Called by application manager to start the MIDlet.
    public void startApp()
    {
    display.setCurrent(fmMain);
    }

    // A required method
    public void pauseApp()
    { }

    // A required method
    public void destroyApp(boolean unconditional)
    { }

    // Process events
    public void commandAction(Command c, Displayable s)
    {
    if (c == cmExit)
    {
    destroyApp(false);
    notifyDestroyed();
    }
    else if (c == cmUload || c == cmDload)
    display.setCurrent(tbAction);
    else if (c == cmBack)
    display.setCurrent(fmMain);
    }
    }

    Thanks,
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  3. #3
    Registered User
    Join Date
    Sep 2008
    Posts
    16

    Re: commandButtons? help pls

    Thank you for the reply, all of my forms that are going to be used are created in netbeans, private fmMainMenu and privatefm1stEquation

    In my canvas.java , i have shown the buttons Back and Main Menu(not functioning)..

    i have created

    public void commandAction(command c, Displayable s){
    if(c.getCommandType==BACK){
    // I dont know what to put here
    // This is to go back to the mainMidlet's last form that has been used
    }
    if(c.getCommandType==SCREEN){
    //This should move to mainMidlet's main menu form
    // I don't know what are the availble codes to call the action from this Canvas.java to mainMidlet
    }
    }

    I really dont know to connect the buttons...

  4. #4
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Thumbs up Re: commandButtons? help pls

    Hi,
    Can you just tell me what you wana display on the back command.
    and what on main menu..
    And what is the code you have done,

    I gave you that demo why dont you check that..
    If it is simple application then you can put the code here,
    let me check the same.
    Thanks,
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  5. #5
    Registered User
    Join Date
    Sep 2008
    Posts
    16

    Re: commandButtons? help pls

    Ok sir, sorry.. im desperate doing this, deadline is 1week.. school purpose only..

    http://www.mediafire.com/file/njowicd2nj1/myjava.rar

    I uploaded the files there sir, please take a look.

    Thanks for helping sir!

  6. #6
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Thumbs up Re: commandButtons? help pls

    Hi,
    Unable to save the same,
    Can not open the links,
    you can mail me,
    raj.sharma015@gmail.com

    Thanks,
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  7. #7
    Registered User
    Join Date
    Sep 2008
    Posts
    16

    Re: commandButtons? help pls

    Did you received my e-mail sir?

    its casamania_15@yahoo.com

    I will be waiting for your reply sir tomorrow, i've got to go now..

  8. #8
    Registered User
    Join Date
    Oct 2007
    Posts
    11

    Re: commandButtons? help pls

    If I understand all you have to do is a Display.setCurrent when you hit the buttons. Imagine that:

    We declare two forms

    Form form1 = new Form();
    Form form2 = new Form();

    and in the code where you define the buttons (I c&p from your code):

    public void commandAction(command c, Displayable s){
    if(c.getCommandType==BACK){
    // I dont know what to put here
    // This is to go back to the mainMidlet's last form that has
    // been used
    display.setCurrent(form1);

    }
    if(c.getCommandType==SCREEN){
    //This should move to mainMidlet's main menu form
    // I don't know what are the availble codes to call the action
    //from this Canvas.java to mainMidlet
    display.setCurrent(form2);
    }
    }

    hope this can be useful for you

  9. #9
    Registered User
    Join Date
    Sep 2008
    Posts
    16

    Re: commandButtons? help pls

    My forms are in my other MIdlet.java file created from netbeans..

    they are initialized private and i can't change them to public..

    Do i need to declare them in my Canvas.java? how?

    i hope mr. raj_j2me received my e-mail..

    thanks for helping too

  10. #10
    Registered User
    Join Date
    Sep 2008
    Posts
    16

    Re: commandButtons? help pls

    import javax.microedition.midlet.MIDlet;
    import javax.microedition.lcdui.*;
    import javax.microedition.midlet.*;
    import com.makeLogic.mg.LineGraph;
    import java.lang.System.*;
    import javax.microedition.lcdui.Canvas;
    import javax.microedition.lcdui.Command;
    import javax.microedition.lcdui.Displayable;
    import javax.microedition.lcdui.Font;
    import javax.microedition.lcdui.Graphics;

    public class LineGraphTest extends Canvas{

    private Display display;
    private int xmargin=15;
    public static Command cmdMain;
    public static Command cmdBack;
    public Econics midlet;


    public LineGraphTest(){
    this.display=display;
    cmdMain=new Command("Main Menu",Command.EXIT,2);
    cmdBack=new Command("Back",Command.BACK,1);
    addCommand(cmdMain);
    addCommand(cmdBack);

    }
    public void paint (Graphics g) {
    int width=getWidth();
    int height=getHeight();
    g.setColor (255,255,255);
    g.fillRect (0, 0, getWidth (), getHeight ());

    g.setStrokeStyle(Graphics.SOLID);
    //Draw X axis
    g.setColor(0x00ff00);
    g.drawLine(0, height/2, width, height/2);
    //Draw Y axis
    g.setColor(0x00ff00);
    g.drawLine(width/2, 0,width/2 , height);

    g.setColor(0,0,255);
    g.drawString("X",width/2,height/2,g.BASELINE|g.LEFT);
    }
    //Not sure with this
    public void commandAction(Command c,Displayable s) {

    if(c.getCommandType()== Command.BACK){
    display.setCurrent(midlet.get_frmInputCircleEq1());
    }
    if(c.getCommandType()== Command.EXIT){
    display.setCurrent(midlet.get_frmMainMenu());
    }
    }
    }

    i declared my mainMidlet which is Econics as mnidlet..

    i can show the buttons in the canvas output, but the actions won't work..I need help with this pleasE? anyone?

  11. #11
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Thumbs up Re: commandButtons? help pls

    Hi,
    Yeah I got the mail..however that I am not able to run ..due to the uncompleted code..or the packages..

    Since you are using the netbeans created attributes then what I have understand is that you can change the access modifier of the forms at the time of the creation...

    you can mail me the complete code and let me check..those files are not running..it is showing "org.netbeans.microedition.lcdui" this error,

    Thanks,
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  12. #12
    Registered User
    Join Date
    Sep 2008
    Posts
    16

    Re: commandButtons? help pls

    I've emailed you now sir, it contains my java files..

    the mainmidlet and canvas.java

    The overview of my project is described there sir..

    thanks

Similar Threads

  1. How To Implement equalizers in symbian C++..Pls help
    By upendersolanki in forum Symbian Media (Closed)
    Replies: 1
    Last Post: 2008-02-12, 16:48
  2. Replies: 15
    Last Post: 2006-08-28, 13:57
  3. pls help
    By viraj_turakhia in forum Symbian Tools & SDKs
    Replies: 0
    Last Post: 2004-12-13, 08:33
  4. pls help me pls..... (everybody read this).....need it urgently
    By Never_Die in forum Bluetooth Technology
    Replies: 0
    Last Post: 2004-11-30, 07:52

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×