Modern Java
http://www.modernminds.com
B uttonBar Constructors

The ButtonBar class provides two constructors for instantiating an object. The difference between the two constructors is that one of the constructors accepts URLs for button images, while the other constructor accepts Image objects.

Both ButtonBar constructors are presented below. You can click the parameter name to jump directly to a description of the parameter.

U RL Based Constructor

This constructor for the ButtonBar class requires URLs for the button bar image files to be passed.

public ButtonBar(
   boolean barHorizontal,
   URL     base,
   String  baseBarName,
   String  mouseOverBarName,
   String  mouseOverBar2Name,
   String  mouseDownBarName,
   String  mouseDownOverBarName,
   String  buttonsDisabledBarName,
   String  backgroundImageName,
   int     barXBackgroundPos,
   int     barYBackgroundPos,
   int     drawButtonBorders,
   Color   borderColorTopLeft,
   Color   borderColorBottomRight,
   int     borderIntensityPercent,
   int     buttonBorderSize,
   boolean downShift,
   int     downShiftAmt,
   int     baseBrightenPct,
   Color   baseBrightenTint,
   int     mouseOverBrightenPct,
   Color   mouseOverBrightenTint,
   boolean mouseDownBrightenAll,
   int     mouseDownBrightenPct,
   Color   mouseDownBrightenTint,
   int     buttonsDisabledDimPct,
   int     grayBarBrighten,
   int     frameRate
) throws Exception
I mage Based Constructor

This constructor for the ButtonBar class requires Image objects to be passed for the button bar button images.

public ButtonBar(
   boolean barHorizontal,
   Image   baseBar,
   Image   mouseOverBar,
   Image   mouseOver2Bar,
   Image   mouseDownBar,
   Image   mouseDownOverBar,
   Image   buttonsDisabledBar,
   Image   backgroundImage,
   int     barXBackgroundPos,
   int     barYBackgroundPos,
   int     drawButtonBorders,
   Color   borderColorTopLeft,
   Color   borderColorBottomRight,
   int     borderIntensityPercent,
   int     buttonBorderSize,
   boolean downShift,
   int     downShiftAmt,
   int     baseBrightenPct,
   Color   baseBrightenTint,
   int     mouseOverBrightenPct,
   Color   mouseOverBrightenTint,
   boolean mouseDownBrightenAll,
   int     mouseDownBrightenPct,
   Color   mouseDownBrightenTint,
   int     buttonsDisabledDimPct,
   int     grayBarBrighten,
   int     frameRate
) throws Exception
P arameter Descriptions

Each of the parameters for the ImageURLButtonBar applet is described in detail in this section.

barHorizontal (boolean)

A parameter value of "true" will tell the class that the button bar has a horizontal orientation, while a parameter value of "false" will tell the class that the button bar is oriented vertically.
base (URL)

This parameter is used in the URL based constructor.

This is the URL to the base directory where the image files are located. A path for an image file location will begin at this base directory.
baseBarName (String)

This parameter is used in the URL based constructor.

This is the file name of the GIF or JPEG image file for the base button bar. If a path to the image file is specified, then the path root is based on the base parameter.

The base button bar contains button images that are displayed when the mouse is not within any button's boundaries.

Note that the button bar will become functional as soon as the base button bar is loaded (if a background image is specified, then both the base and the background image must be loaded before the button bar will become functional). By "functional" what is meant is that the base state for buttons will be displayed, and events for buttons on the button bar will be generated. Button images for other button states will be available only after all of the other specified image files have been loaded.
baseBar (Image)

This parameter is used in the Image based constructor.

This is the Image object for the base button bar.

The base button bar contains button images that are displayed when the mouse is not within a button's boundaries.
mouseOverBarName (String)

This parameter is used in the URL based constructor.

This is the file name of the GIF or JPEG image file for the mouseOver button bar.

If a path to the image file is specified, then the path root is based on the base parameter.

The mouseOver button bar contains button images that are displayed when the mouse is moved within a button's boundaries.

If this parameter has a value of null, then the class will use the image file specified by the baseBarName parameter as the mouseOver image, and a grayscale version of the base image as the base button bar image (see also the grayBarBrighten parameter).
mouseOverBar (Image)

This parameter is used in the Image based constructor.

This is the Image object for the mouseOver button bar.

The mouseOver button bar contains button images that are displayed when the mouse is moved within a button's boundaries.

