The code creates a window "Code sake" of 300 pixels by 300 pixels. The window won´t be visible until we call setVisible(true). If we don´t include the last line "frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)", when we close the window the program won´t finish and will continue running.
package code.sake.window; import javax.swing.JFrame; public class Game { public static void main(String[] args) { JFrame frame = new JFrame("Code sake"); frame.setSize(300, 300); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } }
If we run it we will obtain:
0 comments:
Post a Comment