Creating Simple Window in Java: using swings

Advertisement:


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



YouTube Link: http://www.youtube.com/watch?v=7ThtNST8gKE [Watch the Video In Full Screen.]



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:
window swing java Creating Simple Window in Java: using swings


Related posts:







Get FREE blog updates to your email inbox. Enter your email ID and subscribe:


Do not forget to click the verification link in your email, after subscribing.
--Thanks for your support

Start Making Money From Your Programming Skills


( Free ebook )
ebook cover
  • 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..

One Response to “Creating Simple Window in Java: using swings”

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

Leave a Reply