Creating Simple Window in Java: using swings
This Java video tutorial demonstrates the creation of a simple window by importing Swings package and extending JFrame class.
import javax.swing.*;
javax.swing provides a set of lightweight components that, to the maximum degree possible, works the same on all platforms.
myWindow Class
class myWindow extends JFrame
{
}myWindow is user the name given to the defined class. extends is the keyword. JFrame is a built-in class of swing package.
Constructor
myWindow()
{
setTitle("My window program, using Swings");
setSize(400, 200);
setVisible( true );
setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
}myWindow() is the constructor, and thus it’s name matches with that of its class name.
setTitle() : To set the string present on the title bar of the window we are creating.
setSize() : To set the size of the window. It takes two parameters, width and height of the window.
setVisible() : It’s very important for all the programs which involves visual components. passing a value of true makes the window visible.
Main method
public static void main(String args[])
{
// new myWindow();
myWindow m1 = new myWindow();
}main method just calls the constructor. We can simply write new myWindow() since we are not at all taking the help of any object here.
Video Tutorial: Creating Simple Window in Java: using swings
Full Source code to create a simple window in Java: using swings
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | 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[])
{
// new myWindow();
myWindow m1 = new myWindow();
}
} |
Output:

Related posts:
- Addition/Subtraction of Complex Number: Java
- First Java Program: Basic
- Using Constructors & Member Function to add two numbers: Java
- Read Keyboard Input: Java
Get FREE blog updates to your email inbox. Enter your email ID and subscribe:
Start Making Money From Your Programming Skills
- Subscribe to Technotip.com blog update and you will be able to download "Tips, Tricks and Strategies to Make Money Online" eBook for free.
- You will also receive tips to improve your programming skills, and strategies to make money from your programming skills. We will also send useful resources for learning and building your application.
- You can also make money with us, by just recommending our website to your friends and family. You will get complete strategy for making $300 and more in the ebook that we will send you - once you subscribe to our free blog update using the below form..


Discussion Forum Thread:
http://technotip.com/forums/to.....va-swings/