Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Close JFrame with a button?

Status
Not open for further replies.

tikoze

Programmer
Jun 6, 2005
4
0
0
US
I have a JFrame with a JButton that is supposed to terminate the program when pressed... What is the code to do that?
 
Assuming you've subclassed JFrame, then something like :-
Code:
JButton btn = new JButton("Terminate");
btn.addActionListener( new ActionListener(){
  public void actionPerformed(ActionEvent e){
    closeApplication();
  }
}

Code:
private void closeApplication(){
  dispose();
}

Tim
---------------------------
"Your morbid fear of losing,
destroys the lives you're using." - Ozzy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top