nbham29
asked on
Java Text listener
I need some assistance finding out how to take information received from a textfield adding the value to a total and displaying it without a button
What would activate getting the total?
If moving away from the field, then see
http://www.exampledepot.com/egs/java.awt.event/FocusEvents.html
http://www.exampledepot.com/egs/java.awt.event/FocusEvents.html
ASKER
I was thinking some kind of listener might activate but I am not sure. All I know is that I wanted it to update a JLabel like a checkbox or a radio button does
ASKER
I have found some code that use a textListener and TextEvent recorded the event everytime something was entered but I don't exactly know how to get that to a variable and add it to total and the label.
How would it know when to stop listening and start acting?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
will this work with combo boxes and radio boxes in the project as well.
A FocusListener will, yes
> will this work with combo boxes and radio boxes in the project as well.
no use an ActionListener for those
no use an ActionListener for those
ASKER
label.setText(Integer.toSt ring(total + value));
will this portion work with a double
will this portion work with a double
You need
label.setText(Double.toString(total + value));
> label.setText(Integer.toSt ring(total + value));
depends, do you want it displayed as a double or as an integer
if you want to display it as a double then see here for how to convert it to a string
http://helpdesk.objects.com.au/java/how-to-format-a-double-as-a-string
let me know if you need any help
depends, do you want it displayed as a double or as an integer
if you want to display it as a double then see here for how to convert it to a string
http://helpdesk.objects.com.au/java/how-to-format-a-double-as-a-string
let me know if you need any help
nbham29, could you post for the benefit of future visitors, how you used a DocumentListener?