CSCI E-70
HarvardUniversityExtensionSchool

Spring 2004

Java for Graphical User Applications

Lecture 3 Outline

16 Feb 2005

  1. The Basis for all Swing Graphical Interface building blocks: JComponentHierarchy
  2. java.lang.Object – 11 methods:
  3. synchronization: multiple threads or GC thread:6
  4. identity: distinguising/distinguishing/outputting/type:5
  5. java.awt.Component
  6. 206new methods:
  7. deprecated methods: 35
  8. AWT only (not used if only lightweight used): 19
  9. 2 – popups
  10. 2 – native peer
  11. 9 – image
  12. 4 – event
  13. 2 – drag and drop
  14. internals or rarely used: 56
  15. 4 – layout
  16. 3 – properties
  17. 11 – painting management
  18. 11 – event propagation, processing
  19. 17 – obscure focus manipulations
  20. 9 – rarely used listeners
  21. likely to use or at least of interest:96
  22. 25 – commonly used listeners
  23. 8 get, 8 remove, 8 add, 1 special
  24. 2 – painting management
  25. paint(), repaint()
  26. 25 – geometry and layout (setting/querying)
  27. e.g. setWidth(), getAlignmentX()...
  28. 20 – appearance
  29. 10 getters, 10 setters
  30. e.g.: setFont(), getBackground() ...
  31. 8 – properties
  32. 4 queriers/getters(), 4 setters
  33. e.g.: setEnabled, setName()...
  34. 7 – debugging
  35. paramString(), toString(), list()...
  36. 7 – internationalization / accessibility
  37. 2 input-method related (but not listeners)
  38. get/setLocale()
  39. get/setComponentOrientation()
  40. getAccessibleContext()
  41. 2 – printing
  42. A quiet workhorse: capabilities confused with JComponent
  43. much overridden/deprecated/non-lightweight
  44. but a lot of basics still important: listeners, properties, geometry, repaint()...
  45. see in JComponent: “Methods inherited from Component”
  46. java.awt.Container – 69 new methods: two broad categories
  47. managing containment
  48. add, remove direct children
  49. propagate layout changes up/down hierarchy
  50. control propagation
  51. find components based on position
  52. who would use these methods?
  53. overriding various Component methods to be container-like
  54. printing
  55. sizing
  56. debugging
  57. doing property changes differently (new properties!)
  58. javax.swing.JComponent
  59. 339 total methods (remember, many deprecated/internal/rare)
  60. 10 inherited from Object
  61. 137 inherited from Component
  62. 51 inherited from Container
  63. 69 overridden from Component
  64. 18 overridden from Container
  65. 53 brand new ones
  66. 8 broad categories of new ones, in order of importance for us
  67. Borders/Insets
  68. Client properties (extensible!)
  69. Double buffering – avoid flicker
  70. Opacity management (very simple)
  71. Keystroke handling
  72. Tooltips
  73. Focus management (actually mostly in Component)
  74. Other (will not be covering unless time allows)
  75. Accessibility support
  76. Debug Graphics
  77. Auto-Scrolling
  1. The JComponent architecture
  2. Inheritance used sparingly (only one parent!)
  3. Components concrete and useful out-of-the-box
  4. lots of model/listener instantiation & setup done for you
  5. but all can be overridden
  6. sizing example, p. 141
  7. this IS object-oriented programming; you choose your level of customization!
  8. change value of a property
  9. compose new object into collection
  10. override individual methods
  11. add data members, write new methods
  12. write own minor classes:
  13. new event types
  14. write own major class: model, UI delegate, CellRenderer:
  15. bare, from the requisite base class or interface
  16. write own class suitefrom scratch
  17. JComponent
  18. Look and Feel / Theme
  19. wacky stuff
  20. custom 2-D rendering, image manipulation
  21. native 3-D rendering
  22. Everything Else in the World: tying it to your GUI...:-)
  23. invalidate, revalidate, validate, paint, repaint: sorting it out
  24. Borders
  25. composability
  26. factory design pattern
  27. insets and paint() vs paintComponent()
  28. Client Properties
  29. can avoid subclassing, stay flexible
  30. bound -- implications
  31. Double buffering – offscreen rendering
  32. Opacity control – background painted?
  33. Keystroke – example
  34. Tooltips – example 4.18
  35. Focus – basics, focusRoot
  36. Brief description of accessiblity, debug graphics, auto-scroll
  37. The Basic JComponents: Labels and Buttons
  38. Lots of overlap in functionality
  39. text
  40. images
  41. relative & absolute alignment, spacing control
  42. think of label as non-interactive button
  43. default button properties – p. 392
  44. Overview of remainder of hierarchy (Ch. 9)
  45. ToggleButtons
  46. checkboxes
  47. radio buttons
  48. mutually exclusive grouping
  49. A complex JComponent: JList
  50. Get to know models for real now: ListModel
  51. Customizable at interface, abstract, or concrete level
  52. Very simple concept
  53. Emphasize model/UI separability: the Contract
  54. Scroll containment: JScrollPane
  55. must set size
  56. is a validation root!
  57. Example code: 17-2: Using a DefaultListModel (concrete impl. of ListModel)
  58. First component with:
  59. open-ended choices on data representation
  60. need not be one actual object per list item
  61. need not be a Vector or array, even if so
  62. data model that generates events useful to others: when data changes
  63. multiple models: also a ListSelectionModel: a GUI state model!
  64. customizable smaller units: CellRenderers (oh no! more later)
  65. new listeners of interest to handle selections: ItemListeners

– Page 1 of 3–