Package breadboards

Class 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
    • Nested Class Summary

      • Nested classes/interfaces inherited from class java.awt.Window

        java.awt.Window.Type
      • Nested classes/interfaces inherited from class java.awt.Component

        java.awt.Component.BaselineResizeBehavior
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int CENTER
      An identifier for the center panel, intended for drawing GObjects
      static int NORTH
      An identifier for the north (top) panel, where the text area resides
      static int SOUTH
      An 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
      • Fields inherited from interface java.awt.image.ImageObserver

        ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
      • Fields inherited from interface javax.swing.WindowConstants

        DISPOSE_ON_CLOSE, DO_NOTHING_ON_CLOSE, EXIT_ON_CLOSE, HIDE_ON_CLOSE
    • Constructor Summary

      Constructors 
      Constructor Description
      Breadboard()
      This constructs a 500 x 500 breadboard window
      Breadboard​(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
      void add​(GObject gObject)
      adds the specified GObject to this breadboard
      void add​(GObject gObject, double x, double y)
      adds the specified GObject to this breadboard at the specified location
      void add​(GObject gObject, GPoint pt)
      adds the specified GObject to this breadboard at the specified point
      Breadboard getBreadboard()
      returns a reference to the breadboard
      javax.swing.JButton getButton1()
      returns a reference to the left button in the south panel of this breadboard
      javax.swing.JButton getButton2()
      returns a reference to the right button in the south panel of this breadboard
      int getCenterPanelHeight()
      returns the height of the drawable area in the center of this breadboard
      int getCenterPanelWidth()
      returns the width of the drawable area in the center of this breadboard
      GObject getElement​(int index)
      returns the element with the specified z-level.
      GObject getElementAt​(double x, double y)
      returns the top-most element at the specified location
      GObject getElementAt​(GPoint pt)
      returns the top-most element at the specified point
      int getElementCount()
      returns the number of GObjects on the breadboard
      javax.swing.JLabel getLabel()
      returns a reference to the label in the south panel of this breadboard
      javax.swing.JPanel getPanel​(int panelConstant)
      returns a reference to one of the panels of this breadboard (as indicated by the panelConstant)
      javax.swing.JTextArea getTextArea()
      returns the text area at the top of the breadboard window
      javax.swing.JTextField getTextField()
      returns a reference to the text field in the south panel of this breadboard
      javax.swing.Timer getTimer()
      returns a reference to the built-in timer associated with this breadboard
      void init()
      Override to perform some action before the breadboard is initially made visible
      void onButton1Click()
      Override to perform some action whenever the left button is clicked
      void onButton2Click()
      Override to perform some action whenever the right button is clicked.
      void onTimerTick()
      Override to perform some action with each tick of the timer, provided the timer has been started.
      void pause​(int milliseconds)  
      void remove​(GObject gObject)
      removes the specified GObject from the breadboard
      void removeAll()
      removes all GObjects currently on the breadboard
      void sendBackward​(GObject gObj)
      Swaps the z-orders of the specified GObject and the object immediately "below" it.
      void sendForward​(GObject gObj)
      Swaps the z-orders of the specified GObject and the object immediately "above" it.
      void sendToBack​(GObject gObj)
      Moves the specified object below all other GObjects on the breadboard.
      void sendToFront​(GObject gObj)
      Moves the specified object "on top" of all other GObjects on the breadboard
      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)
      void setCenterPanelSize​(int width, int height)
      Expands or contracts the breadboard window size so that its central drawing area has the specified dimensions
      void updateDisplay()
      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
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.awt.MenuContainer

        getFont, postEvent
    • 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 produced
        height - 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:
        setBackground in class java.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 GObject
        x - the x-coordinate of the location specified
        y - 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 GObject
        pt - 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:
        removeAll in class java.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 location
        y - 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:
        sendForward in interface GObjectParent
        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:
        sendBackward in interface GObjectParent
        Parameters:
        gObj - the specified GObject
      • sendToFront

        public void sendToFront​(GObject gObj)
        Moves the specified object "on top" of all other GObjects on the breadboard
        Specified by:
        sendToFront in interface GObjectParent
        Parameters:
        gObj - the specified GObject
      • sendToBack

        public void sendToBack​(GObject gObj)
        Moves the specified object below all other GObjects on the breadboard.
        Specified by:
        sendToBack in interface GObjectParent
        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 area
        height - 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.