jQuery in Action, 3rd edition
The moose likes Swing / AWT / SWT and the fly likes Real Time Applet Design Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Real Time Applet Design" Watch "Real Time Applet Design" New topic

Real Time Applet Design

Firdos Ali

Joined: Jan 21, 2005
Posts: 1
I need help with the design of my applet. It is a financial applet and it has several text boxes. I need to be able to gather information from the text boxes and display the results. The problem is that whenever a textbox value changes I want to update my total. Because there are so many text boxes it would be very difficult to maintain if I was to create an ActionListener class for each one of them, so I wanted a way to implement a Listener that would listen or wait for the text boxes to change and then automatically update itself. How do I implement such a thing and if you could provide some examples I would really appreciate it. Thank You in advance
Alexandru Popescu
Ranch Hand

Joined: Jul 12, 2004
Posts: 995
You can reuse a single ActionListener for all your textfields. Than retrieve the info (using ((JTextField) actionEvent.getSource()).getText()) and than update the total value. (the tricky part would be the part when you really compute the total,as you would need to know the previous value ).

Another option is to make your computation on focus lost event (same mechanism as above).

[ January 21, 2005: Message edited by: Ali Pope ]

blog - InfoQ.com
I agree. Here's the link: http://aspose.com/file-tools
subject: Real Time Applet Design
It's not a secret anymore!