CM10135 / Programming II:   Lecture 15


Components, Layouts, Panes, Listeners etc.


-I. House Keeping

  1. Coursework 2 notes:
    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.
  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. People last year were overly worried about CW2.  I want to address some possible falicies:
    1. Q: CW2 involves knowing and doing too many different things!
      1. A:  CW2 only suggests doing a lot of things.  You only need to do 3 or 4 of them to get an excellent mark.
    2. Q: you need to already know Java to do well on CW2.
      1. A: No, you can learn enough to do well if you've been keeping up with lectures & you have been putting the time you are supposed to (about 7 hours a week) into the course work.
      2. A: The reason there are so many different things you can do is that you can pick which parts of the most recent content are most interesting to you & try to get extra marks with them.  Though some things are mandatory.
    3. Q:  But it does help if you already know how to do Java.
      1. A:  Yes, and it helps your mark in Spanish if you're already fluent in Spanish / go to Spain every summer.
        1. That's the way it ought to be --- the whole point of assessing coursework is to see if you know how to program, not to find out where you learned!
        2. Though that is one reason why MIT used to teach people Scheme instead of a  more popular language.
    4. Q:  Well,  I think CW2 is much too easy!
      1. A: The point isn't just to get marks.
        1. The main point is to learn.  That's why you're here.
        2. If you build something cooler than you can get marks for, you can always put it on your web page & show it off to potential employers, your parents, or (geeky) dates.
  4. The most important thing for tackling a big problem like CW2 is to develop the code iteratively.
    1. Think about what you need to do & what you want to do.
    2. Figure out a piece you can do first, that you can test without having gotten everything else working.
    3. Build that piece.
    4. Test that piece & fix it until it works.
    5. Now go back to step I.2.1!
      1. You'll have learned things about the problem and the solution, so you want to think about the problem again before you choose the next piece to do.
  5. Don't forget this is a double unit.
    1. Counts for twice as much as your other units.
    2. Should get twice as much of your time.
  6. Programming is an art.  Practicing is the only way to get better.
  7. finish listeners if didn't last time

 I. Review

  1. Remember the kinds of things we saw when building the window yesterday...
  2. Frame
  3. Widgets (small components)
  4. Layout
  5. Listener
  6. Remind students what these are for!
  7. Now we're going to look at how to look up and find stuff that you can use to build into your system.  (except not about listeners, go to yesterday's lecture to see about them.

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 http://java.sun.com/docs/books/tutorial/uiswing/, but these links are for my laptop. 
    3. Best to start here, show the path file:///Users/j2bryson/Documents/java%20tutorial%20Folder/uiswing/index.html
  2. Start with componenths --> visual introduction
    1. file:///Users/j2bryson/Documents/java%20docs/tutorial%20Folder/uiswing/components/components.html
    2. http://java.sun.com/docs/books/tutorial/uiswing/components/components.html
  3. Top level containers
    1. skip applets, get them Tuesday
    2. 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, or through link.
      3. we'll be doing radio buttons etc. later, see how they work.
      4. Be sure to show modal stuff, leads to glass pane below...
    1. Frame --
      1. already saw basics yesterday,
      2. but show first & last set of methods
        1. diff exits, icon -- see notes too
        2. show & talk about the different panes. No longer sensible from this page!
  4. skip down to "special purpose containers"
    1. show pane drawing,
    2. explain glass pane again,
    3. go into layered panes, show demo
  5. go back up to GP containers
  6. skip panels until talk about layouts
  7. 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.
  8. show split pane demo
  9. 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:  http://java.sun.com/docs/books/tutorial/uiswing/components/components.html
  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
  9 March 2006