Java program to print Hello World on a frame
KW.java
import javax.swing.*;
class KW
{
    public static void main(String args[])
    {
        JPanel p=new JPanel();
        JLabel l1=new JLabel("Hello, World!");
        JLabel l2=new JLabel("Welcome to Kodingwindow!");
        p.add(l1);
        p.add(l2);
        JFrame f=new JFrame("Frame");
        f.setContentPane(p);
        f.setSize(300,300);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setVisible(true);
    }
}
Output
kodingwindow@kw:~$ javac KW.java
kodingwindow@kw:~$ java KW
Advertisement