Click Here!
home account info subscribe login search My ITKnowledge FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

Sams Teach Yourself Visual J++ 6 in 21 Days
(Publisher: Macmillan Computer Publishing)
Author(s): Rick Leinecker
ISBN: 0672313510
Publication Date: 11/01/98

Bookmark It

Search this book:
 
Previous Table of Contents Next


Summary

Frame windows are a powerful tool in making programs more flexible and communicative. They can underscore special information you want brought to users’ attention, or they can hold information that’s somehow different than what’s in your main program.

There’s just about no end to what you can do with Frame windows if you get creative. Go ahead and do the review exercises to really get up to speed!

Q&A

Q How is a constant variable declared in Java?

A A constant variable is declared as a final variable.

Q How do you compare two objects for equality?

A If the object properly implements the equals() method, the equals() method must be used. The (==) operator can be used, however. This operator only checks to see whether both variables are referencing the same object instance.

Q What can you do with a Frame class after you have created it if you have not extended it into your own class?

A Not much! You can use a few of the Frame class’s methods, such as setTitle() and setSize(), but you won’t be able to intercept any kinds of events or override any of the Frame class’s methods, such as the paint() method.

Q Why is garbage collection in Java so important?

A Because the leading causes of program bugs and program failures are memory allocation and overrun bugs. Not having to worry about deallocating memory saves Visual J++ programmers a huge headache. In addition, it prevents many, many bugs from creeping into their programs.

Q Why would I ever want to overload methods? Why wouldn’t I want to just write separate methods that take different parameters?

A The reason is that if methods perform the same functions, they should be named the same thing (for program clarity) even if they do different things. For instance, the concatenate() method does the same thing whether it takes two strings or a string and an integer as arguments. The minute you start renaming these methods depending on which arguments they take, you confuse their meaning and make the program less obvious and less straightforward.

Exercises

1.  Create an applet. In the applet, declare and create a Frame class. In the applet’s init() method, call the Frame’s setVisible() method, and set the frame visibility to true.
2.  Create an applet. In the applet, create your own class that extends the Frame class. In your extended Frame class, declare a constructor that calls the superclass’s claim constructor. (If you’re unclear on how to do this, refer to the example in Listing 5.3.) After you’ve done that, add a paint() method to your new class. Inside the paint() method, display some text at a coordinate of (50,50) so that you know you’ve actually drawn to your Frame window when the applet runs.
3.  Take the applet you just wrote, and inside the extended Frame class, create another class that extends the WindowAdapter class. Inside this WindowAdapter class, add a windowActivated() method. Inside the windowActivated() method, change the Frame window’s text so that every time the window is activated, the Frame window’s text changes and you can tell that the Frame window caught the windowActivated() event and responded to it.


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.