As a first illustration of BreezyGUI, we develop a very simple temperature conversion application. This application, whose interface is shown below, can convert Fahrenheit degrees to Centigrade (or Celsius as it is also known) and vice-versa.

For instance, to convert from Centigrade to Fahrenheit, a user enters degrees Centigrade in the second text box and clicks the Convert to Fahrenheit button.
The code for a BreezyGUI application is split between two classes. The first class is very brief and contains only the static method main. Every Java application must start by executing a static function main. Here main instantiates the application's GUI part and nothing else.
import java.awt.*;
public class TemperatureConversion
{
public static void main (String[] args)
{
//Instantiate the GUI part
Frame frm = new TheGUIPart();
//Set the application's window width and height in pixels
frm.setSize (200, 150);
//Make the window visible to the user
frm.setVisible (true);
}
}
An instance of the GUI part does all the actual work. The code below is heavily commented in an attempt to make it as understandable as possible. In fact there are more comments than code. The program should become clear after a couple of readings, but if it is not, do not panic, we will return to all the major points in more detail later in the tutorial.
import java.awt.*; import BreezyGUI.*;
public class TheGUIPart extends GBFrame
//^^^^^^^^^^^^^^^
//Every BreezyGUI application program
//extends a class called GBFrame.
//This class in turn extends the AWT class
//Frame.
{
//Declare window components for labels, integer fields, and
//command buttons. These components are defined in the imported
//packages and serve various roles in a graphical user interface.
//The labels: these display the text strings that guide the user.
private Label fahrenheitLabel;
private Label centigradeLabel;;
//The integer fields: these are used for the input and output of
//integer values.
private IntegerField fahrenheitField;
private IntegerField centigradeField;
//The command buttons: these trigger the buttonClicked method when
//clicked.
private Button fahrenheitButton;
private Button centigradeButton;
//The constructor: here each window component is instantiated with
//an initial value and position in the window. A position is
//expressed by four integers that indicate a component's row,
//column, width, and height with reference to an imaginary grid
//superimposed on the window. The add methods do the actual
//instantiation. They each return a control of the indicated
//type.
TheGUIPart ()
{
fahrenheitLabel = addLabel ("Degrees Fahrenheit",1,1,1,1);
centigradeLabel = addLabel ("Degrees Centigrade",2,1,1,1);
fahrenheitField = addIntegerField (32 ,1,2,1,1);
centigradeField = addIntegerField (0 ,2,2,1,1);
fahrenheitButton = addButton ("Compute Fahrenheit",3,1,1,1);
centigradeButton = addButton ("Compute Centigrade",3,2,1,1);
}
//The buttonClicked method is activated every time a command button
//is clicked. The actual button clicked is passed to the method as
//a parameter. This parameter is tested to determine which button
//was clicked, and the appropriate action is then taken.
public void buttonClicked (Button buttonObj)
{
int fahrenheit, centigrade;
//Test the button.
if (buttonObj == fahrenheitButton){
//Use the getNumber method to retrieve an integer from
//an IntegerField object.
centigrade = centigradeField.getNumber();
//Do the conversion calculation
fahrenheit = centigrade * 9 / 5 + 32;
//Use the setNumber method to insert an integer in
//an IntegerField object
fahrenheitField.setNumber (fahrenheit);
}else{
fahrenheit = fahrenheitField.getNumber();
centigrade = (fahrenheit - 32) * 5 / 9;
centigradeField.setNumber (centigrade);
}
}
}
The actual steps for coding, compiling, and running the application shown above vary depending on the development environment; however, these steps are independent of the fact that BreezyGUI is being used. To be used successfully BreezyGUI must be installed in the same manner as any other third party Java package. Instructions for installing BreezyGUI can be found elsewhere on this website.
There are several shortcuts that can be taken in writing the application shown above. First, the two classes can be combined into one. Second, the window components can be declared and initialized in one step without requiring the use of the constructor method. Third, the comments can be stripped out. The result, which is much shorter than before, is shown next. Now one can see clearly how easy it is to create a GUI based application using BreezyGUI.
import java.awt.*;
import BreezyGUI.*;
public class TemperatureConversion extends GBFrame {
private Label fahrenheitLabel
= addLabel ("Degrees Fahrenheit",1,1,1,1);
private Label centigradeLabel
= addLabel ("Degrees Centigrade",2,1,1,1);
private IntegerField fahrenheitField
= addIntegerField (32 ,1,2,1,1);
private IntegerField centigradeField
= addIntegerField (0 ,2,2,1,1);
private Button fahrenheitButton
= addButton ("Compute Fahrenheit",3,1,1,1);
private Button centigradeButton
= addButton ("Compute Centigrade",3,2,1,1);
public void buttonClicked (Button buttonObj){
int fahrenheit, centigrade;
if (buttonObj == fahrenheitButton){
centigrade = centigradeField.getNumber();
fahrenheit = centigrade * 9 / 5 + 32;
fahrenheitField.setNumber (fahrenheit);
}else{
fahrenheit = fahrenheitField.getNumber();
centigrade = (fahrenheit - 32) * 5 / 9;
centigradeField.setNumber (centigrade);
}
}
public static void main (String[] args){
Frame frm = new TemperatureConversion ();
frm.setSize (200, 150);
frm.setVisible (true);
}
}