Class ImageButton
Class ImageButton
java.lang.Object
|
+----java.awt.Component
|
+----java.awt.Canvas
|
+----ImageLabel
|
+----ImageButton
Note: To see an on-line demo,
see the page for
ImageButtons.html. To download the source code,
see ImageButton.java.
For more examples, see the
Core Web Programming source code archive.
- public class ImageButton
- extends ImageLabel
A button class that uses an image instead of a
textual label. Clicking and releasing the mouse over
the button triggers an ACTION_EVENT, so you can add
behavior in the same two ways as you with a normal
Button (in Java 1.0):
- Make an ImageButton subclass and put the
behavior in the action method of that subclass.
- Use the main ImageButton class but then catch
the events in the action method of the Container.
Normally, the ImageButton's preferredSize (used,
for instance, by FlowLayout) is just big enough
to hold the image. However, if you give an explicit
resize or reshape call before adding the
ImageButton to the Container, this size will
override the defaults.
- Version:
- 1.0 (1997)
- Author:
- Marty Hall (hall@apl.jhu.edu)
- See Also:
- Icon, GrayFilter
-
defaultBorderColor
- Default color of 3D border around image.
-
defaultBorderWidth
- Default width of 3D border around image.
-
ImageButton()
- Create an ImageButton with the default image.
-
ImageButton(Image)
- Create an ImageButton using the image specified.
-
ImageButton(String)
- Create an ImageButton using the image at URL
specified by the string.
-
ImageButton(URL)
- Create an ImageButton using the image at URL
specified.
-
ImageButton(URL, String)
- Creates an ImageButton using the file in
the directory specified.
-
action(Event, Object)
- Generated when the button is clicked and released.
-
getDarkness()
- The darkness value to use for grayed images.
-
getGrayImage()
- The gray image used when button is down.
-
mouseDown(Event, int, int)
- When the mouse is clicked, reverse the 3D border
and draw a dark-gray version of the image.
-
mouseExit(Event, int, int)
- If you move the mouse off the button while the
mouse is down, abort and do not trigger
the action.
-
mouseUp(Event, int, int)
- If cursor is still inside, trigger the action
event and redraw the image (non-gray, button
"out").
-
paint(Graphics)
- Draws the image with the border around it.
-
setDarkness(int)
- An int whose bits are combined via "and" ("&")
with the alpha, red, green, and blue bits of the
pixels of the image to produce the grayed-out
image to use when button is depressed.
-
setGrayImage(Image)
- Sets gray image created automatically from regular
image via an image filter to use when button is
depressed.
defaultBorderWidth
protected final static int defaultBorderWidth
- Default width of 3D border around image.
Currently 4.
- See Also:
- setBorder, getBorder
defaultBorderColor
protected final static Color defaultBorderColor
- Default color of 3D border around image.
Currently a gray with R/G/B of 160/160/160.
Light grays look best.
- See Also:
- setBorderColor, getBorderColor
ImageButton
public ImageButton()
- Create an ImageButton with the default image.
- See Also:
- getDefaultImageString
ImageButton
public ImageButton(String imageURLString)
- Create an ImageButton using the image at URL
specified by the string.
- Parameters:
- imageURLString - A String specifying the URL
of the image.
ImageButton
public ImageButton(URL imageURL)
- Create an ImageButton using the image at URL
specified.
- Parameters:
- imageURL - The URL of the image.
ImageButton
public ImageButton(URL imageDirectory,
String imageFile)
- Creates an ImageButton using the file in
the directory specified.
- Parameters:
- imageDirectory - The URL of a directory
- imageFile - File in the above directory
ImageButton
public ImageButton(Image image)
- Create an ImageButton using the image specified.
You would only want to use this if you already
have an image (e.g. created via createImage).
- Parameters:
- image - The image.
paint
public void paint(Graphics g)
- Draws the image with the border around it. If you
override this in a subclass, call super.paint().
- Overrides:
- paint in class ImageLabel
mouseDown
public boolean mouseDown(Event event,
int x,
int y)
- When the mouse is clicked, reverse the 3D border
and draw a dark-gray version of the image.
The action is not triggered until mouseUp.
- Overrides:
- mouseDown in class Component
mouseUp
public boolean mouseUp(Event event,
int x,
int y)
- If cursor is still inside, trigger the action
event and redraw the image (non-gray, button
"out"). Otherwise ignore this.
- Overrides:
- mouseUp in class Component
action
public boolean action(Event event,
Object arg)
- Generated when the button is clicked and released.
Override this in subclasses to give behavior to
the button. Alternatively, since the default
behavior is to pass the ACTION_EVENT along to the
Container, you can catch events for a bunch of
buttons there.
- Overrides:
- action in class Component
- See Also:
- action
mouseExit
public boolean mouseExit(Event event,
int x,
int y)
- If you move the mouse off the button while the
mouse is down, abort and do not trigger
the action. Ignore this if button was not
already down.
- Overrides:
- mouseExit in class Component
getDarkness
public int getDarkness()
- The darkness value to use for grayed images.
- See Also:
- setDarkness
setDarkness
public void setDarkness(int darkness)
- An int whose bits are combined via "and" ("&")
with the alpha, red, green, and blue bits of the
pixels of the image to produce the grayed-out
image to use when button is depressed.
Default is 0xffafafaf: af combines with r/g/b
to darken image.
getGrayImage
public Image getGrayImage()
- The gray image used when button is down.
- See Also:
- setGrayImage
setGrayImage
public void setGrayImage(Image grayImage)
- Sets gray image created automatically from regular
image via an image filter to use when button is
depressed. You won't normally use this directly.