Complete the following set of instructions to develop a simple Java applet shown above. Note that the applet does not respond to events.
- Add an import statement to import java.applet.* (What happens if the import statement is missing?)
- Declare a class ChemicalFormula that extends class Applet.
- Declare elementName as an instance of class Choice. Initialize it to be an empty object.
- Declare elementSymbol as an instance of class TextField. Make its length equal to 2 columns. (What happens if the length is not specified during initialization?)
- Declare atomicWeight as an instance of class TextField. Make its length equal to 8 columns.
- Declare atomicWeightLabel as an instance of Label. Initialize it to "Atomic Weight").
- Declare an init method. It has no parameters, is public and returns void.
- Add the following element names to elementName: Carbon, Iron, Silicon, and Uranium. (Does the sequence matter ?)
- Set the text in elementSymbol to "C".
- Set the text in atomicWeight to "12.017". (What happens if the text is set after the widget has been added to the screen?)
- Set the background color of the applet screen to orange.
- Add to the applet the widgets that you have created.
- End the init method. (Why is it that we do not need a paint method in this applet?)
Last update: September 2, 2004
|
|