Link to home
Start Free TrialLog in
Avatar of nbham29
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
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

What would activate getting the total?
Avatar of nbham29
nbham29

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
Avatar of nbham29

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
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of nbham29

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

Avatar of nbham29

ASKER

label.setText(Integer.toString(total + value));
will this portion work with a double
You need

label.setText(Double.toString(total + value)); 

Open in new window

> label.setText(Integer.toString(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

nbham29, could  you post for the benefit of future visitors, how you used a DocumentListener?