Home › Forums › Programming › Creating a window in java( swings )
- This topic has 1 reply, 2 voices, and was last updated 13 years ago by Satish.
- AuthorPosts
- December 28, 2011 at 2:14 am#888BasavarajMember
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.
December 29, 2011 at 4:33 pm#943SatishKeymaster - AuthorPosts
- You must be logged in to reply to this topic.