PackageCn.jerry;ImportJavax.swing.JFrame;ImportJavax.swing.JPanel;/** Popular components of swing*/ Public classComponent {PrivateJFrame frame;//Window Layout//A panel is a container that can honor other swing components in the PrivateJPanel Panel;//Panel /*** Initialization of the interface * *@paramargs*/ Private voidXianshi () {//TODO auto-generated Method Stubframe =NewJFrame ("Swing Common components"); Panel=NewJPanel (); //adding components to the interface displayFrame.setsize (800, 700);//set the size of the windowFrame.setlocationrelativeto (NULL);//The Settings window appears in the middleFrame.add (panel);//Add PanelFrame.setvisible (true);//Display of WindowsFrame.setdefaultcloseoperation (Jframe.exit_on_close);//window Close } Public Static voidMain (string[] args) {NewComponent (). Xianshi (); }}
Java Display window