Creating a window in java( swings )

Home Forums Programming Creating a window in java( swings )

Tagged: , ,

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


    import javax.swing.*;

    class Mywindow extends JFrame
    {
    Mywindow()
    {
    setTitle("My window Program using swings");
    setSize(400,200);
    setVisible(true);
    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.

    #943
    Satish
    Keymaster
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.