Copyright (c) SEMM NL All rights reserved.
Author : Paul Hamaker. Part of JavaLessons.com
In the source code of the class java.lang.Math we find
.... static final double
PI = 3.14159265358979323846 ;
'final' so PI's value can't be changed inadvertently.
PI is a constant, its name in capitals.
'static' means that there's only one single copy of it.
We can use it by prefixing the name of the class :
In our example, each new instance of OurTF gets its own memory block that contains its ....
plus its colour settings, width, height, position and much more, for it's a subclass of Component.
However, even if there are 10 instances at a given moment, there is only one, single copy of ...
.... stored in memory separately.
Incremented when we construct an OurTF.
Notice the syntax when using it, the class name up front.
This special code block runs right after the class OurTF has been loaded into memory, before any instance has yet been made. Its purpose is to initialize static data.
In this particular case we could have done without it, but we point out its existence if the need arises for more complex statics initialization.
Statics can be used without instantiating !!!!
Same goes for methods that are static, in this example ...
Static methods have an important restriction, they CANNOT access regular, instance variables !!!!
MAXTFS' value is fixed at 15,...
...used when allocating memory for 15 reference variables ( probably 60 bytes ),...
... and to check the index.
CURLY brackets for the static initializer.
Color objects like these are statics, too.
This is a final static.
This is a call to the TextField constructor that takes no arguments.
TextField is this class' superclass.
This is actually a call to the setText method in the TextField class, INHERITED by OurTF class.