Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS221 © 2007 Ray S. Babcock Menus, Toolbars, and a Mouse Appendix C.6-C.7.

Similar presentations


Presentation on theme: "CS221 © 2007 Ray S. Babcock Menus, Toolbars, and a Mouse Appendix C.6-C.7."— Presentation transcript:

1 CS221 © 2007 Ray S. Babcock Menus, Toolbars, and a Mouse Appendix C.6-C.7

2 CS221 © 2007 Ray S. Babcock Menus  Restaurant analogy.  Text is often less ambiguous than pictures.  Frame as in Frame of Reference.  Standard 1 level.  Multi-Level menus and sub-menus.  Popup Menus.  Icons : pictorial reference (not always clear).  Accelerator (key stroke without menu display).  Mnemonic (key stroke shortcut with menu).  Restaurant analogy.  Text is often less ambiguous than pictures.  Frame as in Frame of Reference.  Standard 1 level.  Multi-Level menus and sub-menus.  Popup Menus.  Icons : pictorial reference (not always clear).  Accelerator (key stroke without menu display).  Mnemonic (key stroke shortcut with menu).

3 CS221 © 2007 Ray S. Babcock JMenuItem  Extension of AbstractButton.  Display text or icon.  Fire action events when activated.  Various Constructors  JMenuItem ( ) : no text or icon.  JMenuItem (Icon icon) : with an icon.  JMenuItem (String text) : with text.  JMenuItem (String text, Icon icon) : both.  JMenuItem (String text, int mnemonic) : Text with int ke code defined by KeyEvent.  Extension of AbstractButton.  Display text or icon.  Fire action events when activated.  Various Constructors  JMenuItem ( ) : no text or icon.  JMenuItem (Icon icon) : with an icon.  JMenuItem (String text) : with text.  JMenuItem (String text, Icon icon) : both.  JMenuItem (String text, int mnemonic) : Text with int ke code defined by KeyEvent.

4 CS221 © 2007 Ray S. Babcock JMenuItem (cont.)  Method  void setAccelerator(KeyStroke keystroke) Sets key combination that invokes the menu item’s action listener without showing menu.  Methods Inherited from AbstractButton  void setIcon (Icon icon) : set default icon.  void setText (String text) : set text.  setMnemonic (int mnemonic) : set mnemonic.  void addActionListener (ActionListener l) : Adds an ActionListener to this menu item.  Method  void setAccelerator(KeyStroke keystroke) Sets key combination that invokes the menu item’s action listener without showing menu.  Methods Inherited from AbstractButton  void setIcon (Icon icon) : set default icon.  void setText (String text) : set text.  setMnemonic (int mnemonic) : set mnemonic.  void addActionListener (ActionListener l) : Adds an ActionListener to this menu item.

5 CS221 © 2007 Ray S. Babcock Icons  Confusion : the save file story.  InterfaceIcon  int getIconHeight ( ) : returns icon’s height.  int getIconWidth ( ) : returns icon’s width.  void paintIcon (Component c, Graphics g, int x, int y) : Draw the icon at the specified location using the given graphics context.  Uses an image file (such as.gif or.jpg).  Confusion : the save file story.  InterfaceIcon  int getIconHeight ( ) : returns icon’s height.  int getIconWidth ( ) : returns icon’s width.  void paintIcon (Component c, Graphics g, int x, int y) : Draw the icon at the specified location using the given graphics context.  Uses an image file (such as.gif or.jpg).

6 CS221 © 2007 Ray S. Babcock ImageIcon Constructors (subset)  ImageIcon ( ) : Creates unitialized image icon.  ImageIcon (String filename) Create from file.  ImageIcon (String filename, String description) : create from file with description  ImageIcon ( ) : Creates unitialized image icon.  ImageIcon (String filename) Create from file.  ImageIcon (String filename, String description) : create from file with description

7 CS221 © 2007 Ray S. Babcock Toolbars  JToolBar class  Container that can be horizontal or vertical.  Contains selectable icons.  Alternative to a menu.  Docked or floating.  Like functions grouped together.  C.25 and following code give a three icon example.  Don’t forget to register ActionListeners.  JToolBar class  Container that can be horizontal or vertical.  Contains selectable icons.  Alternative to a menu.  Docked or floating.  Like functions grouped together.  C.25 and following code give a three icon example.  Don’t forget to register ActionListeners.

