CM10135 / Programming II:   Lecture 12

Components, Layouts, Panes, Listeners etc.

I. House Keeping

  1. Coursework 2 notes (save for next week):
    1. The hard parts of the assignment should be:
      1. Just learning all the Java components (not that hard, just time consuming).
      2. Putting all the pieces together.
    2. Basically, nothing should be hard in particular, it's just a lot of practice, which is what you need.
    3. Might make networking like the extras -- do any one for a good pass, any two for a distinction.
  2. If you are really having trouble coding, spend time with the tutors in lab!
    1. There's no reason that the tutors should ever be alone while they are in lab.
    2. They get paid for being there.
  3. finish listeners from last time

VI. Listeners

  1. ActionListener -- actionPerformed (button press, slider moved, etc)
  2. FocusListener -- focusGained (FocusEvent e), focusLost.
    1. Focus is basically where you can type, as in "focus of attention".
    2. You can also make a widget request the focus (like Google does in its search window) JComponent.requestFocus()
  3. MouseListener (MouseEvent e)
  4.  void mouseClicked(MouseEvent e)
              Invoked when the mouse button has been clicked (pressed and released) on a component.
     void mouseEntered(MouseEvent e)
              Invoked when the mouse enters a component.
     void mouseExited(MouseEvent e)
              Invoked when the mouse exits a component.
     void mousePressed(MouseEvent e)
              Invoked when a mouse button has been pressed on a component.
     void mouseReleased(MouseEvent e)
              Invoked when a mouse button has been released on a component.
    1. MouseMotionListener
       void mouseDragged(MouseEvent e)
                Invoked when a mouse button is pressed on a component and then dragged.
       void mouseMoved(MouseEvent e)
                Invoked when the mouse cursor has been moved onto a component but no buttons have been pushed.
  5. Also table, menu & hyperlink listeners, many others.

II. Containers &Panes

  1. This lecture is mostly out of the Java Tutorial, because that way I got all the running components for free.
    1. This may seem like the laziest lecture of all time, but honest, I spent a lot of time looking for better solutions & then deciding what to show you after I decided how to show it...
    2. For you guys the tutorial for swing starts on, but these links are for my laptop. 
    3. Best to start here, show the path file:///Users/j2bryson/Documents/java%20docs/tutorial%20Folder/uiswing/index.html
  2. file:///Users/j2bryson/Documents/java%20docs/tutorial%20Folder/uiswing/components/components.html
  3. skip applets, get them Tuesday
  4. dialogs --
    1. remind them they've seen one of the default ones at the top if they ran the code from the last lecture.
    2. show them everything on the run dialog demo, then show them the code for a few things.
      1. code is a couple screens past the demo, just before screen shots.
    3. we'll be doing radio buttons etc. later, see how they work.
  5. Frame --
    1. already saw basics last week,
    2. but show first & last set of methods
      1. diff exits, icon -- see notes too
      2. show & talk about the different panes.
  6. skip down to "special purpose containers"
    1. show pane drawing,
    2. explain glass pane again,
    3. go into layered panes, show demo
  7. go back up to GP containers
  8. skip panels until talk about layouts
  9. show scroll pane -- show demo
    1. show basic call to scroll pane at top - arg is another pane
    2. go down to show how scroll panes are themselves made of other components -- you could really build your own.
    3. might want to use scroll panes for problem set.
  10. show split pane demo
  11. offer tabbed pane demo, prob not
    1. cool thing is the dragging

III. Components

  1. button
    1. show basic demo,
    2. explain disabled / enabled concept
    3. show
      1. mnemonic
      2. tool tips
    4. can't always use glass pane! often some options make sense in some circumstances.
    5. e.g. can't edit or graph file before you've chosen it.
    6. show radio buttons / single option
    7. show check buttons / multiple options.
    8. emphasize these are universals
  2. show list
    1. maybe show demos (time?)
    2. show the selection model part!
  3. show combo box
    1. like radio buttons but takes less space
    2. editable one doesn't seem to work
  4. show slider
    1. not demo, just code is enough, right after first demo/picture
  5. spinner
    1. demo is kind of cool if time -- stops you from giving wrong answer, advances from right one
    2. for sure go down & show the stuff about models (remember model, view controller?)
  6. text field
    1. go in and show the different types of text fields
    2. when done, click on formatted & show the example formats quickly
  7. Wave at uneditable displays -- no time to really go in to it & it's obviousl
  8. wave at most of interactive displays, but go into text
    1. go down to the table of types of text components,
    2. point out text panes are darn useful for coursework
    3. show demo

IV. Layouts

  1. got to go way up to where you had clicked on "using swing components", then down two to layouts, visual guide
    1. file:///Users/j2bryson/Documents/java%20docs/tutorial%20Folder/uiswing/layout/visual.html
    2. for you folks:
  2. one they saw before was grid, probably the most boring
  3. most generally useful / quick is border
    1. need directions
    2. center expands to fit
  4. flow layout is really easy
  5. box layout is too,
    1. a lot like panels
    2. can make vertical boxes of horizontal panels, kind of like grid
  6. grid bag a bit more complicated, flexible
  7. spring layout for nice fancy things
    1. runnable demo is way down on 3rd one for some reason.

V. Summary

  1. talked about listeners quickly, then showed containers & panes, components, layouts
  2. You should play with them & look at the documentation!

page author: Joanna Bryson
10 March 2004