CS1020 - PowerPoint PPT Presentation

1 / 12
About This Presentation
Title:

CS1020

Description:

... a button, presses Enter while typing in a text field, or chooses a menu item ... mouseMoved mouse moved while button up. Point location info in MouseEvent ... – PowerPoint PPT presentation

Number of Views:37
Avg rating:3.0/5.0
Slides: 13
Provided by: drmarkh
Category:
Tags: cs1020

less

Transcript and Presenter's Notes

Title: CS1020


1
The javax.swing package contains several classes
used for creating Menus
  • JMenuBar, JMenu, JMenuItem (and variants)
  • JRadioButtonMenuItem
  • JCheckboxMenuItem
  • Only the JMenuItem objects (and variants)
    generate events.

2
JMenuItems generate Action Events
3
JMenuBar
  • JMenuBar is a bar where the menus are placed.
  • There is only one menu bar per frame.

4
JMenu
  • JMenu (such as File or Edit) is a group of menu
    choices.
  • A JMenuBar object may include many JMenu objects.

5
JMenuItem
  • JMenuItem (such as Copy, Cut, or Paste) is an
    individual menu choice in a JMenu object.
  • Action command defaults to text of menu item
  • Override with call to setActionCommand()
  • Useful when providing UI in multiple languages

6
Demo
  • Menus

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

8
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 is called inheritance coming soon
  • This implies similar behavior for these classes

9
Check boxes
  • Implemented by JCheckBox
  • A GUI usually permits more than one Check box to
    be selected at one time

10
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

11
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
  • or whoever is interested in getting events

12
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
Write a Comment
User Comments (0)
About PowerShow.com