Google Answers Logo
View Question
 
Q: Java Applet question ( Answered 5 out of 5 stars,   0 Comments )
Question  
Subject: Java Applet question
Category: Computers > Programming
Asked by: purplepit-ga
List Price: $20.00
Posted: 26 May 2003 04:04 PDT
Expires: 25 Jun 2003 04:04 PDT
Question ID: 208820
Could you please add comments to every line of the below code?

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

import java.awt.*;
import java.applet.*;

public class Display extends Applet
{
    Panel elementsw = new Panel();
    Panel elementsc = new Panel();
    Panel elementse = new Panel();
    Label myLabel = new Label("This is a Label");
    TextField myText = new TextField(20);
    Button btnClick = new Button("Click Me Please");
    Choice myChoice = new Choice();
    Checkbox option1 = new Checkbox("Tick to select the
option",false);
    Checkbox option2 = new Checkbox("and the other option",false);
    TextArea myTextArea = new TextArea("TextAreas are for large items
of text",8, 20);
    Canvas myCanvas = new Canvas();
    List myList = new List();
    Label chooseOption = new Label("Pick one option from this set:");
    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);

    public void init()
    {
	elementsw.setLayout(new GridLayout(6,1,10,35));
	elementsc.setLayout(new GridLayout(2,1,10,30));
	elementse.setLayout(new GridLayout(5,1,10,0));
	elementsw.add(myLabel);
	elementsw.add(myText);
	elementsw.add(btnClick);
       	myChoice.addItem("Choice 1");
	myChoice.addItem("Choice 2");
	myChoice.addItem("Choice 3");
	myChoice.addItem("Choice 4");
	myChoice.select(0);
	elementsw.add(option1);
	elementsw.add(option2);
	elementsw.add(myChoice);
	elementsc.add(myTextArea);
	myCanvas.setBackground(Color.red);
	myCanvas.setSize(80,40);
	elementsc.add(myCanvas);
	
	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");
	elementse.add(myList);
	
	elementse.add(chooseOption);

	elementse.add(optionA);
	elementse.add(optionB);
	elementse.add(optionC);
	
	add(elementsw, "West");
	add(elementsc, "Center");
	add(elementse, "East");


    }
}

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Thank you!!!

Request for Question Clarification by errol-ga on 26 May 2003 04:12 PDT
Hi there!

Can I just ask what you mean by "comments"?
Do you want somebody to explain what each line does?

Kind regards,
errol-ga.

Clarification of Question by purplepit-ga on 26 May 2003 05:42 PDT
Hi There,
Yes just a brief description, of what each line means please....
Answer  
Subject: Re: Java Applet question
Answered By: answerguru-ga on 26 May 2003 08:41 PDT
Rated:5 out of 5 stars
 
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
purplepit-ga rated this answer:5 out of 5 stars
Thank you very much.......

Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy