BreezySwing
Class GBFrame
java.lang.Object
|
+--java.awt.Component
|
+--java.awt.Container
|
+--java.awt.Window
|
+--java.awt.Frame
|
+--javax.swing.JFrame
|
+--BreezySwing.GBFrame
- All Implemented Interfaces:
- javax.accessibility.Accessible, java.awt.image.ImageObserver, java.awt.MenuContainer, javax.swing.RootPaneContainer, java.io.Serializable, javax.swing.WindowConstants
- public class GBFrame
- extends javax.swing.JFrame
The class GBFrame (short for Grid Bag Frame) provides a high-level application window.
The window comes with a built in GridBagLayout. Components are added
to the window by specifying their row position, column position, width (in columns),
and height (in rows)in the grid.
Events of different types, such as button clicks and menu item selections,
are handled by implementing the appropriate GBFrame methods in the application.
Example use of GBFrame:
// Hello world application with BreezySwing.
import javax.swing.*;
import BreezySwing.*;
public class HelloWorld extends GBFrame{
// Add a labeled button to the window at row 1, column 1, width 1, height 1.
JButton clickMe = addButton("Click me", 1, 1, 1, 1);
// Implement the method to handle the button click.
public void buttonClicked(JButton buttonObj){
messageBox("Hello world!");
}
// Implement the method that runs when the application is launched.
public static void main(String[] args){
Frame frm = new HelloWorld();
frm.setSize(100, 100);
frm.setVisible(true);
}
}
- See Also:
- Serialized Form
Inner classes inherited from class javax.swing.JFrame |
javax.swing.JFrame.AccessibleJFrame |
Inner classes inherited from class java.awt.Frame |
java.awt.Frame.AccessibleAWTFrame |
Inner classes inherited from class java.awt.Window |
java.awt.Window.AccessibleAWTWindow |
Inner classes inherited from class java.awt.Container |
java.awt.Container.AccessibleAWTContainer |
Inner classes inherited from class java.awt.Component |
java.awt.Component.AccessibleAWTComponent |
Fields inherited from class javax.swing.JFrame |
accessibleContext, EXIT_ON_CLOSE, rootPane, rootPaneCheckingEnabled |
Fields inherited from class java.awt.Frame |
CROSSHAIR_CURSOR, DEFAULT_CURSOR, E_RESIZE_CURSOR, HAND_CURSOR, ICONIFIED, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NORMAL, NW_RESIZE_CURSOR, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, W_RESIZE_CURSOR, WAIT_CURSOR |
Fields inherited from class java.awt.Component |
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
Fields inherited from interface javax.swing.WindowConstants |
DISPOSE_ON_CLOSE, DO_NOTHING_ON_CLOSE, HIDE_ON_CLOSE |
Fields inherited from interface java.awt.image.ImageObserver |
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
Constructor Summary |
GBFrame()
Creates a GBFrame application window. |
Method Summary |
javax.swing.JButton |
addButton(java.lang.String text,
int row,
int col,
int width,
int height)
Adds a JButton with the specified name to the specified position, with the specified
width and height. |
javax.swing.JCheckBox |
addCheckBox(java.lang.String text,
int row,
int col,
int width,
int height)
Adds a JCheckBox to the specified position, with the specified
width and height. |
javax.swing.JComboBox |
addComboBox(int row,
int col,
int width,
int height)
Adds a JComboBox (pull down list) to the specified position, with the specified
width and height. |
DoubleField |
addDoubleField(double num,
int row,
int col,
int width,
int height)
Adds a DoubleField containing the specified number to the specified position, with the specified
width and height. |
IntegerField |
addIntegerField(int num,
int row,
int col,
int width,
int height)
Adds an IntegerField containing the specified integer to the specified position, with the specified
width and height. |
javax.swing.JLabel |
addLabel(java.lang.String text,
int row,
int col,
int width,
int height)
Adds a label with the specified name to the specified position, with the specified
width and height. |
javax.swing.JList |
addList(int row,
int col,
int width,
int height)
Adds a JList (a scrolling list) to the specified position, with the specified
width and height. |
javax.swing.JMenuItem |
addMenuItem(java.lang.String menuName,
java.lang.String itemName)
Adds an item with the specified name to a menu with the specified name
in the window. |
GBPanel |
addPanel(GBPanel panel,
int row,
int col,
int width,
int height)
Adds a GBPanel to the specified position, with the specified
width and height. |
javax.swing.JRadioButton |
addRadioButton(java.lang.String text,
int row,
int col,
int width,
int height)
Adds a JRadioButton to the specified position, with the specified
width and height. |
javax.swing.JTextArea |
addTextArea(java.lang.String text,
int row,
int col,
int width,
int height)
Adds a JTextArea containing the specified string to the specified position, with the specified
width and height. |
javax.swing.JTextField |
addTextField(java.lang.String text,
int row,
int col,
int width,
int height)
Adds a JTextField containing the specified string to the specified position, with the specified
width and height. |
void |
buttonClicked(javax.swing.JButton buttonObj)
The application must implement this method in order to handle button clicks. |
void |
listDoubleClicked(javax.swing.JList listObj,
java.lang.String itemClicked)
The application must implement this method in order to handle a
double click on an item in a scrolling list. |
void |
listItemSelected(javax.swing.JList listObj)
The application must implement this method in order to handle a selection
(single click) on an item in a scrolling list. |
void |
menuItemSelected(javax.swing.JMenuItem mi)
The application must implement this method in order to handle menu events. |
void |
messageBox(double num)
Pops up a message box containing the number and an OK button. |
void |
messageBox(double num,
int width,
int height)
|
void |
messageBox(java.lang.Object msg)
Pops up a message box containing the string representation of the object and an OK button. |
void |
messageBox(java.lang.Object msg,
int width,
int height)
|
void |
messageBox(java.lang.String msg)
Pops up a message box containing the string and an OK button. |
void |
messageBox(java.lang.String msg,
int width,
int height)
|
static void |
pause()
Used with non-GUI applications (tester programs) to pause execution
until the user hits the Enter key. |
void |
setLookAndFeel(java.lang.String type)
Allows the application to set the look and feel of the window
and all its subcomponents to a platform-specific look and feel. |
void |
setSize(int width,
int height)
|
Methods inherited from class javax.swing.JFrame |
addImpl, createRootPane, frameInit, getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getJMenuBar, getLayeredPane, getRootPane, isRootPaneCheckingEnabled, paramString, processKeyEvent, processWindowEvent, remove, setContentPane, setDefaultCloseOperation, setGlassPane, setJMenuBar, setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, update |
Methods inherited from class java.awt.Frame |
addNotify, finalize, getCursorType, getFrames, getIconImage, getMenuBar, getState, getTitle, isResizable, remove, removeNotify, setCursor, setIconImage, setMenuBar, setResizable, setState, setTitle |
Methods inherited from class java.awt.Window |
addWindowListener, applyResourceBundle, applyResourceBundle, dispose, getFocusOwner, getGraphicsConfiguration, getInputContext, getListeners, getLocale, getOwnedWindows, getOwner, getToolkit, getWarningString, hide, isShowing, pack, postEvent, processEvent, removeWindowListener, setCursor, show, toBack, toFront |
Methods inherited from class java.awt.Container |
add, add, add, add, add, addContainerListener, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getInsets, getLayout, getMaximumSize, getMinimumSize, getPreferredSize, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paint, paintComponents, preferredSize, print, printComponents, processContainerEvent, remove, removeAll, removeContainerListener, setFont, validate, validateTree |
Methods inherited from class java.awt.Component |
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addPropertyChangeListener, addPropertyChangeListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, getBackground, getBounds, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphics, getHeight, getInputMethodRequests, getLocation, getLocation, getLocationOnScreen, getName, getParent, getPeer, getSize, getSize, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isDisplayable, isDoubleBuffered, isEnabled, isFocusTraversable, isLightweight, isOpaque, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseEvent, processMouseMotionEvent, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setDropTarget, setEnabled, setForeground, setLocale, setLocation, setLocation, setName, setSize, setVisible, show, size, toString, transferFocus |
Methods inherited from class java.lang.Object |
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.awt.MenuContainer |
getFont, postEvent |
GBFrame
public GBFrame()
- Creates a GBFrame application window.
pause
public static void pause()
- Used with non-GUI applications (tester programs) to pause execution
until the user hits the Enter key.
Prevents a "fly-by" disappearance of the terminal window
in some environments by pausing execution until the user
hits the Enter key. Usage: GBFrame.pause();
setLookAndFeel
public void setLookAndFeel(java.lang.String type)
- Allows the application to set the look and feel of the window
and all its subcomponents to a platform-specific look and feel.
If no event handling is desired, this method need not be implemented.
- Parameters:
type
- A String, either "METAL", "MOTIF", or "OTHER"
setSize
public void setSize(int width,
int height)
- Overrides:
setSize
in class java.awt.Component
messageBox
public void messageBox(double num)
- Pops up a message box containing the number and an OK button.
messageBox
public void messageBox(java.lang.String msg)
- Pops up a message box containing the string and an OK button.
messageBox
public void messageBox(java.lang.Object msg)
- Pops up a message box containing the string representation of the object and an OK button.
messageBox
public void messageBox(double num,
int width,
int height)
messageBox
public void messageBox(java.lang.String msg,
int width,
int height)
messageBox
public void messageBox(java.lang.Object msg,
int width,
int height)
menuItemSelected
public void menuItemSelected(javax.swing.JMenuItem mi)
- The application must implement this method in order to handle menu events. If no menus
are added to the window, this method need not be implemented.
- Parameters:
mi
- The MenuItem in which the selection occurred.
Example:
// Add the menu items to the window.
JMenuItem newFileMI = addMenuItem("File", "New");
JMenuItem openFileMI = addMenuItem("File", "Open");
JMenuItem saveFileMI = addMenuItem("File", "Save");
// Handle the menu selection.
public void menuItemSelected(JMenuItem mi){
if (mi == newFileMI)
messageBox("File/New selected");
else if (mi == openFileMI)
messageBox("File/Open selected");
else
messageBox("File/Save selected");
}
listItemSelected
public void listItemSelected(javax.swing.JList listObj)
- The application must implement this method in order to handle a selection
(single click) on an item in a scrolling list.
If no event handling is desired, this method need not be implemented.
- Parameters:
listObj
- The JList in which the selection occurred.
buttonClicked
public void buttonClicked(javax.swing.JButton buttonObj)
- The application must implement this method in order to handle button clicks.
If no buttons are added to the window, this method need not be implemented.
- Parameters:
buttonObj
- The JButton in which the click occurred.
Example:
// Add the buttons to the window.
JButton okButton = addButton("OK", 1, 1, 1, 1);
JButton cancelButton = addButton("Cancel", 1, 2, 1, 1);
// Handle the button selection.
public void buttonClicked(JButton buttonObj){
if (buttonObj == okButton)
messageBox("OK selected");
else
messageBox("Cancel selected");
}
listDoubleClicked
public void listDoubleClicked(javax.swing.JList listObj,
java.lang.String itemClicked)
- The application must implement this method in order to handle a
double click on an item in a scrolling list.
If no double click is anticipated, this method need not be implemented.
- Parameters:
listObj
- The JList in which the double click occurred.itemClicked
- The string selected by the double click.
addMenuItem
public javax.swing.JMenuItem addMenuItem(java.lang.String menuName,
java.lang.String itemName)
- Adds an item with the specified name to a menu with the specified name
in the window.
- Parameters:
menuName
- The name of the menu.item
- name The name of the menu item (selection).- Returns:
- The JMenuItem.
Example:
JMenuItem newFileMI = addMenuItem("File", "New");
JMenuItem openFileMI = addMenuItem("File", "Open");
JMenuItem saveFileMI = addMenuItem("File", "Save");
addLabel
public javax.swing.JLabel addLabel(java.lang.String text,
int row,
int col,
int width,
int height)
- Adds a label with the specified name to the specified position, with the specified
width and height.
- Parameters:
text
- The name of the label.row
- The beginning row (starting from 1) of the window's grid in which the label is displayed.col
- The beginning column (starting from 1) of the window's grid in which the label is displayed.width
- The number of columns of the window's grid occuppied by the label.height
- The number of rows of the window's grid occuppied by the label.- Returns:
- the JLabel
addButton
public javax.swing.JButton addButton(java.lang.String text,
int row,
int col,
int width,
int height)
- Adds a JButton with the specified name to the specified position, with the specified
width and height.
- Parameters:
text
- The name of the Button.row
- The beginning row (starting from 1) of the window's grid in which the Button is displayed.col
- The beginning column (starting from 1) of the window's grid in which the Button is displayed.width
- The number of columns of the window's grid occuppied by the Button.height
- The number of rows of the window's grid occuppied by the Button.- Returns:
- the button.
Example:
JButton okButton = addButton("OK", 1, 1, 1, 1);
// Adds a button at position row 1, column 1,
// with a width of 1 column and a height of one row.
addTextField
public javax.swing.JTextField addTextField(java.lang.String text,
int row,
int col,
int width,
int height)
- Adds a JTextField containing the specified string to the specified position, with the specified
width and height.
- Parameters:
text
- The string to be displayed initially.row
- The beginning row (starting from 1) of the window's grid in which the JTextField is displayed.col
- The beginning column (starting from 1) of the window's grid in which the JTextField is displayed.width
- The number of columns of the window's grid occuppied by the JTextField.height
- The number of rows of the window's grid occuppied by the JTextField.- Returns:
- the JTextField.
addTextArea
public javax.swing.JTextArea addTextArea(java.lang.String text,
int row,
int col,
int width,
int height)
- Adds a JTextArea containing the specified string to the specified position, with the specified
width and height.
- Parameters:
text
- The string to be displayed initially.row
- The beginning row (starting from 1) of the window's grid in which the JTextArea is displayed.col
- The beginning column (starting from 1) of the window's grid in which the JTextArea is displayed.width
- The number of columns of the window's grid occuppied by the JTextArea.height
- The number of rows of the window's grid occuppied by the JTextArea.- Returns:
- the TextArea.
addList
public javax.swing.JList addList(int row,
int col,
int width,
int height)
- Adds a JList (a scrolling list) to the specified position, with the specified
width and height.
- Parameters:
row
- The beginning row (starting from 1) of the window's grid in which the JList is displayed.col
- The beginning column (starting from 1) of the window's grid in which the JList is displayed.width
- The number of columns of the window's grid occuppied by the JList.height
- The number of rows of the window's grid occuppied by the JList.- Returns:
- the JList
addComboBox
public javax.swing.JComboBox addComboBox(int row,
int col,
int width,
int height)
- Adds a JComboBox (pull down list) to the specified position, with the specified
width and height.
- Parameters:
row
- The beginning row (starting from 1) of the window's grid in which the JComboBox is displayed.col
- The beginning column (starting from 1) of the window's grid in which the JComboBox is displayed.width
- The number of columns of the window's grid occuppied by the JComboBox.height
- The number of rows of the window's grid occuppied by the JComboBox.- Returns:
- the JComboBox.
addIntegerField
public IntegerField addIntegerField(int num,
int row,
int col,
int width,
int height)
- Adds an IntegerField containing the specified integer to the specified position, with the specified
width and height.
- Parameters:
num
- The integer to be displayed initially.row
- The beginning row (starting from 1) of the window's grid in which the IntegerField is displayed.col
- The beginning column (starting from 1) of the window's grid in which the IntegerField is displayed.width
- The number of columns of the window's grid occuppied by the IntegerField.height
- The number of rows of the window's grid occuppied by the IntegerField.
addDoubleField
public DoubleField addDoubleField(double num,
int row,
int col,
int width,
int height)
- Adds a DoubleField containing the specified number to the specified position, with the specified
width and height.
- Parameters:
num
- The number to be displayed initially.row
- The beginning row (starting from 1) of the window's grid in which the DoubleField is displayed.col
- The beginning column (starting from 1) of the window's grid in which the DoubleField is displayed.width
- The number of columns of the window's grid occuppied by the DoubleField.height
- The number of rows of the window's grid occuppied by the DoubleField.
addCheckBox
public javax.swing.JCheckBox addCheckBox(java.lang.String text,
int row,
int col,
int width,
int height)
- Adds a JCheckBox to the specified position, with the specified
width and height.
- Parameters:
row
- The beginning row (starting from 1) of the window's grid in which the JCheckBox is displayed.col
- The beginning column (starting from 1) of the window's grid in which the JCheckBox is displayed.width
- The number of columns of the window's grid occuppied by the JCheckBox.height
- The number of rows of the window's grid occuppied by the JCheckBox.- Returns:
- the JCheckBox.
addRadioButton
public javax.swing.JRadioButton addRadioButton(java.lang.String text,
int row,
int col,
int width,
int height)
- Adds a JRadioButton to the specified position, with the specified
width and height.
- Parameters:
row
- The beginning row (starting from 1) of the window's grid in which the JRadioButton is displayed.col
- The beginning column (starting from 1) of the window's grid in which the JRadioButton is displayed.width
- The number of columns of the window's grid occuppied by the JRadioButton.height
- The number of rows of the window's grid occuppied by the JRadioButton.- Returns:
- the JRadioButton.
addPanel
public GBPanel addPanel(GBPanel panel,
int row,
int col,
int width,
int height)
- Adds a GBPanel to the specified position, with the specified
width and height.
- Parameters:
row
- The beginning row (starting from 1) of the window's grid in which the GBPanel is displayed.col
- The beginning column (starting from 1) of the window's grid in which the GBPanel is displayed.width
- The number of columns of the window's grid occuppied by the GBPanel.height
- The number of rows of the window's grid occuppied by the GBPanel.- Returns:
- the GBPanel.