What's the fastest way to draw a Hello World in Java

后端 未结 3 1913
别跟我提以往
别跟我提以往 2021-01-16 02:38

What\'s the fastest way to draw a Hello World on the screen using a GUI in Java:

1- by using the minimum number of classes.

2- with the leas

相关标签:
3条回答
  • 2021-01-16 02:57

    this is the fastest graphical Hello world i could get.

    public class HelloWorld{
        public static void main(String[] args) {
            javax.swing.JOptionPane.showMessageDialog(null, "Hello World");
        }
    }
    
    0 讨论(0)
  • 2021-01-16 03:06

    The SplashScreen class would be tough to beat as it can display an image even before JVM starts, though I'm not sure if it qualifies for a "GUI".

    With an empty main() (which results in a 370-byte class file with Win XP JDK6), java -splash:helloworld.png <class> (or a jar) would run faster than you can blink.

    Or you can use this trivial class to control how long you'll see the image:

    public class DoNothing
    {
        public static void main(String[] args) throws InterruptedException
        {
            int i = 1000;
            if( args != null && args.length > 0 )
                try{ i = Integer.parseInt(args[0]); }
                catch( NumberFormatException ex ) {} 
            Thread.sleep(i);
        }
    }
    
    0 讨论(0)
  • 2021-01-16 03:17

    If you're optimizing for runtime then pre-render an image with the text "Helo World" and then use Java to display it as an image. You can use ImageIcon to easily display an image.

    0 讨论(0)
提交回复
热议问题