static. Except for some utility methods and
main(...), you should probably not be using static methods. A good example of a static methods in Java is the Math or Character classes. For example, the
Math.cos(x)method calls the cosine method in the Math class. Cosine takes only one (primitive) parameter, and it doesn't work on any object. Make a call to a static method by putting a class name and a dot in front of the method call.
init()method. The JApplet class already has an
init()method which you are overriding. When the browser calls
init(), it will then call your version of the method. In this case you need to write
init()in JApplet does nothing. Similarly, JPanel's
paintComponent()method is overridden when you declare a JPanel for drawing.
All calls go to your new method, and not to the method by the same name
in the parent class. To call the method in the parent class, as you must
do in the first line of
paintComponent(), prefix the call with
You can also define a method in one class that has the same signature (name and parameters) as the method in a different class. This is not called overloading, and there can be no confusion because the object in front of the method identifies which class the method is in.