Skip to content

Instantly share code, notes, and snippets.

@janbiasi
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save janbiasi/b08759f07488356fe7e5 to your computer and use it in GitHub Desktop.
Save janbiasi/b08759f07488356fe7e5 to your computer and use it in GitHub Desktop.
Simple eventhandling for frames and so on in java
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
class MyFrame extends JFrame {
private JFrame reference = this;
JButton myButton = new JButton();
myButton.setText("Exit Applcation ...");
/* Add listener for the button to close */
myButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ev) {
reference.dispose();
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment