Creating a window in java( swings )

Home Forums Programming Creating a window in java( swings )

Tagged: , ,

This topic contains 1 reply, has 2 voices, and was last updated by  Satish 5 years, 11 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • #888


    import javax.swing.*;

    class Mywindow extends JFrame
    setTitle("My window Program using swings");
    setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );

    public static void main( String args[] )
    Mywindow m1=new Mywindow();

    This is a simple program to create a window, in java we can design GUI’s( Graphical User Interfaces ) using the concept of swings.

    In this example i have used the class called JFrame which is predefined in the package javax.swing. to use this class we have to write import statement.

    Mywindow is a user defined class which extends( inheritance ) JFrame
    class, by extending the existing JFrame class we can develop our own application that’s what the application of inheritance is.

    1st line i.e Class Mywindow extends JFrame is extending the JFrame class.
    2nd line i.e Mywindow()
    it is constructor here it is used to define the characteristics of the window to be displayed like it’s title,size ( width and height )
    the method setVisible( true ) makes the window to be visible,setDefaultCloseoperation( JFrame.EXIT_ON_CLOSE ) this line is written close the window soon after clicking the cancel button of the window by default it wont get closed.

    inside the main the object has been created by the statement Mywindow m1=new Mywindow() which intern invokes constructor and constructor makes the window to be visible.


Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.