Discussion Board

Results 1 to 11 of 11
  1. #1
    Registered User kumarv75's Avatar
    Join Date
    May 2010
    Posts
    214
    Hi, how to get the value printed in the button to appear in the text area that I have created, I have initialized text area and the buttons in lwuit.............................I have created the buttons by array................

  2. #2
    Nokia Developer Champion jitu_goldie's Avatar
    Join Date
    Sep 2008
    Location
    Noida, U.P.
    Posts
    1,330
    dont know so much about LWUIT but there must be some function to get String or label of command.. Check and verify..
    look at this..
    command.getName();
    thanks,
    jitu_goldie..

    KEEP TRYING..

  3. #3
    Registered User j2me_bug's Avatar
    Join Date
    Jun 2010
    Posts
    3
    try getText() method of the button. If you are looking for the mechanism to press the button and set its value in a textarea , I think I've replied to you post on the same problem
    http://discussion.forum.nokia.com/fo...y-one-help-me-.....................

    To set value in a textarea , use setText() method of textArea.

    Please elaborate your problem if still u dont get the solution.

    Thanks.

  4. #4
    Registered User kumarv75's Avatar
    Join Date
    May 2010
    Posts
    214
    Quote Originally Posted by j2me_bug View Post
    try getText() method of the button. If you are looking for the mechanism to press the button and set its value in a textarea , I think I've replied to you post on the same problem
    http://discussion.forum.nokia.com/fo...y-one-help-me-.....................

    To set value in a textarea , use setText() method of textArea.

    Please elaborate your problem if still u dont get the solution.

    Thanks.


    Hi I am doing a calculator using lwuit wherein I have created the buttons and text area I wanna know how to display the value printed over the button to cum in textfield.......

    I am able to get the properties of the button by the following statement

    public void actionPerformed(ActionEvent ae)
    {
    //String numbers =("0123456789");
    //String operations =("+-*/.");
    //String Clear = "C";
    if(ae.getSource() instanceof Command)
    {
    if(ae.getSource() == exit)
    {
    parentMidlet.notifyDestroyed();
    }
    }
    if(ae.getSource() instanceof Button)
    {
    Button btn = (Button) ae.getSource();
    //System.out.println(""+btns);
    //txt.setText(numbers);
    String S = btn.getText();
    System.out.println("button is"+S);
    }
    }

    hi I have created the buttons using a string array ...................so now thw value that is getting printed should cum in text area how to make it cum pls help me...........

  5. #5
    Registered User kumarv75's Avatar
    Join Date
    May 2010
    Posts
    214
    Quote Originally Posted by kumarv75 View Post
    Hi I am doing a calculator using lwuit wherein I have created the buttons and text area I wanna know how to display the value printed over the button to cum in textfield.......

    I am able to get the properties of the button by the following statement

    public void actionPerformed(ActionEvent ae)
    {
    //String numbers =("0123456789");
    //String operations =("+-*/.");
    //String Clear = "C";
    if(ae.getSource() instanceof Command)
    {
    if(ae.getSource() == exit)
    {
    parentMidlet.notifyDestroyed();
    }
    }
    if(ae.getSource() instanceof Button)
    {
    Button btn = (Button) ae.getSource();
    //System.out.println(""+btns);
    //txt.setText(numbers);
    String S = btn.getText();
    System.out.println("button is"+S);
    }
    }

    hi I have created the buttons using a string array ...................so now thw value that is getting printed should cum in text area how to make it cum pls help me...........





    Hi I have got that myself........................by the follwing command

    if(ae.getSource() instanceof Button)
    {
    Button btn = (Button) ae.getSource();
    //System.out.println(""+btns);
    //txt.setText(numbers);
    /* String button = btn.getText();*/
    // System.out.println("button is"+button);
    txt.setText(btn.getText());
    }

    now I wanna get continues values as u get it in calculator like 11,22,121 so on............................................................

  6. #6
    Registered User kumarv75's Avatar
    Join Date
    May 2010
    Posts
    214
    Quote Originally Posted by kumarv75 View Post
    Hi I have got that myself........................by the follwing command

    if(ae.getSource() instanceof Button)
    {
    Button btn = (Button) ae.getSource();
    //System.out.println(""+btns);
    //txt.setText(numbers);
    /* String button = btn.getText();*/
    // System.out.println("button is"+button);
    txt.setText(btn.getText());
    }

    now I wanna get continues values as u get it in calculator like 11,22,121 so on............................................................
    I have even done tht on my own I wanna now get only numbers not the operators +,-,/,*...........................

  7. #7
    Registered User ektasrv's Avatar
    Join Date
    Oct 2009
    Location
    Noida
    Posts
    941
    So for this, in your actionPerformed()
    if you get any operator don't append it to the text.
    Thanks,
    Ekta

  8. #8
    Registered User kumarv75's Avatar
    Join Date
    May 2010
    Posts
    214
    Quote Originally Posted by ektasrv View Post
    So for this, in your actionPerformed()
    if you get any operator don't append it to the text.
    hi I gave as

    String numbers =("0123456789")
    if(ae.getsource == numbers)
    {
    Button btn = (Button) ae.getSource();

    txt.setText(btn.getText());
    }

    it doesnt stated any error but was not able to get the values in the text area it is not even evaluvating the if statement y wht might be the reason......................

  9. #9
    Registered User ektasrv's Avatar
    Join Date
    Oct 2009
    Location
    Noida
    Posts
    941
    Quote Originally Posted by kumarv75 View Post
    hi I gave as

    String numbers =("0123456789")
    if(ae.getsource == numbers)
    {
    Button btn = (Button) ae.getSource();

    txt.setText(btn.getText());
    }

    it doesnt stated any error but was not able to get the values in the text area it is not even evaluvating the if statement y wht might be the reason......................
    This if(ae.getsource == numbers) will not work, comment it out.
    update txt.setText(btn.getText()); with below
    You will need to compare if( btn.getText() .equals("0")||btn.getText() .equals("1")||btn.getText() .equals("2")||btn.getText() .equals("3")||btn.getText() .equals("4")||btn.getText() .equals("5")||btn.getText() .equals("6")||btn.getText() .equals("7")||btn.getText() .equals("8")||btn.getText() .equals("8")) txt.setText(btn.getText());
    Thanks,
    Ekta

  10. #10
    Registered User kumarv75's Avatar
    Join Date
    May 2010
    Posts
    214
    Quote Originally Posted by ektasrv View Post
    This if(ae.getsource == numbers) will not work, comment it out.
    update txt.setText(btn.getText()); with below
    You will need to compare if( btn.getText() .equals("0")||btn.getText() .equals("1")||btn.getText() .equals("2")||btn.getText() .equals("3")||btn.getText() .equals("4")||btn.getText() .equals("5")||btn.getText() .equals("6")||btn.getText() .equals("7")||btn.getText() .equals("8")||btn.getText() .equals("8")) txt.setText(btn.getText());

    hi Ekta thank u I have seperated the numbers from the operators thank u for u help .............................................now for the operators I have given a if loop like urs

    if(btn.getText().equals("+")||btn.getText().equals("-")||btn.getText().equals("*")||btn.getText().equals("/"))
    {
    doOperations();
    }
    which would call the doOperation method where I would define the +,- * / operations ..................k ekta its some personal oblication will u be online bcause if I have any doubt u can help me let me first define the doOperation method

  11. #11
    Registered User kumarv75's Avatar
    Join Date
    May 2010
    Posts
    214
    Quote Originally Posted by kumarv75 View Post
    hi Ekta thank u I have seperated the numbers from the operators thank u for u help .............................................now for the operators I have given a if loop like urs

    if(btn.getText().equals("+")||btn.getText().equals("-")||btn.getText().equals("*")||btn.getText().equals("/"))
    {
    doOperations();
    }
    which would call the doOperation method where I would define the +,- * / operations ..................k ekta its some personal oblication will u be online bcause if I have any doubt u can help me let me first define the doOperation method
    Hi ekta can u help me how can I get the value when I press the = button c I have wrriten as follows

    public void doOperations()
    {
    {
    if(valueone.equals(""))
    {
    valueone = txt.getText();
    operation = operand;
    secondValueStarted = false;
    }
    if(operand.equals("="))
    {
    valuetwo = txt.getText();
    if(operation.equals("+"))
    {
    float result = Float.parseFloat(valueone) + Float.parseFloat(valuetwo);
    resetCalculator();
    txt.setText(String.valueOf(result));
    }
    if(operation.equals("-"))
    {
    float result = Float.parseFloat(valueone) - Float.parseFloat(valuetwo);
    resetCalculator();
    txt.setText(String.valueOf(result));
    }
    if(operation.equals("*"))
    {
    float result = Float.parseFloat(valueone) * Float.parseFloat(valuetwo);
    resetCalculator();
    txt.setText(String.valueOf(result));
    }
    if(operation.equals("/"))
    {
    float result = Float.parseFloat(valueone) / Float.parseFloat(valuetwo);
    resetCalculator();
    txt.setText(String.valueOf(result));
    }
    }
    }

    }

    and I have globally declared

    protected String valueone="";

    protected String valuetwo="";

    protected String operation="";






    please help me..............................

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved