Package breadboards
Class Breadboard
- java.lang.Object
-
- java.awt.Component
-
- java.awt.Container
-
- java.awt.Window
-
- java.awt.Frame
-
- javax.swing.JFrame
-
- breadboards.Breadboard
-
- All Implemented Interfaces:
GObjectParent,java.awt.image.ImageObserver,java.awt.MenuContainer,java.io.Serializable,javax.accessibility.Accessible,javax.swing.RootPaneContainer,javax.swing.WindowConstants
public class Breadboard extends javax.swing.JFrame implements GObjectParent
A JFrame with several components pre-added for quick development (i.e., a text area, text field, label, two buttons, and a panel on which drawings can be made. This class includes methods for taking advantage of a built in timer, to facilitate animations.- Author:
- paul oser
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static intCENTERAn identifier for the center panel, intended for drawing GObjectsstatic intNORTHAn identifier for the north (top) panel, where the text area residesstatic intSOUTHAn identifier for the south (bottom) panel, where the label, text field, and both buttons reside.-
Fields inherited from class java.awt.Frame
CROSSHAIR_CURSOR, DEFAULT_CURSOR, E_RESIZE_CURSOR, HAND_CURSOR, ICONIFIED, MAXIMIZED_BOTH, MAXIMIZED_HORIZ, MAXIMIZED_VERT, 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
-
-
Constructor Summary
Constructors Constructor Description Breadboard()This constructs a 500 x 500 breadboard windowBreadboard(int width, int height)This constructs a breadboard window with the specified dimensions
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(GObject gObject)adds the specified GObject to this breadboardvoidadd(GObject gObject, double x, double y)adds the specified GObject to this breadboard at the specified locationvoidadd(GObject gObject, GPoint pt)adds the specified GObject to this breadboard at the specified pointBreadboardgetBreadboard()returns a reference to the breadboardjavax.swing.JButtongetButton1()returns a reference to the left button in the south panel of this breadboardjavax.swing.JButtongetButton2()returns a reference to the right button in the south panel of this breadboardintgetCenterPanelHeight()returns the height of the drawable area in the center of this breadboardintgetCenterPanelWidth()returns the width of the drawable area in the center of this breadboardGObjectgetElement(int index)returns the element with the specified z-level.GObjectgetElementAt(double x, double y)returns the top-most element at the specified locationGObjectgetElementAt(GPoint pt)returns the top-most element at the specified pointintgetElementCount()returns the number of GObjects on the breadboardjavax.swing.JLabelgetLabel()returns a reference to the label in the south panel of this breadboardjavax.swing.JPanelgetPanel(int panelConstant)returns a reference to one of the panels of this breadboard (as indicated by the panelConstant)javax.swing.JTextAreagetTextArea()returns the text area at the top of the breadboard windowjavax.swing.JTextFieldgetTextField()returns a reference to the text field in the south panel of this breadboardjavax.swing.TimergetTimer()returns a reference to the built-in timer associated with this breadboardvoidinit()Override to perform some action before the breadboard is initially made visiblevoidonButton1Click()Override to perform some action whenever the left button is clickedvoidonButton2Click()Override to perform some action whenever the right button is clicked.voidonTimerTick()Override to perform some action with each tick of the timer, provided the timer has been started.voidpause(int milliseconds)voidremove(GObject gObject)removes the specified GObject from the breadboardvoidremoveAll()removes all GObjects currently on the breadboardvoidsendBackward(GObject gObj)Swaps the z-orders of the specified GObject and the object immediately "below" it.voidsendForward(GObject gObj)Swaps the z-orders of the specified GObject and the object immediately "above" it.voidsendToBack(GObject gObj)Moves the specified object below all other GObjects on the breadboard.voidsendToFront(GObject gObj)Moves the specified object "on top" of all other GObjects on the breadboardvoidsetBackground(java.awt.Color color)This sets the background color of the breadboard's content area (i.e, the drawing area in the center)voidsetCenterPanelSize(int width, int height)Expands or contracts the breadboard window size so that its central drawing area has the specified dimensionsvoidupdateDisplay()repaints the breadboard-
Methods inherited from class javax.swing.JFrame
getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getGraphics, getJMenuBar, getLayeredPane, getRootPane, getTransferHandler, isDefaultLookAndFeelDecorated, remove, repaint, setContentPane, setDefaultCloseOperation, setDefaultLookAndFeelDecorated, setGlassPane, setIconImage, setJMenuBar, setLayeredPane, setLayout, setTransferHandler, update
-
Methods inherited from class java.awt.Frame
addNotify, getCursorType, getExtendedState, getFrames, getIconImage, getMaximizedBounds, getMenuBar, getState, getTitle, isResizable, isUndecorated, remove, removeNotify, setCursor, setExtendedState, setMaximizedBounds, setMenuBar, setOpacity, setResizable, setShape, setState, setTitle, setUndecorated
-
Methods inherited from class java.awt.Window
addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, dispose, getBackground, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getIconImages, getInputContext, getListeners, getLocale, getModalExclusionType, getMostRecentFocusOwner, getOpacity, getOwnedWindows, getOwner, getOwnerlessWindows, getShape, getToolkit, getType, getWarningString, getWindowFocusListeners, getWindowListeners, getWindows, getWindowStateListeners, hide, isActive, isAlwaysOnTop, isAlwaysOnTopSupported, isAutoRequestFocus, isFocusableWindow, isFocusCycleRoot, isFocused, isLocationByPlatform, isOpaque, isShowing, isValidateRoot, pack, paint, postEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, reshape, setAlwaysOnTop, setAutoRequestFocus, setBounds, setBounds, setCursor, setFocusableWindowState, setFocusCycleRoot, setIconImages, setLocation, setLocation, setLocationByPlatform, setLocationRelativeTo, setMinimumSize, setModalExclusionType, setSize, setSize, setType, setVisible, show, toBack, toFront
-
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, print, printComponents, remove, removeContainerListener, setComponentZOrder, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, transferFocusDownCycle, validate
-
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, dispatchEvent, enable, enable, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, prepareImage, prepareImage, printAll, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resize, resize, revalidate, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setMaximumSize, setMixingCutoutShape, setName, setPreferredSize, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
-
-
-
Field Detail
-
NORTH
public static final int NORTH
An identifier for the north (top) panel, where the text area resides- See Also:
- Constant Field Values
-
CENTER
public static final int CENTER
An identifier for the center panel, intended for drawing GObjects- See Also:
- Constant Field Values
-
SOUTH
public static final int SOUTH
An identifier for the south (bottom) panel, where the label, text field, and both buttons reside.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Breadboard
public Breadboard()
This constructs a 500 x 500 breadboard window
-
Breadboard
public Breadboard(int width, int height)This constructs a breadboard window with the specified dimensions- Parameters:
width- the width of the window producedheight- the height of the window produced
-
-
Method Detail
-
pause
public void pause(int milliseconds)
-
setBackground
public void setBackground(java.awt.Color color)
This sets the background color of the breadboard's content area (i.e, the drawing area in the center)- Overrides:
setBackgroundin classjava.awt.Frame
-
getBreadboard
public Breadboard getBreadboard()
returns a reference to the breadboard- Returns:
- a reference to the breadboard
-
getTextArea
public javax.swing.JTextArea getTextArea()
returns the text area at the top of the breadboard window- Returns:
- the text area at the top of the breadboard window
-
getLabel
public javax.swing.JLabel getLabel()
returns a reference to the label in the south panel of this breadboard- Returns:
- a reference to the label in the south panel of this breadboard
-
getTextField
public javax.swing.JTextField getTextField()
returns a reference to the text field in the south panel of this breadboard- Returns:
- a reference to the text field in the south panel of this breadboard
-
getTimer
public javax.swing.Timer getTimer()
returns a reference to the built-in timer associated with this breadboard- Returns:
- a reference to the built-in timer associated with this breadboard
-
getButton1
public javax.swing.JButton getButton1()
returns a reference to the left button in the south panel of this breadboard- Returns:
- a reference to the left button in the south panel of this breadboard
-
getButton2
public javax.swing.JButton getButton2()
returns a reference to the right button in the south panel of this breadboard- Returns:
- a reference to the right button in the south panel of this breadboard
-
getPanel
public javax.swing.JPanel getPanel(int panelConstant)
returns a reference to one of the panels of this breadboard (as indicated by the panelConstant)- Parameters:
panelConstant- (e.g., Breadboard.NORTH, Breadboard.CENTER, Breadboard.SOUTH)- Returns:
- a reference to one of the panels of this breadboard (as indicated by the panelConstant)
-
getCenterPanelHeight
public int getCenterPanelHeight()
returns the height of the drawable area in the center of this breadboard- Returns:
- the height of the drawable area in the center of this breadboard
-
getCenterPanelWidth
public int getCenterPanelWidth()
returns the width of the drawable area in the center of this breadboard- Returns:
- the width of the drawable area in the center of this breadboard
-
add
public void add(GObject gObject)
adds the specified GObject to this breadboard- Parameters:
gObject- the GObject to be added
-
add
public void add(GObject gObject, double x, double y)
adds the specified GObject to this breadboard at the specified location- Parameters:
gObject- the specified GObjectx- the x-coordinate of the location specifiedy- the y-coordinate of the location specified
-
add
public void add(GObject gObject, GPoint pt)
adds the specified GObject to this breadboard at the specified point- Parameters:
gObject- the specified GObjectpt- the specified point
-
remove
public void remove(GObject gObject)
removes the specified GObject from the breadboard- Parameters:
gObject- the specified GObject
-
removeAll
public void removeAll()
removes all GObjects currently on the breadboard- Overrides:
removeAllin classjava.awt.Container
-
getElementAt
public GObject getElementAt(double x, double y)
returns the top-most element at the specified location- Parameters:
x- the x-coordinate of the specified locationy- the y-coordinate of the specified location- Returns:
- a reference to the top-most (in the z-order sense) element at the specified location
-
getElementAt
public GObject getElementAt(GPoint pt)
returns the top-most element at the specified point- Parameters:
pt- the specified point- Returns:
- a reference to the top-most (in the z-order sense) element at the specified point
-
getElementCount
public int getElementCount()
returns the number of GObjects on the breadboard- Returns:
- the number of GObjects on the breadboard
-
getElement
public GObject getElement(int index)
returns the element with the specified z-level.- Parameters:
index- the position in the z-order list maintained by the breadboard- Returns:
- a reference to the GObject with the specified index (i.e., position in the aforementioned list)
-
sendForward
public void sendForward(GObject gObj)
Swaps the z-orders of the specified GObject and the object immediately "above" it.- Specified by:
sendForwardin interfaceGObjectParent- Parameters:
gObj- the specified GObject
-
sendBackward
public void sendBackward(GObject gObj)
Swaps the z-orders of the specified GObject and the object immediately "below" it.- Specified by:
sendBackwardin interfaceGObjectParent- Parameters:
gObj- the specified GObject
-
updateDisplay
public void updateDisplay()
repaints the breadboard- Specified by:
updateDisplayin interfaceGObjectParent
-
sendToFront
public void sendToFront(GObject gObj)
Moves the specified object "on top" of all other GObjects on the breadboard- Specified by:
sendToFrontin interfaceGObjectParent- Parameters:
gObj- the specified GObject
-
sendToBack
public void sendToBack(GObject gObj)
Moves the specified object below all other GObjects on the breadboard.- Specified by:
sendToBackin interfaceGObjectParent- Parameters:
gObj- the specified GObject
-
setCenterPanelSize
public void setCenterPanelSize(int width, int height)Expands or contracts the breadboard window size so that its central drawing area has the specified dimensions- Parameters:
width- the new width of the central drawing areaheight- the new height of the central drawing area
-
init
public void init()
Override to perform some action before the breadboard is initially made visible
-
onButton1Click
public void onButton1Click()
Override to perform some action whenever the left button is clicked
-
onButton2Click
public void onButton2Click()
Override to perform some action whenever the right button is clicked.
-
onTimerTick
public void onTimerTick()
Override to perform some action with each tick of the timer, provided the timer has been started.
-
-