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

Slides:



Advertisements
Similar presentations
Event handling and listeners What is an event? user actions and context event sources and listeners Why should my programs be event- driven? User interaction.
Advertisements

Handling Mouse Events Event-Driven Programming Approccio standard per programmare GUI In contrapposizione al polling offre: - Maggiore flessibilità - Minor.
Programming in Java; Instructor:John Punin Graphics and Graphical User Interfaces1 Programming in Java Graphics and Graphical User Interfaces.
Graphical User Interfaces (Part IV)
 Specifies a set of methods (i.e., method headings) that any class that implements that interface must have.  An interface is a type (but is not a class).
Mouse Listeners We continue our examination of GUIs by looking at how to interact with the mouse –Just as Java creates Events when the user interacts with.
CS18000: Problem Solving and Object-Oriented Programming.
Graphical User Interfaces, 2D Graphics & Game Programming.
Bar Graph Design. Left-side/Right-side mechanical processing creative, abstract reasoning.
TCU CoSc Programming with Java Handling Events.
Event-Driven Programming You might have realized in creating a GUI and clicking on the JButtons that nothing happens Clicking on a JButton causes the JVM.
Computer Science 209 Graphics and GUIs. Working with Color The class java.awt.Color includes constants for typical color values and also supports the.
Dale Roberts GUI Programming using Java - Mouse Events Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer.
GUI and Swing, part 2 The illustrated edition. Scroll bars As we have previously seen, a JTextArea has a fixed size, but the amount of text that can be.
Jan Event Handling -1.1 Yangjun Chen Dept. Business Computing University of Winnipeg.
1 Inheritance. 2 One class inherits from another if it describes a specialized subset of objects Terminology: inheritschild class subclass –the class.
Event Handling Events and Listeners Timers and Animation.
Slides prepared by Rose Williams, Binghamton University Chapter 18 Applets.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 14 GUI and Event-Driven Programming.
Event Handling. In this class we will cover: Keyboard Events Mouse Events Focus Events Action Interface Multicasting.
Lecture 18 Review the difference between abstract classes and interfaces The Cloneable interface Shallow and deep copies The ActionListener interface,
More on Creating GUIs in Java using Swing David Meredith Aalborg University.
Graphic User Interfaces Part 1. Typical GUI Screen from Microsoft Word What GUI “components” can you see? –Menus? Buttons? Labels? What else? –Anything.
1 CSC111H Graphical User Interfaces (GUIs) Introduction GUIs in Java Understanding Events A Simple Application The Containment Hierarchy Layout Managers.
Chapter 11 Java AWT Part I: Mouse Events (Optional) Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by S.N. Kamin,
More Event Handling Adapters Anonymous Listeners Pop menus Validating User Input.
Java Programming: Guided Learning with Early Objects
Session 11 Border Layout, using Panels, Introduction to PinBallGame.
CSE 501N Fall ‘09 20: Event Handling and Inner Classes 17 November 2009 Nick Leidenfrost.
7/3/00SEM107- © Kamin & ReddyClass 11 - Events - 1 Class 11 - Events r A couple of odds & ends m Component sizes  switch statement r Event types r Catching.
– Advanced Programming P ROGRAMMING IN Lecture 21 Introduction to Swing.
Graphic User Interface. Graphic User Interface (GUI) Most of us interact with computers using GUIs. GUIs are visual representations of the actions you.
MSc Workshop - © S. Kamin, U.Reddy Lect 4 - Events - 1 Lecture 4 – Event Handling r Painting r Event types r Catching different event types.
12/5/00SEM107, Kamin & ReddyReview - 34 Events Event types Catching different event types Getting information from components and events Distinguishing.
Chapter 15: Advanced GUI Topics. Objectives Use content panes Use color Learn more about layout managers Use JPanel s to increase layout options Create.
Graphical User Interfaces (Part 2) 1. View  view  presents the user with a sensory (visual, audio, haptic) representation of the model state  a user.
JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN © 2012 Pearson Education, Inc., Upper Saddle River,
Object-Oriented Software Engineering
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 21.1 Test-Driving the Painter Application.
AGDER COLLEGEFACULTY OF ENGINEERING & SCIENCE GUI Components ikt403 – Object-Oriented Software Development.
UID – Event Handling and Listeners Boriana Koleva
Agenda Introduction. Event Model. Creating GUI Application. Event Examples.
Index Event Handling Events Event Source Event Listener Event Classes Action Event Class Adjustment event Class Event Source Event Listener Interface Using.
Swing - 2 Session 13. Swing - 2 / 2 of 38 Objectives (1) Discuss trees and tables Discuss progress bars Discuss MVC architecture Describe menus.
COSC 4126 User Interaction User Interaction capturing and responding to input events.
Mouse Listeners Moving the mouse will also generate events like the Timer –To have your program respond, you must implement either or both of MouseListener.
(c) by Elizabeth Sugar Boese.1 Chapter 6 Events - Lecture Slides.
Creating User Interfaces Event-Driven Programming.
Lecture 33: More Graphical User Interface (GUI) Announcements & Review Read Ch GU1 & GU2 Cohoon & Davidson Ch 14 Reges & Stepp Lab 10 set game due 4/26.
Rina System development with Java Instructors: Rina Zviel-Girshin Lecture 10.
MT311 Java Application Development and Programming Languages Li Tak Sing ( 李德成 )
What Is an Event? Events – Objects that describe what happened Event sources – The generator of an event Event handlers – A method that receives an event.
Event Handling H_Func(Event) { } Event Receiver Object Source Object Registration.
Slides prepared by Rose Williams, Binghamton University Chapter 19 Swing II.
View  view  presents the user with a sensory (visual, audio, haptic) representation of the model state  a user interface element (the user interface.
Menus Pull-downs and popups. Tooltips –a ToolTip is a context-sensitive text string that is displayed in a popup window when the mouse rests over a particular.
Mouse, Keyboard, Sounds, and Images JavaMethods An Introduction to Object-Oriented Programming Maria Litvin Gary Litvin Copyright © 2003 by Maria Litvin,
Prepared by: Dr. Abdallah Mohamed, AOU-KW Unit7: Event-driven programming 1.
10/20/2005week71 Graphics, mouse and mouse motion events, KeyEvent Agenda Classes in AWT for graphics Example java programs –Graphics –Mouse events –Mouse.
Events and Event Handling
Mouse Event Handling in Java (Review)
Advanced User Interfaces
Computer Science 209 Graphics and GUIs.
Interfaces.
CSE 114 – Computer Science I Event Programming
GUI Programming using Java - Mouse Events
Web Design & Development Lecture 12
Presentation transcript:

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

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).

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.

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.

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).

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

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.

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

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

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

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

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

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.

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.

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.

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.

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!