If this parameter has a value of null, then the class will use the image specified by the baseBar parameter as the mouseOver image, and a grayscale version of the base image as the base button bar image (see also the grayBarBrighten parameter).
mouseOverBar2Name (String)

This parameter is used in the URL based constructor.

This is the file name of the GIF or JPEG image file for the mouseOver2 button bar. The mouseOver2 button bar is used for button animation only.

If a path to the image file is specified, then the path root is based on the base parameter.

If an image file is specified for this parameter, then when the mouse is moved within a button's boundaries the button will be animated by alternating between the button image on the button bar specified by the mouseOverBarName parameter and the button image on the mouseOver2 bar. The rate at which the images are alternated is determined by the frameRate parameter.

If this parameter is null, then no button animation will be performed.
mouseOverBar2 (Image)

This parameter is used in the Image based constructor.

This is the Image object for the mouseOver2 button bar. The mouseOver2 button bar is used for button animation only.

If an image object is specified for this parameter, then when the mouse is moved within a button's boundaries the button will be animated by alternating between the button image on the button bar specified by the mouseOverBar parameter and the button image on the mouseOver2 bar. The rate at which the images are alternated is determined by the frameRate parameter.

If this parameter is not specified, then no button animation will be performed.
mouseDownBarName (String)

This parameter is used in the URL based constructor.

This is the file name of the GIF or JPEG image file for the mouseDown button bar.

If a path to the image file is specified, then the path root is based on the base parameter.

The mouseDown button bar contains button images that are displayed when the mouse is moved within a button's boundaries and clicked. The image is displayed as long as the mouse button is held down.

If this parameter is null, and if button borders are not used (see the drawButtonBorders parameter), then the class will "brighten" the image specified by the mouseOverBarName parameter for use as the mouseDown button bar image by the percentage specified by the mouseDownBrightenPct parameter.
mouseDownBar (Image)

This parameter is used in the Image based constructor.

This is the Image object for the mouseDown button bar.

The mouseDown button bar contains button images that are displayed when the mouse is moved within a button's boundaries and clicked. The image is displayed as long as the mouse button is held down.

If this parameter is null, and if button borders are not used (see the drawButtonBorders parameter), then the class will "brighten" the image specified by the mouseOverBar parameter for use as the mouseDown button bar image by the percentage specified by the mouseDownBrightenPct parameter.
mouseDownOverBarName (String)

This parameter is used in the URL based constructor.

This is the file name of the GIF or JPEG image file for the mouseDownOver button bar. The mouseDownOver button bar is only used for "sticky" buttons (i.e., buttons that are not "momentary contact" buttons).

If a path to the image file is specified, then the path root is based on the base parameter.

The mouseDownOver button bar contains button images that are displayed when the mouse is moved within the boundaries of a button that is "stuck" in the "down" or "on" position. The button image is displayed until the mouse moves off of the button or until the button is clicked.

If this parameter is null, then the class will "brighten" the image specified by the mouseDownBarName parameter for use as the mouseDownOver button bar image by the percentage specified by the mouseDownBrightenPct parameter.
mouseDownOverBar (Image)

This parameter is used in the Image based constructor.

This is Image object for the mouseDownOver button bar. The mouseDownOver button bar is only used for "sticky" buttons (i.e., buttons that are not "momentary contact" buttons).

The mouseDownOver button bar contains button images that are displayed when the mouse is moved within the boundaries of a button that is "stuck" in the "down" or "on" position. The button image is displayed until the mouse moves off of the button or until the button is clicked.

If this parameter is null, then the class will "brighten" the image specified by the mouseDownBar parameter for use as the mouseDownOver button bar image by the percentage specified by the mouseDownBrightenPct parameter.
buttonsDisabledBarName (String)

This parameter is used in the URL based constructor.

This is the file name of the GIF or JPEG image file for the buttonsDisabled button bar.

If a path to the image file is specified, then the path root is based on the base parameter.

The buttonsDisabled button bar contains button images that are displayed when a button is disabled (a button is disabled via a method of the ButtonRegion class).

If this parameter is null, then the class will "darken" the image specified by the baseBarName parameter for use as the buttonsDisabled button bar image by the percentage specified by the buttonsDisabledDimPct parameter.
buttonsDisabledBar (Image)

This parameter is used in the Image based constructor.

This is the Image object for the buttonsDisabled button bar.

