CS 221 Menus Toolbars and a Mouse Appendix
CS 221 Menus, Toolbars, and a Mouse Appendix C. 6 -C. 7 © 2007 Ray S. Babcock
CS 221 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). © 2007 Ray S. Babcock
CS 221 JMenu. Item § § Extension of Abstract. Button. Display text or icon. Fire action events when activated. Various Constructors § JMenu. Item ( ) : no text or icon. § JMenu. Item (Icon icon) : with an icon. § JMenu. Item (String text) : with text. § JMenu. Item (String text, Icon icon) : both. § JMenu. Item (String text, int mnemonic) : Text with int ke code defined by Key. Event. © 2007 Ray S. Babcock
CS 221 JMenu. Item (cont. ) § Method § void set. Accelerator(Key. Stroke keystroke) Sets key combination that invokes the menu item’s action listener without showing menu. § Methods Inherited from Abstract. Button § void set. Icon (Icon icon) : set default icon. § void set. Text (String text) : set text. § set. Mnemonic (int mnemonic) : set mnemonic. § void add. Action. Listener (Action. Listener l) : Adds an Action. Listener to this menu item. © 2007 Ray S. Babcock
CS 221 Icons § Confusion : the save file story. § Interface. Icon § int get. Icon. Height ( ) : returns icon’s height. § int get. Icon. Width ( ) : returns icon’s width. § void paint. Icon (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). © 2007 Ray S. Babcock
CS 221 Image. Icon Constructors (subset) § Image. Icon ( ) : Creates unitialized image icon. § Image. Icon (String filename) Create from file. § Image. Icon (String filename, String description) : create from file with description © 2007 Ray S. Babcock
CS 221 Toolbars § JTool. Bar 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 Action. Listeners. © 2007 Ray S. Babcock
CS 221 Case Study § Some code missing so we can’t run this. § Look at how menus are built up. § C. 26 -C. 28 © 2007 Ray S. Babcock
CS 221 The Story Of A Mouse © 2007 Ray S. Babcock
CS 221 Not THAT one, this one. © 2007 Ray S. Babcock
CS 221 Well, Maybe a little newer © 2007 Ray S. Babcock
CS 221 WIMP § § § Windows Icons Menus Pointing device WIMP History Another WIMP site. © 2007 Ray S. Babcock
CS 221 Java Mouse BUTTON 1, BUTTON 2, BUTTON 3 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. § § § © 2007 Ray S. Babcock
CS 221 Mouse. Event selected methods § Point get. Point ( ) : returns x, y position of the event relative to the component that receives the event. § Int get. Button ( ) : Returns which, if any, of the mouse buttons has changed state. Possible values are BUTTON 1, BUTTON 2, BUTTON 3, or NOBUTTON. © 2007 Ray S. Babcock
CS 221 Mouse. Motion. Listener § void mouse. Dragged (Mouse. Event e) : invoked when mouse is moved while a button is pressed. § void mouse. Moved (Mouse. Event e) : invoked when the mouse is moved while no button is pressed. © 2007 Ray S. Babcock
CS 221 Mouse. Listener § void mouse. Clicked (Mouse. Event e) : mouse button pressed and released. § void mouse. Entered (Mouse. Event e) : mouse enters a component. § void mouse. Exited (Mouse. Event e) : mouse exits a component. § void mouse. Pressed (Mouse. Event e) : mouse button pressed. § void mouse. Released (Mouse. Event e) : mouse button released. © 2007 Ray S. Babcock
CS 221 Draw. Panel Class § Table C. 19 and Figure C. 30 § Some things to notice: § Algorithm for stretch. Me method. § Write your high level designs in the most familiar language. For most of us, that’s English! © 2007 Ray S. Babcock
- Slides: 17