=====
TODAY WE WILL
=====
* announcements
* intro to threads (and a little Graphics in Java...)
* prep for next class!
* still in (reading)
* Chapter 12 - Section 12.1, 12.2, 12.3
* Chapter 10 - Section 10.3
* FIRST: a few words about Graphics and Swing...
FIRST thing:
* paint your graphics on another component BESIDES a JFrame, please!
(JFrames are reallllly intended to be a container of containers...)
* JPanels work very nicely to be painted upon
SECOND thing:
* to paint/draw on a JComponent (such as a JPanel),
you OVERRIDE the inherited paintComponent method in your
subclass component you wish to paint/draw on
* void method
* has an argument! An object of type Graphics
* course text, p. 576:
"All drawing in Java must go through a Graphics object."
THIRD thing:
* YOU don't call paintComponent! (So YOU don't have to worry
about creating or comping up with its Graphics argument!?!?)
IT is called AUTOMATICALLY whenever a part of the application
needs to be redrawn -- you SHOULD NOT INTERFERE with this
automatic process (also noted on p. 576)
* wait -- what if you WANT to repaint the screen?
You call the method
repaint(); <-- no arguments! a method the JComponent inherits!
* p. 576: "The repaint method will cause paintComponent to be
called for all components, with a properly configured Graphics
object."
* Measurement on a Graphics object for screen display is done in
pixels
* The (0, 0) coordinate denotes the top-left corner of the component
on whose surface you are drawing
* [is this still recommended?]
I was originally taught that it was good/wise to call the inherited version
of paintComponent as the first statement in my overridden paintComponent:
public void paintComponent(Graphics g)
{
super.paintComponent(g);
// then your code to paint/draw what you want...
* a few selected Graphics methods:
setFont -- expects a Font argument, that becomes the font used
for painted strings;
setColor -- expects a Color argument, that becomes the color for
stuff drawn
drawString -- expects a string-to-draw, pixel-loc-x-of-bottom-left,
pixel-loc-y-of-bottom-;eft
that's where the given string is drawn
* Swing is not thread-safe?!?
that is: if you try to manipulate user interface elements from
MULTIPLE threads, then your user interface can become
corrupted;
* this is the reason we construct our JFrame subclasses in the
event dispatch thread in our Java GUI applications, I believe;