The buttonsDisabled button bar contains button images that are displayed when a button is disabled (a button is disabled via a method of the ButtonRegion class).

If this parameter is null, then the class will "darken" the image specified by the baseBar parameter for use as the buttonsDisabled button bar image by the percentage specified by the buttonsDisabledDimPct parameter.
backgroundImageName (String)

This parameter is used in the URL based constructor.

This is the file name of the GIF or JPEG image file that is displayed behind the button bar.

If a path to the image file is specified, then the path root is based on the base parameter.

When the button bar is displayed, the background image (if specified) is drawn first, then the button bar is drawn on top of the background image. This can be useful, for instance, if you wish to surround your button bar with a custom graphic, such as a frame.

The position of the button bar on the background image is specified by the barXBackgroundPos and barYBackgroundPos parameters.

If this parameter is null, then the class will not draw a button bar background.
backgroundImage (Image)

This parameter is used in the Image based constructor.

This is the Image object that is displayed behind the button bar.

When the button bar is displayed, the background image (if specified) is drawn first, then the button bar is drawn on top of the background image. This can be useful, for instance, if you wish to surround your button bar with a custom graphic, such as a frame.

The position of the button bar on the background image is specified by the barXBackgroundPos and barYBackgroundPos parameters.

If this parameter is null, then the class will not draw a button bar background.
barXBackgroundPos (int)

This parameter is only used by the class if the backgroundImage (or backgroundImageName) parameter is specified.

The barXBackgroundPos parameter is used to position the button bar horizontally on the background image.

The left edge of the background image is at position 0 (zero).
barYBackgroundPos (int)

This parameter is only used by the class if the backgroundImage (or backgroundImageName) parameter is specified.

The barYBackgroundPos parameter is used to position the button bar vertically on the background image.

The top edge of the background image is at position 0 (zero).
drawButtonBorders (int)

This parameter controls whether borders are drawn around buttons.

The four valid constant values for this parameter are:
  • ButtonBar.BORDERS_NONE (or 0) - borders are not drawn around buttons


  • ButtonBar.BORDERS_BASE (or 1) - borders are drawn around buttons on the base button bar only


  • ButtonBar.BORDERS_OTHER (or 2) - borders are drawn around buttons on all button bars except the base button bar


  • ButtonBar.BORDERS_ALL (or 3) - borders are drawn around the buttons on all button bars
If button borders are drawn, then the border characteristics are determined by the parameters borderColorTopLeft, borderColorBottomRight, borderIntensityPercent, and buttonBorderSize.
borderColorTopLeft (Color)

Normally, button borders (see the drawButtonBorders parameter) are drawn by "lightening" or "darkening" the borders around a button image by the percentage specified by the borderIntensityPercent parameter. However, it is possible to manually specify a solid color to use when drawing a border.

This parameter allows you to manually specify the Color used to draw the top and left button borders.
borderColorBottomRight (Color)

Normally, button borders (see the drawButtonBorders parameter) are drawn by "lightening" or "darkening" the borders around a button image by the percentage specified by the borderIntensityPercent parameter. However, it is possible to manually specify a solid color to use when drawing a border.

This parameter allows you to manually specify the Color used to draw the bottom and right button borders.
borderIntensityPercent (int)

Normally, button borders (see the drawButtonBorders parameter) are drawn by "lightening" or "darkening" the borders around a button image by the percentage specified by this parameter.

Lightening and darkening button borders instead of using solid colors can result in some interesting effects as the image itself becomes part of the border.

If you prefer to manually specify solid border colors, see the borderColorTopLeft and the borderColorBottomRight parameters.

If solid border colors are not manually specified, then the value for this parameter must be between "0" and "100" percent.
buttonBorderSize (int)

If borders are drawn for buttons (see the drawButtonBorders parameter), then this parameter will determine the width of the border that surrounds each button.
downShift (boolean)

When the mouse is clicked while over a button, then the mouseDown image is displayed (see the mouseDownBar or mouseDownBarName parameter). In addition to displaying the mouseDown image, you can also specify that the button image be offset or "shifted" down and to the right. This gives the illusion that the button has been depressed.

If this parameter is "true", then when the mouse is clicked on a button it will be shifted down and to the right by the number of pixels specified by the downShiftAmt parameter. Note that downShift can be enabled regardless of whether borders (see the drawButtonBorders parameter) are being drawn for the buttons or not.

