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

More Info About the Breezy Boxes
(Working with String input and set precision.)

If you want the user to type String data in the Breezy response box:
. . .
// This program expects user to type his/her name in response
// - - then enter age.
// The information will be displayed in a message box.

public class SampleProgram extends GBFrame
{
     Label nameLabel = addLabel ("Name",1,1,1,1);
     Label ageLabel = addLabel ("Age",2,1,1,1);
    
     TextField nameField = addTextField ("",1,2,1,1);
     IntegerField ageField = addIntegerField (0,2,2,1,1);
    
     Button computeButton = addButton ("Display",3,1,2,1);

     public void buttonClicked (Button buttonObj)
    {
        String name, outputString;
        int age;
        name = nameField.getText();
        age = ageField.getNumber();
     
        outputString= "Name: " + name + "\n" + "Age: " + age + "\n";
        messageBox(outputString);
     }

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



If you want to display a specific number of decimal places in a Breezy box:
. . .
// This program takes a dollar amount from user
// and converts it to pesos.
// Information will be displayed with two decimal places.

public void buttonClicked (Button buttonObj)
{
       double dollar, peso;
       peso = PesosField.getNumber();
       dollar = peso/10.2;
       DollarsField.setNumber(dollar);
       DollarsField.setPrecision(2);
}
 

TextField nameField = addTextField ("",1,2,1,1);

Be careful when entering this line.  The correct entry is "" (right tight together) and not " " (with a space in between).  If you put in the space, you will need to type a space at the end of the string being entered in the Breezy box for it to be recognized correctly.

 

If you want to give your Breezy box a title:

Notice that this Breezy box has a title up in the blue area at the top.  To create a title, simply add one line of code in main.

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



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