Results 1 to 2 of 2
  1. #1
    marylanddem is offline Member
    Join Date
    Nov 2010
    Posts
    6
    Rep Power
    0

    Default Getting Backspace on a java calculator program to work

    The following code is for a java calculator program. The code compiles, but I can't get the backspace button to work.

    This is the code that calls for the backspace function:

    if(i==18)
    { if(lcd.getText().length()<=1)
    op1 = (lcd.getText().length() - 1);

    }

    The code for the calculator is attached. Any insight on how to get the backspace to work?
    Attached Files Attached Files

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    I can't get the backspace button to work.

    What does "work" mean? In particular what was the intention of this line:

    Java Code:
    op1 = (lcd.getText().length() - 1);

    I only glanced at you code, but op1 seems to be a double value (representing the first operand of a calculation?), but in this line you are setting it equal to one less than the length of a string. It's hard to see why.

    ----------------------

    Also I noticed code like

    Java Code:
    String arg = e.getActionCommand();
    if (arg == "Exit")

    just before you switch on the index of the source widget within the keys array. It is a good idea to use the string method equals() to compare strings. == tests for string identity rather than equality in the sense of being made up of the same characters in the same order.

Similar Threads

  1. ignore backspace
    By Kyle227 in forum New To Java
    Replies: 6
    Last Post: 05-16-2010, 09:34 PM
  2. Calculator program
    By kevzspeare in forum New To Java
    Replies: 6
    Last Post: 03-18-2009, 01:43 PM
  3. Calculator Program HELP NEEDED FAST! Homework assignment
    By SteroidalPsycho in forum New To Java
    Replies: 3
    Last Post: 03-05-2009, 04:02 AM
  4. unreachable statement - Java calculator program
    By V2001Gordon in forum New To Java
    Replies: 3
    Last Post: 12-13-2008, 12:57 AM

Posting Permissions

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