[Java] // instance 1: directly define the Jframe class object to create a window package jFrame; import javax. swing. *; // to use the Swing class, you must introduce the Swing package public class JFrameDemo1 {public static void main (String args []) {// define a form object f, the form name is "a simple window" JFrame f = new JFrame (); f. setTitle ("instance 1: A simple window"); // you can specify the text in the title bar f. setLocationRelativeTo (null); // center the form to f. setSize (300,200); // set the size of the form to 300*200. setResizable (false); // sets whether the form can be adjusted. The parameter is a Boolean value. // sets the form to be visible. Without this statement, the form is invisible. This statement must exist, otherwise, f. setVisible (true); // The operation performed by the program when the user clicks the close button of the window. setdefaclocloseoperation (JFrame. EXIT_ON_CLOSE); // close the window when the user clicks} [java // instance 2: Create class inherits JFrame class to create a window package JFrameDemo2; import javax. swing. *; // create a subclass MyFrame to inherit the parent class JFrame class MyFrame extends JFrame {// define the constructor without the MyFrame () {setLocationRelativeTo (null) parameter ); // set setTitle ("instance 1: A simple window") in the center of the form; // set the text setSize (300,200) in the title bar of the window ); // set the size of the form to 300*200. setResizable (false); // set whether the form can be adjusted. The parameter is a Boolean value of setVisible (true ); // set whether the form size can be adjusted. The parameter is a Boolean value setDefaultCloseOperation (EXIT_ON_CLOSE); // close the window when the user clicks} public class JFrameDemo2 {public static void main (String args []) {// instantiate a class object, prompting to set the parameter MyFrame f = new MyFrame () ;}} [java] // instance 3: No constructor is used, and the method can be the same as that of the instance, the code can be changed to the following mode: package JFrameDemo3; import javax. swing. *; class MyFrame extends JFrame {MyFrame () {}} public class JframeDemo3 {public static void main (String args []) {MyFrame f = new MyFrame (); f. setTitle ("instance 1: A simple window"); // you can specify the text in the title bar f. setLocationRelativeTo (null); // center the form to f. setSize (300,200); // set the size of the form to 300*200. setResizable (false); // sets whether the form can be adjusted. The parameter is a Boolean value. // sets the form to be visible. Without this statement, the form is invisible. This statement must exist, otherwise, f. setVisible (true); // The operation performed by the program when the user clicks the close button of the window. setdefaclocloseoperation (JFrame. EXIT_ON_CLOSE); // close the window when the user clicks }}