Java Reference
In-Depth Information
We will change the label's text later with the information in the Employee object.
2.
In the EmpFrame constructor, before the statement that adds empNameLbl to the frame,
define the two labels so that:
A.
They are the same length and height as empNameLbl
B.
empStreetLbl is 40 pixels beneath empNameLbl
C.
empCSZLbl is 80 pixels beneath empNameLbl
If you are unsure how to do this, see the earlier discussion of the setBounds statement.
3.
After the statement that adds empNameLbl to the frame, enter two statements to add the
two new labels to the frame.
The executable source code should look like the following:
package c3;
import java.awt.Frame;
import java.awt.Label;
public class EmpFrame extends Frame {
Label empNameLbl = new Label("My First Label");
Label empStreetLbl = new Label("New label");
Label empCSZLbl = new Label("New label");
public EmpFrame(Employee emp) {
empNameLbl.setBounds(100, 150, 150, 20);
empStreetLbl.setBounds(100, 190, 150, 20);
empCSZLbl.setBounds(100, 230, 150, 20);
this .add(empNameLbl);
this .add(empStreetLbl);
this .add(empCSZLbl);
this .setTitle("New Frame Title");
this .setLayout( null );
this .setBounds(10, 10, 300, 300);
this .setVisible( true );
}
}
4.
Save the source code and verify that there are no errors.
Just because RAD is not displaying any error messages does not mean that the code is correct. You really need to
test that the correct results will be produced and, if the results are not correct, find the errors. The best/easiest way to
find errors is to follow the “code a little, test a little” (CALTAL) style of programming. Many beginning programmers try
to enter all the source code at one time and are often then overwhelmed by all the errors. An easy way to avoid that is
to test frequently after adding or changing code. Therefore, at this point, we will run the code and verify that it works
correctly.
5.
Run EmployeeApp.
Search WWH ::




Custom Search