JFrame.DISPOSE_ON_CLOSE
- JFrame.DISPOSE_ON_CLOSE
- JFrame EXIT_ON_CLOSE.
- JFrame HIDE_ON_CLOSE.
- JFrame DO_NOTHING_ON_CLOSE.
Apart from setDefaultCloseOperation,JFrame swing window has various methods.I have previously looked at some of them.Make sure you check out.
JFrame methods.
- [setSize(new Dimension(400,400)]
- [JFrame.setJMenuBar(bar)]
- setSize()
- setVisible()
- setLocationRelativeTo(null)
JFrame.DISPOSE_ON_CLOSE Example
[
import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.JButton; public class JFrameMethods extends JPanel{ JFrameMethods() { JTextField username=new JTextField("Enter Username"); JTextField password=new JTextField("Enter Password"); JButton login=new JButton("Login"); JButton cancel=new JButton("Cancel"); username.setBounds(10, 10, 100, 20); password.setBounds(10, 20, 100, 20); add(username); add(password); add(login); add(cancel); } public static void main(String args[]) { JFrame window=new JFrame("JFrame methods"); window.getContentPane().add(new JFrameMethods()); window.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); window.setLocationRelativeTo(null); window.setSize(400,400); window.setVisible(true); } }
]
Code Explanation:
Above class extends JPanel class.Other swing components you should check out are JTextField and JButton.See also how to implement ActionListener to a JButton
Code[window.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);]-sets JFrame defaultcloseoperation method to exit the application once its clicked.