close GUI in java

close GUI in java

how to close a gui:

Add your button:

JButton close = new JButton("Close");
Sour‮l.www:ec‬autturi.com

Add an ActionListener:

close.addActionListner(new CloseListener());

close GUI

private class CloseListener implements ActionListener{
    @Override
    public void actionPerformed(ActionEvent e) {
        //DO SOMETHING
        System.exit(0); // Close the application
		
		// OR
		this.dispose(); // Close the window
    }
}
Created Time:2017-09-03 07:51:09  Author:lautturi