MathBits.com
Return to Unit Menu | Java Main Page | MathBits.com | Terms of Use 

Controlling the Window

The GBFrame
With the use of the GBFrame, BreezyGUI can create windows that hold buttons, input and output boxes, and more.  The window will show up as a "drop down" on your screen like the window seen at the left.

To create a GUI style window, you will add control items to your GBFrame such as input/output boxes (called fields), labels, buttons and more.

You control the layout of a window by imagining a grid superimposed over the window.  The grid can contain as many cells as needed.

While most controls occupy only one cell, it is possible for a control to span several cells.  In this window, the "Compute Ounces" button spans cells (3,1) and (3,2).

Types of Objects:

LabelThese are "words" telling the user what is needed.  Used to explain the purpose of the window.

IntegerFieldCreates the entry box for the user to input integer values.  If the user enters nonnumeric or floating-point data in an integer field box, the program will automatically convert the value to a 0.

DoubleFieldCreates the entry box for the user to input double values.  If the user enters nonnumeric data in a double field box, the program will automatically convert it to a 0.

ButtonCreates the button telling the program to perform some process.

To create a window, simply indicate the position of the objects you wish to use.  The grid will automatically adjust itself to the needed number of rows and columns.  The correct syntax is:

<type of object> <name> = <addType> (<initial value>, <row#>, <column#>,<width>,<height>);

Format:

Label <name> = addLabel (".....",r,c,w,h);

IntegerField <name> = addIntegerField(<integer>,r,c,w,h);

DoubleField <name> = addDoubleField(<double>,r,c,w,h);

Button <name> = addButton (".....",r,c,w,h);
 

r, c:   <row#>,<column#>
This is the location of the control as designated by the top left corner of the cell.

w, h:  <width>,<height>
This is the number of horizontal and vertical cells occupied by the control. 

 

Let's Examine our Ounces/Pounds Program:
 

//Sample Program
//Using BreezyGUI

import java.awt.*;
import BreezyGUI.*;

public class OuncesPounds extends GBFrame
{
     Label poundsLabel = addLabel ("Pounds",1,1,1,1);
     Label ouncesLabel = addLabel ("Ounces",2,1,1,1);

     DoubleField poundsField = addDoubleField (0 ,1,2,1,1);
     DoubleField ouncesField = addDoubleField (0 ,2,2,1,1);

     Button poundsButton = addButton ("Compute Pounds",3,1,1,1);
     Button ouncesButton = addButton ("Compute Ounces", 3,2,1,1);

     public void buttonClicked (Button buttonObj)
     {
          double pounds, ounces;
          if (buttonObj == ouncesButton)
          {
                pounds = poundsField.getNumber();
                ounces = 16 * pounds;
                ouncesField.setNumber(ounces);
                ouncesField.setPrecision(2);
          }
         else
         {
                ounces = ouncesField.getNumber();
                pounds=ounces/16;
                poundsField.setNumber(pounds);
                poundsField.setPrecision(2);
         }
      }

     public static void main (String[ ] args)
     {
          Frame frm = new OuncesPounds ();
          frm.setSize (250, 150);
          frm.setVisible (true);
     }
}
 



Return to Unit Menu | Java Main Page | MathBits.com | Terms of Use