Results 1 to 2 of 2
- 12-09-2010, 12:47 AM #1
Member
- Join Date
- Nov 2010
- Posts
- 6
- Rep Power
- 0
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?
- 12-09-2010, 01:01 AM #2
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
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
-
ignore backspace
By Kyle227 in forum New To JavaReplies: 6Last Post: 05-16-2010, 09:34 PM -
Calculator program
By kevzspeare in forum New To JavaReplies: 6Last Post: 03-18-2009, 01:43 PM -
Calculator Program HELP NEEDED FAST! Homework assignment
By SteroidalPsycho in forum New To JavaReplies: 3Last Post: 03-05-2009, 04:02 AM -
unreachable statement - Java calculator program
By V2001Gordon in forum New To JavaReplies: 3Last Post: 12-13-2008, 12:57 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks