1 / 15

Advanced User Interfaces

Advanced User Interfaces. Additional Swing components. Edit. View. Help. The javax.swing package contains several classes used for creating menus. JMenuBar Jmenu JMenuItem (and variants): JRadioButtonMenuItem JCheckboxMenuItem. Edit. View. Help.

stesch
Download Presentation

Advanced User Interfaces

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Advanced User Interfaces Additional Swing components CS-1020 Dr. Mark L. Hornick

  2. Edit View Help The javax.swing package contains several classes used for creating menus • JMenuBar • Jmenu • JMenuItem (and variants): • JRadioButtonMenuItem • JCheckboxMenuItem CS-1020 Dr. Mark L. Hornick

  3. Edit View Help JMenuBar is where the menus are placed There is only one JMenuBar per JFrame. JMenuBar CS-1020 Dr. Mark L. Hornick

  4. Edit View Help JMenu (such as “File” or “Edit”) is a group of menu choices A JMenuBar object may include many JMenu objects.JMenu object become visible/invisible automatically. A “File” JMenu object in a JMenuBar CS-1020 Dr. Mark L. Hornick

  5. Edit View Help A JMenuItem (such as New, Open, or Quit) is an individual menu choice in a JMenu object JMenuItem’s can be visually grouped by adding JSeparator’s to a JMenu “Open” JMenuItem JSeparator CS-1020 Dr. Mark L. Hornick

  6. Edit View Help Only the JMenuItem objects (and variants) generate events. A JMenuItem’s Action Command defaults to the text of menu item • Override with call to setActionCommand() • Useful when providing UI in multiple languages CS-1020 Dr. Mark L. Hornick

  7. JMenuItems generate Action Events CS-1020 Dr. Mark L. Hornick

  8. Sequence for Creating Menus • Create a JMenuBar object and add it to a frame via setJMenuBar() • Create a JMenu object. • Create JMenuItem objects and add them to the JMenu object. • Add the JMenu object to the JMenuBar object. CS-1020 Dr. Mark L. Hornick

  9. Demo • Menus CS-1020 Dr. Mark L. Hornick

  10. Radio buttons and Check boxes • Along with JButton, Radio buttons and Check boxes are all specific kinds of buttons – they all derive from the AbstractButton class • This implies similar behavior for these classes • These all generate Action Events CS-1020 Dr. Mark L. Hornick

  11. Check boxes • Implemented by JCheckBox • A GUI usually permits more than one Check box to be selected at one time CS-1020 Dr. Mark L. Hornick

  12. Radio Buttons • Implemented by JRadioButton • A GUI usually prevents more than one Radio button to be selected at once • Typically used along with a ButtonGroup object • ButtonGroup takes care of deselecting the previous Radio button when a new one is selected CS-1020 Dr. Mark L. Hornick

  13. Mouse Events CS-1020 Dr. Mark L. Hornick

  14. Mouse Events • Mouse events arise from such user interactions as • moving the mouse • dragging the mouse (moving the mouse while the mouse button is being pressed) • clicking the mouse buttons. • Who listens for Mouse Events? • JFrame • ContentPane • JPanel • … or whoever is interested in getting events CS-1020 Dr. Mark L. Hornick

  15. Handling Mouse Events • A MouseListener handles most mouse events: • mouseEntered – cursor crossed into the boundary • mouseExited – cursor crossed out of the boundary • mousePressed – button down (specifics in MouseEvent) • mouseReleased – button up • mouseClicked – button down/up in quick succession • A MouseMotionListener handles mouse movement • mouseDragged – mouse moved while button down • mouseMoved – mouse moved while button up • Point location info in MouseEvent • Location is relative to the listening components origin CS-1020 Dr. Mark L. Hornick

More Related