One thing to bear in mind when using the downShift parameter is that the downShift effect is produced by copying the button image, moving it down and to the right, then drawing it over the original button image. In some circumstances portions of the original image might be left in the border region resulting in a less-than-desirable appearance. In this situation, it is recommended that you use solid color borders (see the borderColorTopLeft and borderColorBottomRight parameters).
downShiftAmt (int)

If buttons are shifted down and to the right when they are clicked (see the downShift parameter), then this parameter will determine the number of pixels that the button will be shifted.
baseBrightenPct (int)

If the value of this parameter is greater than zero, then the "brightness" of the base button bar will be increased by the specified percentage.

If the value of this parameter is less than zero, then the "brightness" of the base button bar will be decreased by the specified percentage.

If the value of this parameter is zero, then the brightness of the base button bar will remain unchanged.

The value for this parameter must be between "-100" and "100" percent.
baseBrightenTint (Color)

This parameter is a color that is used to"tint" the base button bar when it is "brightened" (see also the related baseBrightenPct parameter).

For instance, if you want to give the base button bar a reddish tint, then you might specify a tint color that has a hex value of "330000" as, for example:

Color tintColor = new Color(0x33, 0, 0);

It is important to note that in order to tint the button bar, the baseBrightenPct parameter must be assigned a value other than zero (the value can be positive or negative).

Also, note that tinting is an additive process. This means that if you use a bright tint color, then the original colors in the button bar will be brightened. It might be necessary to specify a negative value for the baseBrightenPct parameter in order to prevent the button bar from having a "washed out" appearance.

Usually a small tint value will yield the best results. For instance, a red only tint value of "180000" will appear nearly black on it's own, but when added to the colors in the button image will result in the button image having a reddish tint. If a larger red value was used, for instance "ff0000", the button would probably appear far too red (large values can, however, be useful). The moral is, start small and then increase the tint color value a little at a time until the desired effect is achieved. Also, don't forget to experiment with adjusting the baseBrightenPct parameter value in combination with the baseBrightenTint parameter value.
mouseOverBrightenPct (int)

If the value of this parameter is greater than zero, then the "brightness" of the mouseOver button bar will be increased by the specified percentage.

If the value of this parameter is less than zero, then the "brightness" of the mouseOver button bar will be decreased by the specified percentage.

If the value of this parameter is zero, then the brightness of the mouseOver button bar will remain unchanged.

The value for this parameter must be between "-100" and "100" percent.
mouseOverBrightenTint (Color)

This parameter is a color that is used to"tint" the mouseOver button bar when it is "brightened" (see also the related mouseOverBrightenPct parameter).

For instance, if you want to give the mouseOver button bar a reddish tint, then you might specify a tint color that has a hex value of "330000" as, for example:

Color tintColor = new Color(0x33, 0, 0);

It is important to note that in order to tint the button bar, the mouseOverBrightenPct parameter must be assigned a value other than zero (the value can be positive or negative).

Also, note that tinting is an additive process. This means that if you use a bright tint color, then the original colors in the button bar will be brightened. It might be necessary to specify a negative value for the mouseOverBrightenPct parameter in order to prevent the button bar from having a "washed out" appearance.

Usually a small tint value will yield the best results. For instance, a red only tint value of "180000" will appear nearly black on it's own, but when added to the colors in the button image will result in the button image having a reddish tint. If a larger red value was used, for instance "ff0000", the button would probably appear far too red (large values can, however, be useful). The moral is, start small and then increase the tint color value a little at a time until the desired effect is achieved. Also, don't forget to experiment with adjusting the mouseOverBrightenPct parameter value in combination with the mouseOverBrightenTint parameter value.
mouseDownBrightenAll (boolean)

If drawButtonBorders is configured to draw button borders for the mouseDown button bar (i.e., the parameter is assigned a value of BORDERS_OTHER or BORDERS_ALL), then the mouseDownBrightenPct parameter will be ignored.

In situations where you would like to specify a mouseDownBrightenPct or mouseDownBrightenTint (which requires that mouseDownBrightenPct not be equal to zero), then the mouseDownBrightenAll parameter can be used to override the default behavior of ignoring the mouseDownBrightenPct and mouseDownBrightenTint parameters.

If mouseDownBrightenAll is true, then the mouseDownBrightenPct and mouseDownBrightenTint parameters will always be used.

