Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Design Patterns in UI design of FBN

 
Ashish Sarin
author
Ranch Hand
Posts: 444
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
Presently I'm working on the UI design of the FBN Assignment. In the UI I have provided a button for make the reservations. But the code inside the actionPerformed() method turned out to be very long. Also because I have to use the anonymous inner class as there are number of variables that I have to access in the program. So if I make a seperate action listener in that case I have to pass around 10 parameters to accmplish the reservation. Please tell me which design pattern I should use to get rid of the long code written in the actionPerformed().
TIA,
Ashish Sarin
Systems Engineer
EHPT India Pvt Ltd
 
shilpr
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Ashish,
Have you thought of making your listener an ordinary inner class, not an anonymous inner class ? That way you could still access the instance variables of the class without passing the parameters around.
Or if you wanted to use anonymous classes,how about making a method call in your actionPerformed method, the long code you specified contained in the method being called. That should solve your problem.Hope this is of help.
 
Jerry Pulley
Ranch Hand
Posts: 221
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
shilpr,
That's a good use of an inner class to access member variables and avoid excessive parameter passing. But, please register a valid user name - see the JavaRanch naming policy.
Ashish,
You'll probably want to start a new thread to handle a user action in a Swing (or AWT) program if the code is time consuming. Watch out for the single-thread rule: any code that manipulates the UI must run in the event-dispatch thread. You can handle this with <code>invokeLater()</code>, a method of <code>javax.Swing.SwingUtilities</code> and <code>java.awt.EventQueue</code>.
jply
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic