|
|
Java Student Project |
||
|
|||
| LabelsMessage | |||
|
|
|
||
| Ability Level: | Beginner | ||
|
|
|
||
| Estimated Time: | 45 minutes | ||
|
|
|
||
| Objectives: |
|
||
|
|
|
||
| Materials & Resources: |
|
||
|
|
|
||
| Overview: | Write an applet which will print out a message from a web browser. The message should have a large font. You must use the label command. Call the label by the use of a method. Read the hints below for clarification. Be positive with your message. |
||
|
|
|
||
| Instructions: |
Steps for using Visual J++:
|
||
|
|
|
||
| Hints: | 1. Import is necessary to include library
files. Be sure to include Applet.The asterisk indicates
all the libraries from the applet field are to be included. AWT
is used to indicate Abstract Windows Toolkit package. Examples: import java.awt*; import java.applet.*; 2. Class must be declared with the name and extends Applet to indicate Applet is being created. Example: public class Salutation extends Applet 3. One of the easiest Windows components is a Label. Label is
a built-in class that holds text that can be displayed within an
applet. The Label class contains fields that indicate the
appearance information including font and alignment.
Example: 4. The method you use to add a component to an applet window
is add(). (A method is a small program routine, as a
function is in C++.) 5. The object of the add() method is the applet itself, so when you add a component to a window, you could write this.add(); in place of add();. 6. With an applet, the browser calls many methods
automatically. The following four methods are included in every
applet: 7. Java provides a Font object that holds typeface and size information. The setFont() method requires a Fong object argument. Three arguments, typeface, style, and point size are needed. The typeface is a String representing a font and a request to use the font. 8. The style applies an attribute to displayed text and is one of three arguments, Font.PLAIN, Font.BOLD, or Font.ITALIC. 9. The point size is an integer that represents 1/72 of an inch. 10. To give a Label object a new font, you create the Font object, as in Font headlineFont = new Font ("Helvetica", Font.BOLD,36);, and then you can use the setfont() method to assign the font to a Label with the statement Saluation.setFont (headlineFont); 11. The typeface name is a String, so you must enclose it in double quotation marks when you use it to declare the Font object. | ||