BreezyGUIŪ Quick Reference

 

Importing BreezyGUI

 

Programs that use BreezyGUI must import the BreezyGUI package as follows:

 

import BreezyGUI.*;

 

Extending the Appropriate GB Class

 

To use BreezyGUI one must extend the appropriate GB class:

 

·        For a Java application, define the application class as an extension of GBFrame.

·        For a Java applet, define the applet class as an extension of GBApplet.

·        For a Java dialog, define the dialog class as an extension of GBDialog.

 

Method Summary

 

Add components to a window

addLabel addButton addIntegerField addDoubleField addTextField addTextArea addList addCheckbox addMenuItem

Display message boxes

messageBox

Handle events

buttonClicked listDoubleClicked listItemSelected menuItemSelected mouseClicked mousePressed mouseReleased mouseMoved mouseDragged

Dialogs

constructor getDlgCloseIndicator setDlgCloseIndicator

Console input

pause readChar readDouble readInt readLine

Format data

justify

Integer fields

getNumber setNumber isValid

Double fields

getNumber setNumber isValid setPrecision getPrecision

 

 

Methods That Add Components to a Window

(Used with GBFrame, GBApplet, and BGDialog)

 

addLabel

Label addLabel

(String text, int row, int col, int width, int height)

 

Creates a new label with the given text, places the label in the framework at the given location, and returns the label.

 

Label radiusLabel = addLabel("Radius", 1, 1, 1, 1);

 

addButton

Button addButton

(String label, int row, int col, int width, int height)          

 

Creates a new button with the given label, places the button in the framework at the given location, and returns the button.

 

Button calculateButton = addButton("Calculate", 1, 1, 1, 1);

 

addIntegerField

IntegerField addIntegerField

(int number, int row, int col, int width, int height)

 

Creates a new integer field with the given number, places the integer field in the framework at the given location, and returns the integer field.

 

IntegerField radiusField = addIntegerField(0, 1, 1, 2, 1);

 

addDoubleField

DoubleField addDoubleField

(double number, int row, int col, int width, int height)

 

Creates a new double field with the given number, places the double field in the framework at the given location, and returns the double field.

 

DoubleField areaField = addDoubleField(0.0, 1, 1, 2, 1);

 

addTextField

TextField addTextField

(String text, int row, int col, int width, int height)

 

Creates a new text field with the given text, places the text field in the framework at the given location, and returns the text field.

 

TextField nameField = addTextField("Sandy", 1, 1, 3, 1);

 

addTextArea

TextArea addTextArea

(String text, int row, int col, int width, int height)

 

Creates a new text area with the given text, places the text area in the framework at the given location, and returns the text area.

 

TextArea resultArea = addTextArea("", 1, 1, 5, 2);

 

addList

List addList(int row, int col, int width, int height)

 

Creates a new list, places the list in the framework at the given location, and returns the list.

 

List nameList = addList(1, 1, 5, 1);

 

addCheckbox

Checkbox addCheckbox

(String text, int row, int col, int width, int height)

 

Creates a new checkbox with the given text, places the checkbox in the framework at the given location, and returns the checkbox.

 

Checkbox marriedBox = addCheckbox ("Married", 1, 1, 1, 1);

 

addMenuItem

MenuItem addMenuItem

(String menuLabel, String itemLabel)

 

Creates a menu with the specified label if one does not exist, creates a menu item with the specified label, adds the menu item to the menu, and returns the menu item.  Note: Not available for GBApplet and GBDialog.

 

MenuItem saveFileItem = addMenuItem("File", "Save");

 

 

Methods That Display Message Boxes

messageBox

void messageBox(String message)

 

Displays a message box with the specified string.

 

messageBox("Computation completed.");

 

messageBox

void messageBox(Double number)

 

Displays a message box with the specified number.

 

messageBox(3.14);

 

messageBox

void messageBox(Object obj)

 

Displays a message box with the string representation of the object.

 

messageBox(new Employee());

 

 

Methods for Handling Events in Window Components

buttonClicked

void buttonClicked(Button buttonObj)

 

The framework invokes this method when a button is selected.  The application should override this method to take the appropriate action.  The parameter is the button where the event occurred.

 

listDoubleClicked

void listDoubleClicked(List listObj, String itemClicked)

 

The framework invokes this method when a list item is double-clicked. The application should override this method to take the appropriate action. The parameters are the list and the selected list item.  Note: this method is invoked after the method listItemSelected (see below).

 

listItemSelected

void listItemSelected(List listObj)

 

The framework invokes this method when a list item is selected with a single click or a double click. The application may or may not override this method to take the appropriate action. The parameter is the list in which the item was selected.  The programmer can use the List methods getSelectedIndex() and getItem(int) to determine the selected item.

 

menuItemSelected

void menuItemSelected(MenuItem mI)

 

The framework invokes this method when a menu item is selected. The application should override this method to take the appropriate action. The parameter is the menu item selected when the event occurred.  Note: Not available for GBApplet and GBDialog.

 

mouseClicked

void mouseClicked(int x, int y)

 

