Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question on Action Listeners

 
Ryan Maxwell
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey!

Quick question on action listeners...

I have a program that starts with a main frame and then creates new frames as buttons are pressed. Is it possible to set an action listener that will cause the main frame to respond to button presses within the created frames?

-Thanks!
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure. Just use a reference to the main frame as the action listener as long as it implements ActionListener.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Saint Apathy,"

Welcome to JavaRanch!

Please revise your display name to meet the JavaRanch Naming Policy. To maintain the friendly atmosphere here at the ranch, we like folks to use real (or at least real-looking) names.

You can edit your name here.

Thank you for your prompt attention, and enjoy the ranch!

-Marc
 
Ryan Maxwell
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, thanks!
What do you mean a reference to the main frame?
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well you have to send a reference to an ActionListener to the method setActionListener.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ryan Maxwell:
... What do you mean a reference to the main frame?

I think Keith is suggesting something like this: Suppose you define a class MainFrame that extends JFrame and implements ActionListener. Then...

(Thanks for changing your display name so quickly!)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic