helloworld.java

来自「程序练习中包括书中实例程序代码和练习中要用到的代码,是压缩文件」· Java 代码 · 共 39 行

JAVA
39
字号
package examples.windows;
import javax.swing.JFrame;
import javax.swing.JLabel;
import java.awt.BorderLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
/** An example of a very simple windowed program
  */
public class HelloWorld extends JFrame {
   /** Class constructor
     * @param titleText window's title bar text
     */
   public HelloWorld( String titleText ) {
      super( titleText );
      addWindowListener( new WindowAdapter() {
            /** End the program when the user
              * closes the window
              */
            public void
            windowClosing( WindowEvent e ) {
               HelloWorld.this.dispose();
               System.exit( 0 );
            }
         }
      );
      JLabel greeting = new JLabel( "Hello World!",
                                    JLabel.CENTER );
      getContentPane().add( greeting,
                            BorderLayout.CENTER );
      setSize( 300, 100 );
      setVisible( true );
   }
   /** The test method for the class
     * @param args not used
     */
   public static void main( String[] args ) {
      new HelloWorld( "Hello World! Sample" );
   }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?