1 / 16

COP 4331 – OOD&P

COP 4331 – OOD&P. Lecture 5. TYJ Day 11 – Layout. A Layout Manager determines placement of components Flow Layout Grid Layout Border Layout Card Layout Grid Bag Layout. Flow Layout. class FlowLayout Data flows across rows depending on what will fit

Download Presentation

COP 4331 – OOD&P

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. COP 4331 – OOD&P Lecture 5

  2. TYJ Day 11 – Layout • A Layout Manager determines placement of components • Flow Layout • Grid Layout • Border Layout • Card Layout • Grid Bag Layout

  3. Flow Layout • class FlowLayout • Data flows across rows depending on what will fit • FlowLayout.LEFT, CENTER, RIGHT as parameter to constructor sets alignment • See Alphabet.java

  4. GridLayout • Grid Layout divides panel into rectangular grid and places components in each cell • Uniform spacing • class GridLayout(r, c)

  5. Border Layout • Border Layout creates 5 positions, north and south span area, west, center, and east fill space between • class BorderLayout • Component positioning specified with parameters “North”, “South”, etc. • See Border.java

  6. Mixing Layouts • A panel can be entered as a pane to produce a hierarchical layout • Add items to the subpanel and then add it to the next level at the desired place

  7. Card Layout • Each component acts like a card in a stack of cards • First component added is on top, etc. • Can navigate up and down stack • class CardLayout

  8. Grid Bag Layout • Gives precise and detailed control of placement • Size and layout determined by GridBagConstraints object for each component • Specify position and cells spanned, relative size, and other characteristics • class GridBagLayout

  9. Grid Bag Layout.2 • Plan component layout and draw grid that bounds all component areas, with some components spanning several cells • class GridBagConstraints • gridx, gridy • gridwitth, gridheight • weightx, weighty • Utility function buildConstraints() from text • See NamePass.java

  10. TYJ Day 12 – User Input • Event Listeners are used to detect user interaction with a frame • ActionListener - KeyListener • AdjustmentListener - MouseListener • FocusListener -MouseMotionListener • ItemListener - WindowListener • Each type listens for a particular class of events

  11. Setting Up Listeners • One must add listeners to components • addActionListener() • JButton, JCheckBox, JComboBox, JtextField, JRadioButton, JMenuItem • addAdjustmentListener() • JScrollBar • addFocusListener() • All • addItemListener() • JButton, JCheckBox, JComboBox, JRadioButton

  12. Setting Up Listeners • addKeyListener() • All • addMouseListener() • All • addMouseMotionListener() • All • addWindowListener() • JWindow, JFrame

  13. Event-Handling Methods • Each Listener interface requires certain event-handling methods • Action Listener users • actionPerformed(ActionEvent evt) • The event object contains information about the particular action • See TitleChange.java

  14. Event-Handling Methods.2 • Adjustment Events • adjustmentValueChanged(evt) • Determine type of change and current value • See WellAdjusted.java • Focus Events • focusGained() and focusLost() • Item Events • itemStateChanged() • See SelectItem.java

  15. Event-Handling Methods.3 • Key Events • keyPressed(evt), keyReleased(evt), keyTyped(evt) • Mouse Events • mouseClicked(evt), Entered, Exited, Pressed, Released • Mouse Motion Events • mouseDragged(evt), mouseMoved(evt)

  16. Event-Handling Methods.4 • Window Events • windowActivated(WindowEvent), Closed, Closing, Deactivated, Deiconified, Iconified, Opened • Complete sample application • See SwingColorTest.java

More Related