The framework invokes this method when the mouse is clicked. The application should override this method to take the appropriate action. The parameters represent the window coordinates of the mouse when the event occurred.

 

mousePressed

void mousePressed(int x, int y)

 

The framework invokes this method when the mouse is pressed. The application should override this method to take the appropriate action. The parameters represent the window coordinates of the mouse when the event occurred.

 

mouseReleased

void mouseReleased(int x, int y)

 

The framework invokes this method when the mouse is released. The application should override this method to take the appropriate action. The parameters represent the window coordinates of the mouse when the event occurred.

 

mouseMoved

void mouseMoved(int x, int y)

 

The framework invokes this method when the mouse is moved. The application should override this method to take the appropriate action. The parameters represent the window coordinates of the mouse when the event occurred.

 

mouseDragged

void mouseDragged(int x, int y)

 

The framework invokes this method when the mouse is dragged. The application should override this method to take the appropriate action. The parameters represent the window coordinates of the mouse when the event occurred.

 

 

Methods for Class GBDialog

 

Constructor

GBDialog(Frame f)

 

This is the constructor.  Its use is required in the constructor of a GBDialog subclass, and is invoked by calling super.  The constructor's parameter is the parent frame of the dialog. When the dialog is used by an application, the parent frame is a reference to the application. When the dialog is used by an applet or by another dialog, the parent frame is an anonymous frame.

 

getDlgCloseIndicator

String getDlgCloseIndicator()

 

Returns the dialog's closing indicator.  The value of this indicator is "Cancel" by default.

 

String indicator = theDialog.getDlgCloseIndicator();

 

setDlgCloseIndicator

void setDlgCloseIndicator(String s)

 

Sets the dialog's closing indicator to the given string.

 

setDlgCloseIndicator("OK");

 

 

Methods for Class Console

 

pause

static void pause()

 

Prompts the user to strike the Enter key and waits for the user to do this.  Used to pause output in the terminal window or to keep the terminal window from closing in non-GUI programs.  Note: BreezyGUI also includes the similar method GBFrame.pause().

 

Console.pause();

 

readChar

static char readChar(String userPrompt)

 

Displays userPrompt in the terminal window and waits for the user's input.  Returns a character that represents the user's input from the terminal window.

 

char letter = Console.readChar("Please enter a letter: ");

 

readDouble

static double readDouble(String userPrompt)

 

Displays userPrompt in the terminal window and waits for the user's input.  Throws a NumberFormatException if the user's input cannot represent a double.  Returns a double that represents the user's input from the terminal window.

 

double d = Console.readDouble("Please enter a real number: ");

 

readInt

static int readInt(String userPrompt)

 

Displays userPrompt in the terminal window and waits for the user's input. Throws a NumberFormatException if the user's input cannot represent an int.  Returns an int that represents the user's input from the terminal window.

 

int i = Console.readInt("Please enter an integer: ");

 

readLine

static String readLine(String userPrompt)

 

Displays userPrompt in the terminal window and waits for the user's input.  Returns a string that represents the user's input from the terminal window.

 

String name = Console.readLine("Please enter your name: ");

 

 

Methods for Class Format

 

The class Format allows a programmer to center, left justify, or right justify data with respect to a specified number of columns.

 

justify

static String justify  (char justification, String text, int width)

static String justify  (char justification, char ch, int width)

static String justify  (char justification, long number, int width)

static String justify  (char justification, double number, int width, int precision)

 

Formats and returns a string representation of the given data, where justification equals 'c', 'l', or 'r'.  The data are centered, left justified, or right justified within a string of the specified width.

 

String strOutput  =  Format.justify('r', "Hi there!", 34);

String charOutput =  Format.justify('c', 'A', 10);

String intOutput  =  Format.justify('l', 21, 80);

String dollars    =  Format.justify('r', 3.1416, 10, 2);

 

Note: The extra parameter for the precision must be included when using Format.justify with a double.

 

 

Methods for Class IntegerField

 

getNumber

int getNumber()

 

Returns the integer currently stored in the integer field, or 0 if the integer is malformed.

 

int radius = radiusField.getNumber();

 

setNumber

void setNumber(int number)

 

Displays the specified number in the integer field.

 

radiusField.setNumber(2316);

 

isValid

boolean isValid()

 

Returns true if the integer in the field is well formed, and false otherwise.

 

if (radiusField.isValid()) . . .

     

 

Methods for Class DoubleField

 

getNumber

double getNumber()

 

Returns the floating-point number currently stored in the double field, or 0 if the number is malformed.

 

double velocity = velocityField.getNumber();

 

setNumber

void setNumber(double number)

 

Displays the specified number in the double field.

 

areaField.setNumber(527.32);

 

isValid

boolean isValid()

 

Returns true if the floating-point number in the field is well formed, and false otherwise.

 

if (velocityField.isValid()) . . .

 

setPrecision

void setPrecision(double number)

 

Sets the number of digits to be displayed after the decimal point in the double field.

 

salaryField.setPrecision(2);

 

getPrecision

int getPrecision()

 

Returns number of digits to be displayed after the decimal point in the double field.

 

System.out.println ("Precision = " +

   salaryField.getPrecision());