Java Reference
In-Depth Information
this .setSize( new Dimension(400, 450));
this .setTitle("Employee Information");
this .setBackground(Color. lightGray );
this .add(nameLbl, null );
}
}
Let's examine some of the VE coding standards.
Inside the constructor, VE explicitly calls the superclass's constructor ( super(); ). We mentioned earlier that
the JVM does this automatically. However, it is slightly more efficient to call it explicitly, so that's what VE does.
VE creates a method called initialize that sets the frame's property values and adds the components. Notice
the new setter setBackground. VE added this statement when we defined the background property. The color name
( Color.lightGray ) brings up an interesting point regarding importing. Normally we have imported classes
(e.g., Label , Frame ) and then created objects of these classes. In this case, we imported the class Color but
specified (used) a specific variable (lightGray) within the class. Obviously, lightGray is a public variable!
In the constructor, the initialize method is invoked by its name alone. We have been using the prefix “this”
before all class methods (for instance, this .add or this .setSize) to clearly define what object the method belongs to.
In actuality, the JVM assumes any unqualified method (or variable) names belong to the current object. So, setSize or
setTitle can be used (instead of this .setSize or this .setTitle) and work correctly.
VE also uses Point and Dimension objects to hold the x, y coordinates for locations, and sizes rather then simply
specify the coordinates. Lastly, notice that when adding the label component a value of null is also passed. When
using layout managers, you can specify where components are added with an index value (e.g., in Border layout you
could specify East, West, North, South, or Center). Because EmployeeFrame does not use a layout manager,
RAD explicitly specifies null , even though null is assumed.
To sum up, sometimes VE is overly explicit (i.e., VE doesn't use short cuts). But, as VE is typing the code,
the programmer should be able to accept RAD's little eccentricities.
5.
Minimize the source code pane to redisplay the Design area.
Tutorial: Adding to the Frame
We now need to add the frame:
1.
Add two more labels and accept the default names.
2.
Move and resize the labels so that they look similar to Figure 4-10 .
Notice the label names assigned by VE (see the arrow in Figure 4-10 ).
 
Search WWH ::




Custom Search