Task 1
Add a new Label
to the applet with text of "Some
Components".
You can do this in several ways. First, create the Label,
set its text, and add it as follows:
Label someLabel = new Label();
someLabel.setText("Some Components");
add(someLabel);
Second, you can create the Label and pass the text to
display at the same time as follows:
Label someLabel = new Label("Some Components");
add(someLabel);
Finally, you can combine all the steps into a single statement if you will
not need a reference to the Label later in your program
as follows:
add(new Label("Some components"));
Task 2
Add a new Button with a label of "Ok"
to the
applet.
You can do this in several ways. First, create the Button,
set its text, and add it as follows:
Button someButton = new Button();
someButton.setLabel("Ok");
add(someButton);
Second, you can create the Button and pass the text to
display at the same time as follows:
Button someButton = new Button("Ok");
add(someButton);
Finally, you can combine all the steps into a single statement if you will
not need a reference to the Button later in your
program, as follows:
add(new Button("Ok"));
Task 3
Add another Button with a label of "A
Big
Button" to the applet.
Similar to the last task, you can do this as follows:.
add(new Button("A Big Button"));
Task 4
Add a new Checkbox with a label of
"Anybody
home?" to the applet.
You can do this in several ways. First, create the Checkbox,
set its text, and add it as follows:
Checkbox someCheckbox = new Checkbox();
someCheckbox.setLabel("Anybody home?");
add(someCheckbox);
Second, you can create the Checkbox and pass the
text to
display at the same time as follows:
Checkbox someCheckbox = new Checkbox("Anybody home?");
add(someCheckbox);
Finally, you can combine all the steps into a single statement if you will
not need a reference to the Checkbox later in your
program, as follows:
add(new Checkbox("Anybody home?"));
Task 5
Add a new TextField that is 20
characters wide to the
applet.
Note: The number of columns that you pass represents the preferred
number of characters to be visible. This means:
- Some layout managers may ignore this
setting.
- Because the preferred size is based on the
size of the letter
"M", if the TextField uses a proportional font, you may actually
see more than 20 characters when displayed in a layout manager that
respects the preferred width of the
TextField.
You can do this in several ways. First, create the TextField,
set the number of columns, and add it as follows:
TextField someTextField = new TextField();
someTextField.setColumns(20);
add(someTextField);
Second, you can create the TextField and pass the
number
of columns at the same time, as follows:.
TextField someTextField = new TextField(20);
add(someTextField);
Finally, you can combine all the steps into a single statement if you will
not need a reference to the TextField later in your
program as follows:
add(new TextField(20));
Task 6
Add a new TextArea that is 4 rows
by 10 character columns
to the applet. Again, these sizes represent the preferred size of the
TextArea, which may be respected or ignored by the layout manager in use.
You can do this in several ways. First, create the TextArea,
set the number of columns, and add it as follows:
TextArea someTextArea = new TextArea();
someTextArea.setRows(5);
someTextArea.setColumns(10);
add(someTextArea);
Second, you can create the TextArea and pass the
number of
columns at the same time, as follows:
TextArea someTextField = new TextArea(4,10);
add(someTextArea);
Finally, you can combine all the steps into a single statement if you will
not need a reference to the TextArea later in your
program, as follows:
add(new TextArea(4,10));