Hello again purplepit!
Below is the code you supplied with comments throughout:
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// importing all of the standard Java AWT and Applet libraries
import java.awt.*;
import java.applet.*;
// Define a class that is a subclass of Applet
public class Display extends Applet
{
// Define class variables
// Create and initialize three Panel objects as blank Panels
Panel elementsw = new Panel();
Panel elementsc = new Panel();
Panel elementse = new Panel();
// Create and initialize a Label with the given text string
Label myLabel = new Label("This is a Label");
// Create and initialize a TextField object large enough to display 20
chars
TextField myText = new TextField(20);
// Create and initialize a Button with the given text on the button
Button btnClick = new Button("Click Me Please");
// Create and initialize a dropdown menu with no options
Choice myChoice = new Choice();
// Create and initialize two Checkbox objects
// Both are initialized to be unchecked
Checkbox option1 = new Checkbox("Tick to select the
option",false);
Checkbox option2 = new Checkbox("and the other option",false);
// Create and initialize a TextArea with the given string
// Size is 8 rows by 20 columns
TextArea myTextArea = new TextArea("TextAreas are for large items
of text",8, 20);
// Create and initialize a Canvas object as blank with the default
GraphicConfiguration
Canvas myCanvas = new Canvas();
// Create and initialize a List with no text items
List myList = new List();
// Create and initialize a label with the given string
Label chooseOption = new Label("Pick one option from this set:");
// Define a group of three Checkbox objects where the first and third
objects
// are unchecked and the second is checked
CheckboxGroup myCheckboxGroup = new CheckboxGroup();
Checkbox optionA = new Checkbox("Option A", myCheckboxGroup,
false);
Checkbox optionB = new Checkbox("Option B", myCheckboxGroup,
true);
Checkbox optionC = new Checkbox("Option C", myCheckboxGroup,
false);
// Initialization routine
public void init()
{
// define the layout style for the three panel objects
// parameters are rows, columns, horizontal_gap,vertical_gap
elementsw.setLayout(new GridLayout(6,1,10,35));
elementsc.setLayout(new GridLayout(2,1,10,30));
elementse.setLayout(new GridLayout(5,1,10,0));
// add the previously defined Label, TextField, and Button
// objects to the elementsw Panel
elementsw.add(myLabel);
elementsw.add(myText);
elementsw.add(btnClick);
// add four items to the Choice object and set "Choice 1"
// as the default
myChoice.addItem("Choice 1");
myChoice.addItem("Choice 2");
myChoice.addItem("Choice 3");
myChoice.addItem("Choice 4");
myChoice.select(0);
// add the two checkboxes and the Choice object to the elementsw
panel
elementsw.add(option1);
elementsw.add(option2);
elementsw.add(myChoice);
// add the TextArea object to the elementsc panel
elementsc.add(myTextArea);
// Configure the Canvas object to have a red background.
// width of 80 and height of 40, then add to the elementsc panel
myCanvas.setBackground(Color.red);
myCanvas.setSize(80,40);
elementsc.add(myCanvas);
// add 10 text elements to the previously empty List object
myList.add("List Option A");
myList.add("List Option B");
myList.add("List Option C");
myList.add("List Option D");
myList.add("List Option E");
myList.add("List Option F");
myList.add("List Option G");
myList.add("List Option H");
myList.add("List Option I");
myList.add("List Option J");
// add the List object and the chooseOption Label to the elementse
panel
elementse.add(myList);
elementse.add(chooseOption);
// add three Checkbox objects to the elementse panel
elementse.add(optionA);
elementse.add(optionB);
elementse.add(optionC);
// place elementsw on the west side of the applet
add(elementsw, "West");
// place elementsc at the center of the applet
add(elementsc, "Center");
// place elementse on the east side of the applet
add(elementse, "East");
}
}
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Hopefully the formatting will work out correctly...never can tell
until the post is complete.
If you have any questions please feel free to post a clarification :)
Cheers!
answerguru-ga |