If mouseDownBrightenAll is false or unspecified, and if drawButtonBorders is assigned a value of BORDERS_OTHER or BORDERS_ALL, then the mouseDownBrightenPct and mouseDownBrightenTint parameters will be ignored.
mouseDownBrightenPct (int)

If the value of this parameter is greater than zero, then the "brightness" of the mouseDown button bar will be increased by the specified percentage.

If the value of this parameter is less than zero, then the "brightness" of the mouseDown button bar will be decreased by the specified percentage.

If the value of this parameter is zero, then the brightness of the mouseDown button bar will remain unchanged.

It is important to note that this parameter will be ignored if drawButtonBorders is configured to draw button borders for the mouseDown button bar (i.e., the parameter is assigned a value of BORDERS_OTHER or BORDERS_ALL) and if mouseDownBrightenAll is false or unspecified (see the mouseDownBrightenAll parameter for further details).

The value for this parameter must be between "-100" and "100" percent.
mouseDownBrightenTint (Color)

This parameter is a color that is used to"tint" the mouseDown button bar when it is "brightened" (see also the related mouseDownBrightenPct parameter).

For instance, if you want to give the mouseDown button bar a reddish tint, then you might specify a tint color that has a hex value of "330000" as, for example:

Color tintColor = new Color(0x33, 0, 0);

It is important to note that in order to tint the button bar, the mouseDownBrightenPct parameter must be assigned a value other than zero (the value can be positive or negative).

Also, note that tinting is an additive process. This means that if you use a bright tint color, then the original colors in the button bar will be brightened. It might be necessary to specify a negative value for the mouseDownBrightenPct parameter in order to prevent the button bar from having a "washed out" appearance.

Usually a small tint value will yield the best results. For instance, a red only tint value of "180000" will appear nearly black on it's own, but when added to the colors in the button image will result in the button image having a reddish tint. If a larger red value was used, for instance "ff0000", the button would probably appear far too red (large values can, however, be useful). The moral is, start small and then increase the tint color value a little at a time until the desired effect is achieved. Also, don't forget to experiment with adjusting the mouseDownBrightenPct parameter value in combination with the mouseDownBrightenTint parameter value.

Be aware that this parameter will be ignored if drawButtonBorders is configured to draw button borders for the mouseDown button bar (i.e., the parameter is assigned a value of BORDERS_OTHER or BORDERS_ALL) and if mouseDownBrightenAll is false or unspecified (see the mouseDownBrightenAll parameter for further details).
buttonsDisabledDimPct (int)

When a button is disabled, the ButtonBar class will display the button image using the buttonsDisabled button bar. In the case where the buttonsDisabled button bar is not specified, then the base bar is "dimmed" or "darkened" by the percentage given by this parameter.

If the value for this parameter is greater than zero, then the grayscale base bar is "brightened" by the specified percentage. If the value is less than zero, then the grayscale base bar is "darkened" by the specified percentage.

The value for this parameter must be between "-100" (brightest) and "100" (darkest) percent.

If no value is specified for this parameter, then its value defaults to "25."
grayBarBrighten (int)

In the case where a mouseOver button bar is not specified (see the mouseOverBar or mouseOverBarName parameter), then the base button bar (see the baseBar or baseBarName parameter) becomes the mouseOver bar and a grayscale version of the new mouseOver bar becomes the base bar. This parameter is used in creating the new grayscale base bar.

If the value for this parameter is greater than zero, then the grayscale base bar is "brightened" by the specified percentage. If the value is less than zero, then the grayscale base bar is "darkened" by the specified percentage.

Note that only color values are processed (using a weighted algorithm) by the percentage specified by this parameter -- gray values are not "brightened" or "darkened."

Remember, this parameter is only used when the class finds it necessary to create a grayscale base bar (i.e., when no mouseOver bar has been specified).

The value for this parameter must be between "-100" and "100" percent.
frameRate (int)

When a mouseOver2 button bar is specified (see the mouseOverBar2 or mouseOverBar2Name parameter), then two-frame animation will be performed when the mouse is moved within a button's boundaries. This parameter sets the delay (in milliseconds) that takes place between each frame of animation.

Animation is performed by alternating between the button's image on the mouseOver bar (see the mouseOverBar or mouseOverBarName parameter) and the button's image on the mouseOver2 bar.

Note that if a mouseOver2 bar is not specified (i.e., the parameter value is null), then this parameter will be ignored.
Copyright © 1997 by Modern Minds, Inc.