Jump to content
  • Advertisement
Sign in to follow this  
johnnyBravo

Java, creating a listener for a button question

This topic is 4840 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, a while ago I remember in java of creating a listener from just a function, eg instead of: button.addActionListener(new Button_Listener()); and having the seperate class: class Button_Listener implements ActionListener { Button_Listener() { } public void actionPerformed(ActionEvent e) { //do something } } I remember just being able to set a function or something within the current class that the button is residing in. Does anyone know anything about this? Or am I remembering things wrong? Its been a year and a half since I've really touched java so my memory is a lil bit faded. Thanks

Share this post


Link to post
Share on other sites
Advertisement
You are probably referring to anonymous classes:


button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
//do something
}
});




Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!