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

events.. best practices...

 
KEvin Runion
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I have a JFrame created in the main() method and want to catch events, outside of the JFrame object, what are the best ways to do that. Example being, I have a login screen that pops up and then the user either exits or continues on to run the application. I'd like to begin loading the application from within the main method rather then catching the event in the login frame and creating the instance from within it. Basically I'm trying to figure out how I should go about catching events in a child window without going around my a$$ to get to my elbow.
 
KR Campbell
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not an expert, but here's a couple of possible approaches:

You could define a setup() in your main class which creates a login. Run the login in a thread :



..and wait() in your run() :



until the user presses a button:


The run method will exit only after the actionPerformed() has been triggered, letting setup() complete. This allows your main method to wait for the user to make a decision in the Login class and act accordingly.

Alternatively, treat your main class as an Observer and make login extend Observable. This would require less code but I'm not sure it is a 'proper' use of the pattern. Apologies if there are cleaner approaches. *I'd* appreciate any improvements to this.

Regards,
Ken
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic