That's not a complete program. Java programs must always have a public static void main(String args) method somewhere. When you run the program. that's the method the JVM will call to run the code in your program.
For a graphics program, you'll need some more code to set up a window etc. to draw in. The code you posted is just a small part of a complete graphics program.
Probably this was meant in the book just to show how you would implement the paint() method, and it is not intended as a complete program.