Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Creating a Frame 
 

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.

                         

» View all related tutorials
Related Tags: c ide class interface sed color 2d vi pattern int line id ai rad show if ie gradient paint to

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

14 comments so far (
post your own) View All Comments Latest 10 Comments:

i want to learnhow to insert textbox into a frame

Posted by anil on Thursday, 04.9.09 @ 14:53pm | #86683

How to set Frame component Orientation and Change frame default color that is blue to orange... pls help me...

Posted by ahmad ashraf azman on Monday, 04.6.09 @ 16:19pm | #86552

may i have a fvor to all user's and programmers.... that i badly needed a java installer for macintosh os...!

Posted by sansoa on Monday, 09.29.08 @ 13:08pm | #80768

1 ) how to declare the variable static and acess them.

2) how to send data from one frame to another.

Posted by sanjana on Wednesday, 04.30.08 @ 16:06pm | #58216

Regarding Has Map.

Posted by Ramesh on Saturday, 03.1.08 @ 14:59pm | #50843

i have created the GUI using netbeans.But when project is run only the main window is displayed and none of the components in it are shown.How to connect Main.java and NewJFrame1.java in netbeans?

Posted by ramya on Friday, 02.29.08 @ 23:30pm | #50762

how to divide a frame in swings if so provide me some examples as soon as possible and tell me the way to know the key words of swings

Posted by uma on Saturday, 02.16.08 @ 17:00pm | #48583

I have created a main frame with 2 buttons, New and Close All. When New is clicked, a new frame is to be created titled Frame 1. Subsequent clicks of New will create additional frames, Frame 2, Frame 3, etc. When Close All is clicked in my main frame, all Frame n's are to close. I'm new to Java Swing and cannot seem to find an example on how to perform this in code? I see stuff on internal frames, but that is not what I am attempting to do. Can you help?

Posted by J. Beaumont on Wednesday, 05.30.07 @ 07:50am | #17703

How to use HashMap with Swings to retrieve data from database

Posted by Ashish Kumar on Friday, 04.20.07 @ 15:50pm | #14623

Hi,
P.Rajeswari!
I receive your problem for creating menus in the frame. Don’t worry; Pease, click the following link and get the creation process and description to menus or submenus in the frame.

Create menus and submenus

Vinod kumar
(RoseIndia.net)

Posted by vinod kumar on Friday, 04.13.07 @ 18:02pm | #14108

Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.