Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Beginning Java and the fly likes isnt this code a little Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "isnt this code a little "obtuse" ?" Watch "isnt this code a little "obtuse" ?" New topic
Author

isnt this code a little "obtuse" ?

William Quantrill
Ranch Hand

Joined: Dec 23, 2002
Posts: 36
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 ]

"The Rebel army is now the legitimate property of the Army of the Potomac." - Joseph Hooker spoke these pompous words shortly before he was soundly defeated by Robert E. Lee at Chancellorsville
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
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.


"I'm not back." - Bill Harding, Twister
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: isnt this code a little "obtuse" ?
 
Similar Threads
Help.
Won't repaint!
Layout Managers and preferred size