Hi Thomas,
Can't help on the question of "is there a list of classes and functions that all Java programs automatically import or call?"
As for the use of paint() and why the method is defined if the coding doesn't explicitly call it....
My understanding is (and correct me if I'm wrong) that any object that appears on the screen will have a paint method that draws the object on the screen. Sometimes you'll need to define a paint method. Other times this won't be necessary. Following are a couple of examples which might illustrate this idea.
Eg. of not needing to define a paint method
~~~~~~
If you want a button to appear on the screen, you don't need to define a paint method, as button inherits it's paint method from Component.
Extract from the API Component documentation.
~~~~~~~~~~~~~~~
public void paint(Graphics g)
Paints this component.
This method is called when the contents of the component should be painted in response to the component first being shown or damage needing repair... "
~~~~~~~~~~~~~~
When you make an AWT frame containing the button visible via setVisible(true), one of the things that usually happens is an invocation of repaint(), a method which calls paint(). You don't have to call paint() or even define a paint() method in this case - it's done for you.
Eg. when you'd need to define a paint method
~~~~~~~~~~
You might create a simple AWT frame and wish to display a line of text directly onto the frame (not on the title bar, but within the border of the frame itself), without using a label component. In this case, you could define a paint method and use the Graphics drawString method to display the text at a set position within the frame.
eg.
public void paint(Graphics g){
g.drawString("Text to display", 50,75);
}
Here, you need to define a paint method just to get your text to display. In this case, if you'd instead used a label component, you wouldn't need to define a paint() method, as label (like button) inherits a paint method from Component.
I'm wondering if the example of paint() in the Deitel book does something that's appears programmer defined (eg. like drawing a
string, or filling a shape with colour) and so requires explicit definition of a paint method??
cheerio
rowan