The Application Window and Its Attributes

 

The next example is a GUI-based hello world program, which uses black text on a red background: 

 

Note that the window's zoom disk is gray, meaning the window cannot be resized. Here is the code for the program:

   

import javax.swing.*;

import BreezySwing.*;

import java.awt.Color;

 

public class HelloWorld extends GBFrame{

 

    // Set up the greting label by adding it to a row and column in the window's grid

    JLabel greetingLabel = addLabel ("Hello world!", 1, 1, 1, 1);

 

    // Create and display the window when the app launches

    public static void main(String[] args){

        JFrame frm = new HelloWorld();

        frm.setSize (100, 100);

        frm.setResizable (false);

        frm.setBackground (Color.red);

        frm.setVisible (true);

    }

}

 

  The window's size, resizability, and color are set in the main method, by running methods on the window named frm. Note that you must set the windowÕs size, or you will see only the title bar at program startup. If you do not set the window's title, its default title is the empty string.

 

 

Back to tutorial Next topic: Adding window components