Copyright (c) SEMM NL All rights reserved.
Author : Paul Hamaker. Part of JavaLessons.com
What this is about.
To avoid having to specify full class-names every time, we use import statements.
This enables us to write Applet, instead of java.applet.Applet, as before.
This enables us to write TextArea, instead of java.awt.TextArea .
But also Button, instead of java.awt.Button, if we would want to use that. This is implied by the asterisk character .
First, the applet's constructor is executed,.....
where a java.awt.TextArea is created, showing 4 rows and 20 positions/columns :
The reference to the TextArea object ( memory block / instance ) is stored in ta ,.....
so we can use it .
ta is a reference variable , a variable to refer to an object.
The keyword new is essential to creating.
Then the init method is called, because this is an applet.
Here, a newline character, \n , is added to the text in the TextArea by calling its method append .
Text is added :
Then again a newline character, as separator .
and so on.
The newline character can be combined with text .
The TextArea is placed inside the applet, because
this class, TxAr, extends java.applet.Applet,....
which extends java.awt.Panel,...
which extends java.awt.Container.
So TxAr is also a Container and as such it can contain Components .
After this the applet is told to calculate its layout and update its appearance, if necessary .
In this case, it positions and sizes the TextArea properly.
This import does NOT mean that all java.awt classes are loaded in memory, quite the opposite. In Java, ONLY the CLASSES that are really NEEDED are loaded in memory.
import is just a directive so classes can be found .
This is actually a method in the Container class. More on this in the Inheritance lesson.