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


Table 9.1 shows the fields in the DialogResult class that you’ll want to use as your dialog results.

Table 9.1 The Fields in the DialogResult Class That are Used for Your Dialog Results"

Constant Description

ABORT The user has aborted an operation.
CANCEL The user has canceled an operation.
IGNORE The user has chosen to ignore the information that the dialog has presented.
NO The user has answered no to a dialog query.
NONE The user has answered none to a dialog query.
OK The user has accepted the values in the dialog.
RETRY The user has chosen to retry an operation.
YES The user has answered yes to a dialog query.

Performing Tasks When Users Click

You might want to perform certain tasks when users click a button. To handle these situations, select the button control. Go to its event list in the Properties window, and find the click event. Double-click on it. An event handler for the click event will be added, and it will open the source code to the newly added method.

In the handler, you can add any code you need for handling the click event. If you want to close the dialog after you’re done, just call the close() method. Bear in mind that the close() method will return a value of DialogResult.CANCEL.

Useful Form Methods

Various methods in the Form class can be useful for programming dialogs. They’re also useful at other times. In this section, I’ll mention and explain some of these.

The getDisplayRect() method returns the display area used to display components on the Form. The area may be a virtual area if the Form is scrollable. The following example shows how to get the display rectangle for a Form:

Rectangle rect;
rect = getDisplayRect();
int nWidth = rect.width;
int nHeight = rect.height;
int nX = rect.x;
int nY = rect.y;

The getFormState() method returns bits associated with the specified form state. The bits that are returned are determined by the integer argument passed to the method. Table 9.2 shows the possible values.

Table 9.2 Values for the getFormState() Method

Constant Description

FORMSTATE_AUTOSCALING Represents the form’s autoScale property.
FORMSTATE_AUTOSCROLLING Represents the form’s autoScroll property.
FORMSTATE_BORDERSTYLE Represents the form’s borderStyle property.
FORMSTATE_CONTROLBOX Represents the form’s controlBox property.
FORMSTATE_HELPBUTTON Represents the form’s helpButton property.
FORMSTATE_HSCROLLVISIBLERepresents the form’s keyPreview
or FORMSTATE_KEYPREVIEW property.
FORMSTATE_MAXIMIZEBOX Represents the form’s maximizeBox property.
FORMSTATE_MINIMIZEBOX Represents the form’s minimizeBox property.
FORMSTATE_PALETTEDIRTY or FORMSTATE_PALETTEMODE Represents the form’s paletteMode property.
FORMSTATE_SETCLIENTSIZE Represents the form’s size property.
FORMSTATE_STARTPOS Represents the form’s startPosition property.
FORMSTATE_TASKBAR Represents the form’s taskBar property.
FORMSTATE_WINDOWSTATE Represents the form’s windowState property.

The following example returns the value of 1 if there is a maximize button on the Form. It returns 0 if there isn’t.

int nValue;
nValue  = getFormState( FORMSTATE_MAXIMIZEBOX );
if( nValue == 1 )
{
    // Yes maximize box.
}
else
{
    // No maximize box.
}

The getWindowState() method returns the current state of the window. The returned value equates to one of the enumeration constants defined in the FormWindowState class. Those values are shown in Table 9.3.

Table 9.3 Values for the FormWindowState Class

Constant Description

MAXIMIZED Represents a maximized window.
MINIMIZED Represents a minimized window.
NORMAL Represents a normally sized window.

The following example gets the current state of the window:

int nState;
nState = getWindowState();
if( nState == FormWindowState.MAXIMIZED )
{
    // The Form window is maximized.
}
else if( nState == FormWindowState.MINIMIZED )
{
    // The Form window is minimized.
}
else if( nState == FormWindowState.NORMAL )
{
    // The Form window is in a normal state.
}

The pointToScreen() method converts a point in terms of the Form to coordinates in terms of the screen. The following example shows how it’s done:

Point formPoint = new Point( 10, 10 ); // Form coordinate 10, 10
Point screenPoint = pointToScreen( formPoint );
// Now screenPoint has the converted coordinates.

The setFormState() method sets elements of the Form’s state. These elements are the ones that the getFormState() method deals with. (Refer to Table 9.2 for more information.) After you call the setFormState() method, the values returned in the getFormState() method will reflect the change. Any changes that result in visible changes to the window will be seen immediately.

The following example removes the minimize box from the Form:

setFormState( FORMSTATE_MINIMIZEBOX, false );

Almost every Windows programmer has at one time or another wanted to create a window that didn’t place an item in the system taskbar. You can use the setShowInTaskBar() method to either allow or prevent a Form window from appearing in the system taskbar. The following example shows how to prevent the Form from appearing in the system taskbar:

setShowInTaskBar( false );


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.