Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

renewing items in Applet

 
Gary Down
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How should I approach this?
I am iterating through a Treeset which contains variable numbers of objects, each containing a known number of items.

The update and redisplay works but.......
How do I detect which row the button (once clicked) belongs to so I can apply the update to the correct object in the Treeset?

Thanks,
Top.

NOTE: the result = shoppingCart.AddItemToCart.....
and result = shoppingCart.UpdateItemInCart("AA", 20); are temporary, only for testing purposes and will be remover later

 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello "Top Down"-

Welcome to JavaRanch.

On your way in you may have missed that we have a policy on screen names here at JavaRanch. Basically, it must consist of a first name, a space, and a last name, and not be obviously fictitious. Since yours does not conform with it, please take a moment to change it, which you can do right here.

As to your question, one way would be to make that information part of the action command. Instead of all buttons having "Change", they could have "Change-AA", "Change-BB" etc. Be sure to use something unique that also makes it easy to find the correct data in your data structures.

In that case the line "evt.getActionCommand().equals("Change"))" would become "evt.getActionCommand().startWith("Change")).
 
Gary Down
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf,
Thanks for the idea...it didn't directly fix it but certainly aimed me in a different direction of thinking. I eliminated the button altogether and moved the listener to the itemCount. Now all I need to do is force the input to be numeric (which I believe can be done by extending the TextField class)
Any comment/suggestion is welcome.

PS.. I changed my name, however my surname is Down and I've been called Top for most of my life (some bizarre nickname my father hung on me). Gary will do fine.

Cheers,
Gary

 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're using Swing, then this might be what you're looking for: http://faq.javaranch.com/java/NumericTextField
 
Gary Down
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks again Ulf,
you've helped in getting me in the right direction.

I have ended up with the code below. Any comments are welcomed (eg. anything I should be wary off in the code) :-
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic