Package ucb.gui2

Class Pad

All Implemented Interfaces:
KeyListener, MouseListener, MouseMotionListener, ImageObserver, MenuContainer, Serializable, EventListener

public class Pad extends JComponent implements MouseListener, MouseMotionListener, KeyListener
A Pad is a blank slate that may be inserted into a TopLevel. It provides methods that set up responses to mouse events, and an overrideable paintComponent method that allows one to draw anything that may be rendered on a standard Java Graphics2D. Standard usage is to extend Pad.
See Also:
  • Constructor Details

    • Pad

      protected Pad()
      A new, empty Pad.
  • Method Details

    • setMouseHandler

      public void setMouseHandler(String eventKind, BiConsumer<String,MouseEvent> func)
      Handle the kind of mouse event EVENTKIND by calling FUNC's accept method with EVENTKIND and the MouseEvent that describes the event. The default handling of any event is to ignore it. The possible values of EVENTKIND are:
      • "click": A mouse button is clicked (pressed and released).
      • "press": A mouse button is pressed.
      • "release": A mouse button is released.
      • "enter": The mouse enters this Pad.
      • "exit": The mouse exits this Pad.
      • "drag": The mouse dragged (moved while a button is pressed).
      • "move": The mouse moves.
      Mouse clicks follow releases (both occur), unless the mouse has been dragged, in which case one sees a press, one or more drags, and a release with no click.
    • setKeyHandler

      public void setKeyHandler(String eventKind, BiConsumer<String,KeyEvent> func)
      Handle the kind of key event EVENTKIND by calling FUNC's accept method with EVENTKIND and the KeyEvent that describes the event. The default handling of any event is to ignore it. The possible values of EVENTKIND are:
      • "keypress": A key is pressed.
      • "keyrelease": A key is released.
      • "keytype": A key is typed (denoting a valid Unicode character).
      Keytype events occur between a press and subsequent release event (all three occur if the key represents a Unicode character). Keytype events do not occur for typing of keys such as Ctrl, Shift, Meta, Insert, or function keys (F1, etc.) which do not correspond to Unicode characters.
    • paintComponent

      protected void paintComponent(Graphics2D g)
      Repaint myself on G. This default implementation does nothing.
    • paintComponent

      public void paintComponent(Graphics g)
      Overrides:
      paintComponent in class JComponent
    • mouseClicked

      public void mouseClicked(MouseEvent e)
      Specified by:
      mouseClicked in interface MouseListener
    • mouseReleased

      public void mouseReleased(MouseEvent e)
      Specified by:
      mouseReleased in interface MouseListener
    • mousePressed

      public void mousePressed(MouseEvent e)
      Specified by:
      mousePressed in interface MouseListener
    • mouseEntered

      public void mouseEntered(MouseEvent e)
      Specified by:
      mouseEntered in interface MouseListener
    • mouseExited

      public void mouseExited(MouseEvent e)
      Specified by:
      mouseExited in interface MouseListener
    • mouseDragged

      public void mouseDragged(MouseEvent e)
      Specified by:
      mouseDragged in interface MouseMotionListener
    • mouseMoved

      public void mouseMoved(MouseEvent e)
      Specified by:
      mouseMoved in interface MouseMotionListener
    • keyPressed

      public void keyPressed(KeyEvent e)
      Specified by:
      keyPressed in interface KeyListener
    • keyReleased

      public void keyReleased(KeyEvent e)
      Specified by:
      keyReleased in interface KeyListener
    • keyTyped

      public void keyTyped(KeyEvent e)
      Specified by:
      keyTyped in interface KeyListener
    • setPreferredSize

      public void setPreferredSize(int width, int height)
      Set my preferred size to WIDTH x HEIGHT pixels.
    • setMinimumSize

      public void setMinimumSize(int width, int height)
      Set my minimum size to WIDTH x HEIGHT pixels.
    • setMaximumSize

      public void setMaximumSize(int width, int height)
      Set my maximum size to WIDTH x HEIGHT pixels.