Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Spring Framework | Web Services | BioInformatics | Java Server Faces | Jboss 3.0 tutorial | Hibernate 3.0 | XML
 
 
Hot Web Programming Job

 

Tutorial Categories: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML

[an error occurred while processing this directive]

Java Notes

Example - Tiny Window

A very small window The image on the left is the window in its "natural" size. There's nothing in the window so it shrinks down to almost nothing. Because the default position is in the upper left corner of the screen, it may be hard to even see that it's running.

The basic window (JFrame) has controls that work, with the exception of the close box which you must indicate should stop the program as in the program below. You can iconify it, and resize it. The image on the right is what you get if you drag the lower-right corner to enlarge the window. The content pane is just a plain background with nothing on it.

A very small window
  1 
  2 
  3 
  4 
  5 
  6 
  7 
  8 
  9 
 10 
 11 
 12 
 13 
 14 
 15 
 16 
 17 
 18 
 19 
//--- intro-windows/TinyWindow.java - Creates a very small window!
//    This is just about the smallest GUI program you can write.
//    It does nothing, but you can see that the close box works
//    and the window can be resized.
//    Fred Swartz 2004-10-28

import javax.swing.*;                                           //Note 1

////////////////////////////////////////////////////// class TinyWindow
class TinyWindow {
    // ===================================================== method main
    public static void main(String[] args) {
        JFrame window;                                          //Note 2
        window = new JFrame();                                  //Note 3
        window.setTitle("Tiny Window");                         //Note 4
        window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  //Note 5
        window.setVisible(true);                                //Note 6
    }
}

Notes



Note 1: This import statement gets all of the Swing classes, altho we are only using JFrame here. Normally there will be a couple of other imports to get the rest of the common GUI classes.

Note 2: Our common idea of "window" is implemented by the JFrame class.

Note 3: Create a JFrame object..

Note 4: Set the text on the title bar.

Note 5: Makes the application quit when the close box is clicked.

Note 6: After everything is ready, display the window on the screen. This also starts a separate thread to monitor the user interface. Note that System.exit(0) is not called; we don't want to terminate the program. The typical GUI program builds the user interface, then just waits until the user does something.

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

0 comments so far (
post your own) View All Comments Latest 10 Comments:
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification

Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

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

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

Copyright © 2007. All rights reserved.