Package ucb.gui2

Class Pad


  • public class Pad
    extends Widget
    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.
    • Field Summary

      • Fields inherited from class ucb.gui2.Widget

        me
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected Pad()
      A new, empty Pad.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int getHeight()
      Return my current height in pixels.
      int getWidth()
      Return my current width in pixels.
      protected void paintComponent​(Graphics2D g)
      Repaint myself on G.
      void repaint()
      Alert the system that I ought be asked to repaint myself.
      void repaint​(int x, int y, int width, int height)
      Alert the system that I ought be asked to repaint the rectangular area whose top left corner is X, Y and has given WIDTH and HEIGHT.
      void repaint​(long tm)
      Alert the system that I ought be asked to repaint myself within TM milliseconds.
      void repaint​(long tm, int x, int y, int width, int height)
      Alert the system that I ought be asked to repaint the rectangular area whose top left corner is X, Y and has given WIDTH and HEIGHT within TM milliseconds.
      void setKeyHandler​(String eventKind, BiConsumer<String,​KeyEvent> func)
      Handle the kind of key event EVENTKIND by calling FUNC's accept method with EVENT and the KeyEvent that describes the event.
      void setMaximumSize​(int width, int height)
      Set my maximum size to WIDTH x HEIGHT pixels.
      void setMinimumSize​(int width, int height)
      Set my minimum size to WIDTH x HEIGHT pixels.
      void setMouseHandler​(String eventKind, BiConsumer<String,​MouseEvent> func)
      Handle the kind of mouse event EVENTKIND by calling FUNC's accept method with EVENT and the MouseEvent that describes the event.
      void setPreferredSize​(int width, int height)
      Set my preferred size to WIDTH x HEIGHT pixels.
      void setSize​(int width, int height)
      Set my current size to WIDTH x HEIGHT pixels.
    • Constructor Detail

      • Pad

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

      • setSize

        public void setSize​(int width,
                            int height)
        Set my current size to WIDTH x HEIGHT pixels.
      • 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.
      • getWidth

        public int getWidth()
        Return my current width in pixels.
      • getHeight

        public int getHeight()
        Return my current height in pixels.
      • repaint

        public void repaint()
        Alert the system that I ought be asked to repaint myself.
      • repaint

        public void repaint​(long tm)
        Alert the system that I ought be asked to repaint myself within TM milliseconds.
      • repaint

        public void repaint​(int x,
                            int y,
                            int width,
                            int height)
        Alert the system that I ought be asked to repaint the rectangular area whose top left corner is X, Y and has given WIDTH and HEIGHT.
      • repaint

        public void repaint​(long tm,
                            int x,
                            int y,
                            int width,
                            int height)
        Alert the system that I ought be asked to repaint the rectangular area whose top left corner is X, Y and has given WIDTH and HEIGHT within TM milliseconds.
      • setMouseHandler

        public void setMouseHandler​(String eventKind,
                                    BiConsumer<String,​MouseEvent> func)
        Handle the kind of mouse event EVENTKIND by calling FUNC's accept method with EVENT 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 EVENT 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.