×

Discussion Board

Page 1 of 12 1234567891011 ... LastLast
Results 1 to 15 of 179
  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    214

    Unhappy doubt in lwuit project

    Hi I am doing a calculator project in lwuit the problem now I am facing is when the operations are pressed it does not start a new value and also please tell me how to store a value temporarily .........................up till now I have created the form that contains the buttons and the text area where to display and also have seperated the numbers and operators ,as in a windows calculator the numbers would only cum not the operators am dng the similar way can u help me please........................

  2. #2
    Registered User
    Join Date
    Oct 2009
    Location
    Noida
    Posts
    941

    Re: doubt in lwuit project

    Quote Originally Posted by kumarv75 View Post
    Hi I am doing a calculator project in lwuit the problem now I am facing is when the operations are pressed it does not start a new value and also please tell me how to store a value temporarily .........................up till now I have created the form that contains the buttons and the text area where to display and also have seperated the numbers and operators ,as in a windows calculator the numbers would only cum not the operators am dng the similar way can u help me please........................
    when the operations are pressed it does not start a new value ---> looks to be the problem in your logic, share the codelet to debug.
    please tell me how to store a value temporarily ---> take temp variable and assign it.
    Thanks,
    Ekta

  3. #3
    Registered User
    Join Date
    May 2010
    Posts
    214

    Re: doubt in lwuit project

    Quote Originally Posted by ektasrv View Post
    when the operations are pressed it does not start a new value ---> looks to be the problem in your logic, share the codelet to debug.
    please tell me how to store a value temporarily ---> take temp variable and assign it.

    what is a codelet ??????

  4. #4
    Registered User
    Join Date
    May 2010
    Posts
    214

    Re: doubt in lwuit project

    Quote Originally Posted by ektasrv View Post
    when the operations are pressed it does not start a new value ---> looks to be the problem in your logic, share the codelet to debug.
    please tell me how to store a value temporarily ---> take temp variable and assign it.
    hi I have written the code as follows


    protected boolean secondValueStarted = false;\\decleared globally

    String operations =("+-/*=");

    if(ae.getSource() instanceof Button)
    {if(operations.indexOf(btn.getText())> -1)
    {
    doOperations(operation);
    }

    public void doOperations(String operand)
    {
    if(valueone.equals(""))
    {
    valueone = txt.getText();\\value one would be stored here
    operation = operand;
    secondValueStarted = false;
    }
    if(operand.equals("="))
    {
    if(operand.equals("+"))
    {
    float result = Float.parseFloat(valueone) + Float.parseFloat(valuetwo);
    resetCalculator();
    valueone=""+result;
    txt.setText(String.valueOf(result));
    }
    }

    can u tell me what is wrong in my logic that u fell............................

  5. #5
    Registered User
    Join Date
    Oct 2009
    Location
    Noida
    Posts
    941

    Re: doubt in lwuit project

    Quote Originally Posted by kumarv75 View Post
    hi I have written the code as follows


    protected boolean secondValueStarted = false;\\decleared globally

    String operations =("+-/*=");

    if(ae.getSource() instanceof Button)
    {if(operations.indexOf(btn.getText())> -1)
    {
    doOperations(operation);
    }

    public void doOperations(String operand)
    {
    if(valueone.equals(""))
    {
    valueone = txt.getText();\\value one would be stored here
    operation = operand;
    secondValueStarted = false;
    }
    if(operand.equals("="))
    {
    if(operand.equals("+"))
    {
    float result = Float.parseFloat(valueone) + Float.parseFloat(valuetwo);
    resetCalculator();
    valueone=""+result;
    txt.setText(String.valueOf(result));
    }
    }

    can u tell me what is wrong in my logic that u fell............................
    I cannot see, where have you assigned value to variable valuetwo?
    try
    float result = Float.parseFloat(valueone) + Float.parseFloat(txt.getText());
    Thanks,
    Ekta

  6. #6
    Registered User
    Join Date
    May 2010
    Posts
    214

    Re: doubt in lwuit project

    Quote Originally Posted by ektasrv View Post
    I cannot see, where have you assigned value to variable valuetwo?
    try
    float result = Float.parseFloat(valueone) + Float.parseFloat(txt.getText());
    Thank u ekta with ur suggestion am able to perform + and * operations but for -and / the value that is coming is wrong..............................
    if (operand.equals("="))
    {

    if (operation.equals("-"))
    {
    float result = Float.parseFloat(valueone)- Float.parseFloat(txt.getText());
    resetCalculator();
    valueone = "" + result;
    txt.setText(String.valueOf(result));
    }

    if (operation.equals("/"))
    {
    float result = Float.parseFloat(valueone)/ Float.parseFloat(txt.getText());
    resetCalculator();
    valueone = "" + result;
    txt.setText(String.valueOf(result));
    }
    }

  7. #7
    Registered User
    Join Date
    May 2010
    Posts
    214

    Re: doubt in lwuit project

    Quote Originally Posted by ektasrv View Post
    I cannot see, where have you assigned value to variable valuetwo?
    try
    float result = Float.parseFloat(valueone) + Float.parseFloat(txt.getText());


    can u tell me how to get the new value when an operation is pressed ................the value is keep on coming continuesly

  8. #8
    Registered User
    Join Date
    Oct 2009
    Location
    Noida
    Posts
    941

    Re: doubt in lwuit project

    Quote Originally Posted by kumarv75 View Post
    can u tell me how to get the new value when an operation is pressed ................the value is keep on coming continuesly
    you get the new value from the Text box after the = operator is pressed by txt.getText().
    If this works in + & *, it should also work in - or /, just check with a SOP that txt.getText() is not null or "".
    Thanks,
    Ekta

  9. #9
    Registered User
    Join Date
    May 2010
    Posts
    214

    Re: doubt in lwuit project

    Quote Originally Posted by ektasrv View Post
    you get the new value from the Text box after the = operator is pressed by txt.getText().
    If this works in + & *, it should also work in - or /, just check with a SOP that txt.getText() is not null or "".
    I am able to perform all the operations with valuetwo itself but am able to get the answer only if I click the = symbol ..................say if its 2+3+2+......... the result is not coming and it is coming continuesly .........................this is a bug that am facing now

  10. #10
    Registered User
    Join Date
    Oct 2009
    Location
    Noida
    Posts
    941

    Re: doubt in lwuit project

    Quote Originally Posted by kumarv75 View Post
    I am able to perform all the operations with valuetwo itself but am able to get the answer only if I click the = symbol ..................say if its 2+3+2+......... the result is not coming and it is coming continuesly .........................this is a bug that am facing now
    This is happening because you workout the result only when (operand.equals("=")) { }, you also need to do this if the operand =operation
    so modify it to:

    if (operand.equals("=") || operand.equals(operation)) {

    // perform all operations
    }
    Thanks,
    Ekta

  11. #11
    Registered User
    Join Date
    May 2010
    Posts
    214

    Re: doubt in lwuit project

    Quote Originally Posted by ektasrv View Post
    This is happening because you workout the result only when (operand.equals("=")) { }, you also need to do this if the operand =operation
    so modify it to:

    if (operand.equals("=") || operand.equals(operation)) {

    // perform all operations
    }
    hi even thn am not able to get .............

    if (operand.equals("=") || (operand.equals(operation)))
    {
    valuetwo = txt.getText();

    if (operation.equals("+"))
    {
    float result = Float.parseFloat(valueone)+ Float.parseFloat(valuetwo);
    valueone = ""+ result;
    resetCalculator();
    txt.setText(String.valueOf(result));
    }

  12. #12
    Registered User
    Join Date
    Oct 2009
    Location
    Noida
    Posts
    941

    Re: doubt in lwuit project

    Put a few SOP to see the flow is reaching here or not.
    Quote Originally Posted by kumarv75 View Post
    hi even thn am not able to get .............


    System.out.println("I am here");
    if (operand.equals("=") || (operand.equals(operation)))
    {
    System.out.println("I am here: 1");
    valuetwo = txt.getText();
    System.out.println("I am here: 2 - valuetwo "+valuetwo );
    if (operation.equals("+"))
    {
    System.out.println("I am here: inside +");
    float result = Float.parseFloat(valueone)+ Float.parseFloat(valuetwo);
    valueone = ""+ result;
    resetCalculator();
    txt.setText(String.valueOf(result));
    }
    Thanks,
    Ekta

  13. #13
    Registered User
    Join Date
    May 2010
    Posts
    214

    Re: doubt in lwuit project

    Quote Originally Posted by ektasrv View Post
    Put a few SOP to see the flow is reaching here or not.
    HI am able to get the result now but its continues in the sense say 1+1+1 it gives 13 it give the last entered value with the result ....................

  14. #14
    Registered User
    Join Date
    Oct 2009
    Location
    Noida
    Posts
    941

    Re: doubt in lwuit project

    Quote Originally Posted by kumarv75 View Post
    HI am able to get the result now but its continues in the sense say 1+1+1 it gives 13 it give the last entered value with the result ....................
    try to put txt.setText(" "); before
    txt.setText(String.valueOf(result));
    Thanks,
    Ekta

  15. #15
    Registered User
    Join Date
    May 2010
    Posts
    214

    Re: doubt in lwuit project

    Quote Originally Posted by ektasrv View Post
    try to put txt.setText(" "); before
    txt.setText(String.valueOf(result));
    Hi I am getting an exeception now while evaluating the condition if (operand.equals("=")|| (operand.equals(operation)))

Similar Threads

  1. Calculator doubt in lwuit
    By kumarv75 in forum Mobile Java General
    Replies: 8
    Last Post: 2010-06-12, 05:56
  2. doubt in lwuit
    By kumarv75 in forum Mobile Java General
    Replies: 6
    Last Post: 2010-06-09, 05:06
  3. doubt in lwuit
    By kumarv75 in forum Mobile Java General
    Replies: 5
    Last Post: 2010-06-08, 11:07
  4. How can I convert easily from Visual Studio 2008 project to Symbian project?
    By K.John in forum Series 40 & S60 Platform Feedback Archive
    Replies: 2
    Last Post: 2009-08-17, 14:01
  5. How to link a C++ project and symbian OS project in carbide??
    By Adrian99420 in forum Symbian User Interface
    Replies: 0
    Last Post: 2008-02-29, 03:29

Posting Permissions

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