Lecture 5

Topics

1. Basics of Graphical Display
2. Separation of Model and the View
3. The Graphics2D class

Additional Notes

1. Basics of Graphical Display
  • take-home message: graphical display entails a considerable amount of low-level hardware detail; it is desirable to encapsulate all of that low-level detail and then to deal with the graphical display at a more abstract level
  • computer displays consist of pixels (picture elements), which is the smallest single component of a digital image. They are normally arranged in a regular two-dimensional grid (possibly staggered).
  • The number and arrangement of the grid depends upon the display (e.g., VGA display of 640x480 vs higher-end display of 1920×1200). The number of distinct colors that can be represented by a pixel depends on the number of bits used to specify each pixel's value. One bit means two possible values, so 1 bit per per pixel means that the graphics sub-system can either turn the pixel on or off (think of early-generation e-ink, although e-ink is now capable of having multiple possible pixel values). Larger number of bits per pixel mean a larger range of colour. Don't assume that the number of bits per pixel is eveny divided among the colours sub-components (e.g., the red, blue, and green element of the pixel). Some colours get a smaller range of possible values (this tailors the display to the properties of the human vision, for which the ability to distinguish among close shades depends on the particular color - e.g., red vs blue).
  • Think of what this means for display - suppose I wanted to cause a circle to appear in the middle of my display window, where the diameter of the circle is half of the available height. To do so, I would need to determine the total amount of real estate, where is the middle, how many pixels there are (in order to map the middle to a particular pixel), identify all of the pixels involved, figure out how to refer to the pixels, figure out what number corresponds to the colour I want etc. It would be much easier if there were an intermediary who I could ask - draw me a circle with center (x,y) and diameter d. The intermediary would be in charge of carrying out that instruction. This is what the Graphics2D object does - it encapsulates the graphics system and provides an API to us so that we can specify instructions.

2. Separation of Model and the View
  • recall that we are learning about the separation of the view and the model. Recap: what is a "view"? A view is a visual representation - it must convey the state of the system to the user; it is the basis for the user's perceptions about what the system might allow them to do, as well as his/her perceptions about the consequences, if any, of their actions upon the system.
  • In practical terms, a view is actually a hierarchy of interactive elements, where those interactive elements are commonly referred to as widgets.
  • Work through several eg's of interfaces - identifying all of the widgets, discussing them, and building the widget hierarchy.
  • The take-home point is that our view needs a root, and the JFrame class provides the services that we need (in terms of being able to be displayed, being able to add widgets to it).
  • Discussed events as being dispatched depending on the user's actions (e.g., mouse presses, button activations, scroll sliding, etc)


3. The Graphics2D class
  • Refer to sec 8.1.6 and lab 8.2.
  • Discuss services of UniPanel.
  • Develop app Draw.java (available as course eg).