Questions On Java Applet creation

Q Can arguments be sent to applets, as they can to applications?

A
You can't use arguments, but parameters serve a similar function to arguments in applet programming. You can use the tag with its NAME and VALUE attributes to send parameters to Java programs. It's described fully in Hour 15, "Sending Parameters to --Applets."

Q Is there a reason why the --CODEBASE attribute should be used in an --"" tag?

A If all Java programs are grouped into their own subdirectory, as indicated by
--CODEBASE, this structure might improve the way a Web site is organized, but there's no other reason why using --CODEBASE is better than omitting it. The choice is a matter of personal preference.

Q What happens if the height and width specified for an applet don't leave enough room for the information that is displayed in the paint() method?

A
The information will be drawn off-screen beyond the edges of the applet window and won't be visible at any point while the applet runs. Choosing the right dimensions for an applet is largely a matter of trial-and-error until you find the right size for both the
HEIGHT and WIDTH attributes of the tag. Fortunately, you can change the Web page's --HTML without having to recompile the Java program.
Quiz
The following questions test your knowledge of applets.
Questions
1. What type of argument is used with the paint() method?

(a)
A
Graphics object
(b) A Boolean variable
(c) None

2. Which method is handled right before an applet finishes running?

(a)
decline()
(b)
destroy()
(c)
demise()

3. Why can't all variables needed in an applet be created inside the
init() method?

(a)
The scope of the variables would be limited to the method only.
(b) Federal legislation prohibits it.
(c) They can be created there without any problems.
Answers
1. a. The Graphics object keeps track of the behavior and attributes needed to display things on-screen in the applet window.

2.
b.

3.
a. Variables that are used in more than one method of a class should be created right after the class statement but before any methods begin.

Post a Comment

أحدث أقدم