Programs that use BreezyGUI must import the BreezyGUI package as follows:
import BreezyGUI.*;
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.
| Add components to a window |
addLabel addButton addIntegerField addDoubleField
addTextField addTextArea addList addCheckbox addMenuItem |
| Display message boxes |
|
| Handle events |
buttonClicked listDoubleClicked
listItemSelected
menuItemSelected mouseClicked
mousePressed mouseReleased
mouseMoved mouseDragged |
| Dialogs |
|
| Console input |
|
| Format data |
|
| Integer fields |
|
| Double fields |
(Used with GBFrame, GBApplet, and BGDialog)
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);
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);
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);
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);
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);
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);
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);
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);
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");
void messageBox(String message)
Displays a message box with the specified string.
messageBox("Computation completed.");
void messageBox(Double number)
Displays a message box with the specified number.
messageBox(3.14);
void messageBox(Object obj)
Displays a message box with the string representation of the object.
messageBox(new Employee());
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.
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).
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.
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.
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.
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.
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.
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.
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.
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.
String getDlgCloseIndicator()
Returns the dialog's closing indicator. The value of this indicator is "Cancel" by default.
String indicator = theDialog.getDlgCloseIndicator();
void setDlgCloseIndicator(String s)
Sets the dialog's closing indicator to the given string.
setDlgCloseIndicator("OK");
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();
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: ");
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: ");
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: ");
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: ");
The class Format allows a programmer to center, left justify, or right justify data with respect to a specified number of columns.
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.
int getNumber()
Returns the integer currently stored in the integer field, or 0 if the integer is malformed.
int radius = radiusField.getNumber();
void setNumber(int number)
Displays the specified number in the integer field.
radiusField.setNumber(2316);
boolean isValid()
Returns true if the integer in the field is well formed, and false otherwise.
if (radiusField.isValid()) . . .
double getNumber()
Returns the floating-point number currently stored in the double field, or 0 if the number is malformed.
double velocity = velocityField.getNumber();
void setNumber(double number)
Displays the specified number in the double field.
areaField.setNumber(527.32);
boolean isValid()
Returns true if the floating-point number in the field is well formed, and false otherwise.
if (velocityField.isValid()) . . .
void setPrecision(double number)
Sets the number of digits to be displayed after the decimal point in the double field.
salaryField.setPrecision(2);
int getPrecision()
Returns number of digits to be displayed after the decimal point in the double field.
System.out.println ("Precision = " +
salaryField.getPrecision());