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


The last method we’re going to talk about in this chapter sets the window’s visibility to either visible or invisible. The setVisible() method takes a Boolean argument. The value of true makes the window visible; the value of false makes it invisible. The following example shows how to make a window invisible:

setVisible( false );

Summary

Dialogs are a powerful tool in your user-interface arsenal. And Visual J++ makes it easy to create and use them. After you’ve worked your way through this chapter, you should take some time and create dialogs of your own design. This experimentation will go far toward helping you feel comfortable with dialogs in Visual J++.

Q&A

Q Why are dialogs so important in Windows programs?

A They allow you to present many types of information to users and to ask for all kinds of information that the application needs in order to function. For instance, you might need to ask for the user’s name and address. You might want to ask other users to select from a list of choices.

Q What’s the difference between a Form and a dialog?

A Not much in the way they’re created and designed. To add a dialog, you start by adding a Form to your project. You use the same user-interface objects, such as combo boxes, buttons, and list boxes, to add functionality. Where they differ is in how they’re displayed. A dialog is displayed with the showDialog() method. This method then shows the dialog as a modal window.

Q How can you get input from OK and Cancel buttons?

A You start by adding them to the Form. Then you have to set the button dialogResult properties to OK and Cancel. Finally, in the dialog’s Form class, set the acceptButton property to the OK button and the cancelButton property to the Cancel button.

Q Why should dialogs be modal? Why should interaction with the main program be paused until users are finished with the dialog?

A The main purpose for a dialog is to get information from a user that’s needed to continue program execution. In most cases, the program wouldn’t be able to continue without the information requested by the dialog, so it’s only natural to pause the program until all the information has been given.

Q What are some dialog “don’ts”?

A Don’t have minimize and maximize buttons on dialogs. Don’t use pull-down menus in dialogs. Make sure that users can answer all queries and enter all information without having to refer to something in the main program.

Exercises

1.  Create a Visual J++ application. Add a Form named Test. Add an OK and a Cancel button to the form and a label. Set the acceptButton property to the OK button and the cancelButton property to the Cancel button. Set each button’s dialogResult property (OK and Cancel). In the main program, make a place to create and display the dialog (remember the click event handler). Compile and run the program.
2.  Create an application. Add menus that give users three choices. Create three dialogs. For each of the menu selections, create and display one of the dialogs.
3.  Create an application with a dialog. Ask users for their name and address. When users have made their entries and clicked the OK button, display the information that they entered.


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.