Java Reference
In-Depth Information
In addition to the comments, RAD generates the following code:
package
c3;
import
java.awt.Frame;
public class
EmpFrame
extends
Frame {
}
Notice that RAD included the correct import statement and placed the
extends
keyword in the header to define
EmpFrame as a subclass of
Frame
.
Congratulations; you have defined EmpFrame as a subclass of
Frame
. Of course, EmpFrame doesn't do anything,
but it will after we set the properties, and add some components and methods.
Tutorial: Defining and Adding a Label
We need to create a label (to display the employee name) and add it to EmpFrame. The following statements will do that:
A.
Import the java.awt.Label class
B.
Create a
Label
object and variable and assign the object to the variable
C.
Define the label text
D.
Define the label size
E.
Define the label location
F.
Add the label to the frame
1.
Add the following import statement after the already existing import statement:
import
java.awt.Label;
We will create a label and assign it to a class variable called empNameLbl.
2.
Inside of the EmpFrame class, enter the following statement:
Label empNameLbl =
new
Label("My First Label");
This statement does three things:
A.
Creates a
Label
object with the text “My First Label”
B.
Creates a
Label
variable called empNameLbl
C.
Assigns the object to the variable
3.
Insert the following code after the label statement:
public
EmpFrame(Employee emp) {
}