Hello World Program Using SWING

hello friends Today I am discussing about Hello world program using swing
let look below is the program codes
import javax.swing.jFrame;
import javax.swing.JLabel;

public final class hello World extends JFrame
           private Hello World()
           super(“Hello, World”);
           getContentPanel().add(new JLabel(“Hello, World”));
         public static void main(String[] args)
         new HelloWorld().setVisible(true);

now let understand this program
Firstly the constructor of super class is called to set the window’s title as “Hello, World!”.
Swing has its own dispatch thread, which is distinct from the main JVM thread.
         This means that even if the thread exited main method the swing GUI thread world still be running waiting to reponds to user input etc and if the user closes the window then the program would continew to run .Previously we typically attached a window’s listener to our main Jframe and on windowsClosing() event notification callback we would explicitly call System.exit(stat) or some other nastiness.This is the new way of defining default close behavior for a JFrame .The following will merely dipose the JFrame but it will not stop the application

the following stops the application on window close(it is commented out.)

Jframe which is the window component of swing, has an intesering feature it has a layered content architecture which allows for  placement of a component of the JFrame in a designated layer .The layers can be conceptually viewed as a seried of transparencies placed one above another in a overhead projector Swing.

pack( ) tells the receiving container (here this Jframe) for it to optimally pack its components according to its layout

For further knowledge Use can see CLICK HERE

enjoy…keep visiting

Add a Comment

Your email address will not be published. Required fields are marked *