• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

isnt this code a little "obtuse" ?

 
William Quantrill
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im working my way through wrox press beginning java 1.4 and this example on event handling jsut seems a little "over done". maybe im just not to the section on using anonymouse inner classes yet, but doesnt the use of the HandleControlButton class seem a little odd. i mean, instead of using using an integer to figure out which button was clicked, why not jsut use anonymouse inner classes and handle the event for each button. they do that later in the book, but im just wondering if anyone ever really handles events in this fashion other than in a book to show the use of this...


[I disabled smilies so that the ;) in the loops doesn't convert to a smily. - Jim]
[ January 30, 2003: Message edited by: Jim Yingst ]
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i mean, instead of using using an integer to figure out which button was clicked, why not jsut use anonymouse inner classes and handle the event for each button. they do that later in the book, but im just wondering if anyone ever really handles events in this fashion other than in a book to show the use of this...
Sometimes, sure. For example if I'm making a calculator GUI, I might have ten buttons for digits 0-9. I could make ten different anonymous classes to handle them, but I'd probably rather just make one class that handles all the buttons. For most GUI projects I'd make a separate listener for each button, but if the buttons are reasonably similar in function, and/or there's a lot of them, I'll make a single listener.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic