Label Help
Help is available for each task,
or you can go straight to the Label
source code to see a
solution.
Task 1
Create an applet called LabelTest and set the layout manager to GridLayout(3,1).
Using a GridLayout will stretch the region inhabited by our labels to the applet width. In this way, the Label.CENTER etc. attributes will be obvious.
import java.awt.*;
public class LabelTest extends java.applet.Applet {
public void init() {
setLayout(new GridLayout(3,1));
}
}
Task 2
Create and add three Label objects with labels "Left label", "Right label", and "Center label," aligned to the left, right, and center respectively.
public class LabelTest extends java.applet.Applet {
public void init() {
setLayout(new GridLayout(3,1));
add(new Label("Left label"));
add(new Label("Center label", Label.CENTER));
add(new Label("Right label", Label.RIGHT));
}
}
|