capella.GUI
Class ButtonImage

java.lang.Object
  extended by java.awt.Component
      extended by capella.GUI.ButtonImage
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable

public class ButtonImage
extends Component

A button class which use an image instead of a string label. Clicking (press + release) the mouse button triggers an actionEvent in a way similar to the standard java.awt.Button (Java 1.1).

Here is an example of its use:

 public class Test extends Frame implements ActionListener {
   public static void main(String argv[]) {
     Test t = new Test();
   }
   public Test() {
     setLayout(new BorderLayout());
     try {
       ButtonImage button = new ButtonImage(INSERT_AN_URL_HERE));
       add("North",button);
       button.addActionListener(this);
       button.setActionCommand("First Button");
       button = new ButtonImage(INSERT_A_FILENAME_HERE);
       add("South",button);
       button.addActionListener(this);
     }
     catch (Exception e) {}
     doLayout();
     pack();
     show();
   }
   public void actionPerformed(ActionEvent e) {
     System.out.println("ACTION PERFORMED "+e);
   }
 }
 

Since:
JDK1.1
Version:
1.01 (1998)
Author:
Jean-Baptiste Yunès (Jean-Baptiste.Yunes@liafa.jussieu.fr)
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
static Color BORDER_COLOR
          The default color used for border rendering.
static int BORDER_SIZE
          The default border size.
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
ButtonImage(String path)
           
ButtonImage(URL url)
           
 
Method Summary
 void addActionListener(ActionListener al)
          Adds the specified action listener to receive action events from this button.
 String getActionCommand()
          gets the command name.
 Color getBorderColor()
           
 int getBorderSize()
           
 int getHeight()
           
 Dimension getPreferredSize()
          gets the Dimension size for layouts
 int getWidth()
           
 boolean isUp()
           
 void paint(Graphics g)
          used to redraw the button if needed.
protected  void processActionEvent(ActionEvent e)
          process actionEvent on this button.
protected  void processEvent(AWTEvent e)
          process events on this button.
 void removeActionListener(ActionListener al)
          Removes the specified action listener so that it no longer receives action events from this button.
 void setActionCommand(String actionCommand)
          sets the command name.
 void setBorderColor(Color color)
           
 void setBorderSize(int size)
           
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleContext, getAlignmentX, getAlignmentY, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, update, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

BORDER_COLOR

public static final Color BORDER_COLOR
The default color used for border rendering.


BORDER_SIZE

public static final int BORDER_SIZE
The default border size.

See Also:
Constant Field Values
Constructor Detail

ButtonImage

public ButtonImage(URL url)
Parameters:
url - the URL of an image to be used as a label

ButtonImage

public ButtonImage(String path)
Parameters:
path - the pathname of an image to be used as a label
Method Detail

isUp

public boolean isUp()
Returns:
true if this button is actually raised. false if not.

getActionCommand

public String getActionCommand()
gets the command name. The default command name is the URL or pathname used as parameter in constructor, that is, the string used.

Returns:
command name of this button
See Also:
setActionCommand(java.lang.String)

getBorderSize

public int getBorderSize()
Returns:
actual size of the border
See Also:
setBorderSize(int)

getWidth

public int getWidth()
Overrides:
getWidth in class Component

getHeight

public int getHeight()
Overrides:
getHeight in class Component

getPreferredSize

public Dimension getPreferredSize()
gets the Dimension size for layouts

Overrides:
getPreferredSize in class Component
Returns:
the preferred size of this button including the border size

getBorderColor

public Color getBorderColor()
Returns:
the java.awt.Color object used for border rendering
See Also:
setBorderColor(java.awt.Color), BORDER_COLOR

setBorderSize

public void setBorderSize(int size)
Parameters:
size - the new size for the border. If negative, BORDER_SIZE is used.
See Also:
getBorderSize(), BORDER_SIZE

setBorderColor

public void setBorderColor(Color color)
Parameters:
color - the new color for the border. If null BORDER_COLOR is used.
See Also:
getBorderColor(), BORDER_COLOR

paint

public void paint(Graphics g)
used to redraw the button if needed. Called back by repaint on this widget. Don't forget to call this one if you plan to subclass this class and want its standard image rendering.

Overrides:
paint in class Component
Parameters:
g - used to carry drawing requests.

setActionCommand

public void setActionCommand(String actionCommand)
sets the command name. By default this action command is set to match the filename or url of the image used for rendering.

Parameters:
actionCommand - A String used to set the button's action command

processEvent

protected void processEvent(AWTEvent e)
process events on this button. Always invokes processEvent on the superclass.

Overrides:
processEvent in class Component
Parameters:
e - an AWTEvent to process.
See Also:
AWTEvent, processActionEvent(java.awt.event.ActionEvent)

processActionEvent

protected void processActionEvent(ActionEvent e)
process actionEvent on this button. Actually calls actionPerformed through a multicaster object.

Parameters:
e - an ActionEvent to process.
See Also:
ActionEvent, processEvent(java.awt.AWTEvent)

addActionListener

public void addActionListener(ActionListener al)
Adds the specified action listener to receive action events from this button. Action events occur when a user presses or releases the mouse over this button.

Parameters:
al - the action listener.

removeActionListener

public void removeActionListener(ActionListener al)
Removes the specified action listener so that it no longer receives action events from this button. Action events occur when a user presses or releases the mouse over this button.

Parameters:
al - the action listener.