8 CS221 © 2007 Ray S. Babcock Case Study  Some code missing so we can’t run this.  Look at how menus are built up.  C.26-C.28  Some code missing so we can’t run this.  Look at how menus are built up.  C.26-C.28

9 CS221 © 2007 Ray S. Babcock The Story Of A Mouse

10 CS221 © 2007 Ray S. Babcock Not THAT one, this one.

11 CS221 © 2007 Ray S. Babcock Well, Maybe a little newer

12 CS221 © 2007 Ray S. Babcock WIMP  Windows  Icons  Menus  Pointing device  WIMP HistoryHistory  Another WIMP site.WIMP  Windows  Icons  Menus  Pointing device  WIMP HistoryHistory  Another WIMP site.WIMP

13 CS221 © 2007 Ray S. Babcock Java Mouse  BUTTON1, BUTTON2, BUTTON3  MOUSE_CLICKED : button pressed & released  MOUSE_PRESSED : button pressed  MOUSE_RELEASED : button released  MOUSE_MOVED : position changed  MOUSE_DRAGGED : position changed while button is down  MOUSE_ENTERED : Visible part entered.  MOUSE_EXITED : Visible part exited.  BUTTON1, BUTTON2, BUTTON3  MOUSE_CLICKED : button pressed & released  MOUSE_PRESSED : button pressed  MOUSE_RELEASED : button released  MOUSE_MOVED : position changed  MOUSE_DRAGGED : position changed while button is down  MOUSE_ENTERED : Visible part entered.  MOUSE_EXITED : Visible part exited.

14 CS221 © 2007 Ray S. Babcock MouseEvent selected methods  Point getPoint ( ) : returns x,y position of the event relative to the component that receives the event.  Int getButton ( ) : Returns which, if any, of the mouse buttons has changed state. Possible values are BUTTON1, BUTTON2, BUTTON3, or NOBUTTON.  Point getPoint ( ) : returns x,y position of the event relative to the component that receives the event.  Int getButton ( ) : Returns which, if any, of the mouse buttons has changed state. Possible values are BUTTON1, BUTTON2, BUTTON3, or NOBUTTON.

15 CS221 © 2007 Ray S. Babcock MouseMotionListener  void mouseDragged (MouseEvent e) : invoked when mouse is moved while a button is pressed.  void mouseMoved (MouseEvent e) : invoked when the mouse is moved while no button is pressed.  void mouseDragged (MouseEvent e) : invoked when mouse is moved while a button is pressed.  void mouseMoved (MouseEvent e) : invoked when the mouse is moved while no button is pressed.

16 CS221 © 2007 Ray S. Babcock MouseListener  void mouseClicked (MouseEvent e) : mouse button pressed and released.  void mouseEntered (MouseEvent e) : mouse enters a component.  void mouseExited (MouseEvent e) : mouse exits a component.  void mousePressed (MouseEvent e) : mouse button pressed.  void mouseReleased (MouseEvent e) : mouse button released.  void mouseClicked (MouseEvent e) : mouse button pressed and released.  void mouseEntered (MouseEvent e) : mouse enters a component.  void mouseExited (MouseEvent e) : mouse exits a component.  void mousePressed (MouseEvent e) : mouse button pressed.  void mouseReleased (MouseEvent e) : mouse button released.

17 CS221 © 2007 Ray S. Babcock DrawPanel Class  Table C.19 and Figure C.30  Some things to notice:  Algorithm for stretchMe method.  Write your high level designs in the most familiar language. For most of us, that’s English!  Table C.19 and Figure C.30  Some things to notice:  Algorithm for stretchMe method.  Write your high level designs in the most familiar language. For most of us, that’s English!


Download ppt "CS221 © 2007 Ray S. Babcock Menus, Toolbars, and a Mouse Appendix C.6-C.7."

Similar presentations


Ads by Google