Write a java program to print "Hello World" using swing package.

The simplest way to create a graphical window in Java is to have an option pane pop up. An option pane is a simple message box that appears on the screen and presents a message or a request for input to the user. The Java class used to show option panes is called JOptionPane. JOptionPane belongs to the javax.swing package, so you’ll need to import this package to use it. (“Swing” is the name of one of Java’s GUI libraries.) Note that the package name starts with javax this time, not java. The x is because, in Java’s early days, Swing was an extension to Java’s feature set.

JOptionPane can be thought of as a rough graphical equivalent of System.out.println output and Scanner console input. The following program creates a “Hello, world!” message on the screen with the use of JOptionPane:

Program :


import javax.swing.*;

public class HelloWorld 
{
public static void main(String[] args) 
{
JOptionPane.showMessageDialog(null, "Hello, world!");
}

}

Output :



Post a Comment

0 Comments