Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Java Example Java Swing Creating a Frame

Related Tutorials


 
 

Share on Google+Share on Google+

Creating a Frame

Advertisement
This program shows you how to create a frame in Java Swing Application.

Creating a Frame : Swing Tutorials

     

This program shows you how to create a frame in Java Swing Application. The frame in java works like the main window where your components (controls) are added to develop an application. In the Java Swing, top-level windows are represented by the JFrame class. Java supports the look and feel and decoration for the frame. 

For creating java standalone application you must provide GUI for a user. The most common way of creating a frame is, using single argument constructor of the JFrame class. The argument of the constructor is the title of the window or frame. Other user interface are added by constructing and adding it to the container one by one. The frame initially are not visible and to make it visible the setVisible(true) function is called passing the boolean value true. The close button of the frame by default performs the hide operation for the JFrame. In this example we have changed this behavior to window close operation by setting the setDefaultCloseOperation() to EXIT_ON_CLOSE value.

setSize (400, 400):
Above method sets the size of the frame or window to width (400) and height (400) pixels.

setVisible(true):
Above method makes the window visible.

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE):
Above code sets the operation of close operation to Exit the application using the System exit method.

Here is the code of the program : 

import javax.swing.*;

public class Swing_Create_Frame{
  public static void main(String[] args){
  JFrame frame = new JFrame("Frame in Java Swing");
  frame.setSize(400400);
  frame.setVisible(true);
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  }
}

Download this example.

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: April 14, 2007

Related Tutorials

Discuss: Creating a Frame   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:19
suresh
July 12, 2012
studies

java work into jobs company site
ajay
July 23, 2012
how to learn java programs?

java programming language is easy or hard can you explain me with examples in my email id?
fadlhee
August 9, 2012
you

nice code but too easy!
mohsen
August 16, 2012
how can i debug this code

hi. my name is mohsen.i'm from iran.i want to study java programming.i'm new.how can i debug this code.it dosen't work(i use NetBeans IDE 7.1.2) tanks.i'm wating
mohsen
August 16, 2012
i need help so

hi. my name is mohsen.i'm from iran.i want to study java programming.i'm new. how can i debug this code.it dosen't work(i use NetBeans IDE 7.1.2) tanks
mohsen
August 16, 2012
i need help so

hi. my name is mohsen.i'm from iran.i want to study java programming.i'm new. how can i debug this code.it dosen't work(i use NetBeans IDE 7.1.2) tanks
pedro
August 23, 2012
me myself and i

i dont like your freaking codes! its just to easy! Even 4 years old child and below can also do that!
vijayakumar.s
September 24, 2012
java

i can have more thing in frames
TOPIK
June 20, 2013
Tiw tiw tiw

How to Make Frames (Main Windows)
DMCA.com