//For creating a Frame
JFrame testFrame = new JFrame("This is a test Frame");
//Set Size of the Frame
testFrame.setSize(400, 400);
//If you set this property as "False", the Frame will be created but hidden in UI.
testFrame.setVisible(true);
//This is the most important line in your code:
//Use only one of the following based on the requirement:
//If you have several JFrames open using EXIT_ON_CLOSE closes all the JFrames and exits the app
testFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//If you use DISPOSE_ON_CLOSE, only that JFrame will be closed
testFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);