Home Search Contact us About us
Title Base for a frame project.
Summary Use this simple code to form the base of a frame project. There is nothing special just the frame and a handler for the close event.
Contributor John McTainsh
Published 4-Nov-2000
Last updated 4-Nov-2000
Page rating   Be the first to rate this page! Useless Brilliant

Description.

Every application needs to start somewhere so here is the frame work for the simplest window application. It creates a main window with a title bar.

How it does this.

The main functions creates an instance of a Frame derived class ColourCode. initFrame is called to create and display the window. It also adds an event handler to catch requests to close and call exit appropriately.

import java.awt.*;
import java.awt.event.*;

/////////////////////////////////////////////////////////////////////////////
//Class extends the frame class to display the main application frame
public class ColourCode extends Frame
{
    /////////////////////////////////////////////////////////////////////////
    //Application starts here
    public static void main (String[] args)
    {
        ColourCode frame = new ColourCode();
        frame.initFrame();
    }
        
    /////////////////////////////////////////////////////////////////////////
    //Setup the Main window
    private void initFrame()
    {
        //Add an anonymous event handler to shut down on exit
        addWindowListener( new WindowAdapter()
            {
                public void windowClosing( WindowEvent ew )
                {
                    System.exit( 0 );
                }
            } );
        
        //Set the window Size and title
        setTitle( "Code to Colour HTML" );
        setSize( 400, 200 );
        setVisible( true );
    }
}
Comments Date
Home Search Contact us About us