sunw.demo.buttons
Class OurButton

java.lang.Object
  |
  +--java.awt.Component
        |
        +--sunw.demo.buttons.OurButton
Direct Known Subclasses:
ExplicitButton

public class OurButton
extends java.awt.Component
implements java.io.Serializable, java.awt.event.MouseListener, java.awt.event.MouseMotionListener

A simple Java Beans button. OurButton is a "from-scratch" lightweight AWT component. It's a good example of how to implement bound properties and support for event listeners. Parts of the source are derived from sun.awt.tiny.TinyButtonPeer.

See Also:
Serialized Form

Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Constructor Summary
OurButton()
          Constructs a Button with the a default label.
OurButton(java.lang.String label)
          Constructs a Button with the specified label.
 
Method Summary
 void addActionListener(java.awt.event.ActionListener l)
          The specified ActionListeners actionPerformed method will be called each time the button is clicked.
 void addPropertyChangeListener(java.beans.PropertyChangeListener l)
          The specified PropertyChangeListeners propertyChange method will be called each time the value of any bound property is changed.
 void fireAction()
          This method has the same effect as pressing the button.
 boolean getDebug()
          Returns true if debugging output is enabled.
 int getFontSize()
          Return the current font point size.
 java.lang.String getLabel()
          Returns the buttons label.
 java.awt.Dimension getMinimumSize()
           
 java.awt.Dimension getPreferredSize()
           
 boolean isLargeFont()
          Returns true if the font is "large" in the sense defined by setLargeFont.
 java.awt.Dimension minimumSize()
          Deprecated. provided for backward compatibility with old layout managers.
 void mouseClicked(java.awt.event.MouseEvent evt)
           
 void mouseDragged(java.awt.event.MouseEvent evt)
           
 void mouseEntered(java.awt.event.MouseEvent evt)
           
 void mouseExited(java.awt.event.MouseEvent evt)
           
 void mouseMoved(java.awt.event.MouseEvent evt)
           
 void mousePressed(java.awt.event.MouseEvent evt)
           
 void mouseReleased(java.awt.event.MouseEvent evt)
           
 void paint(java.awt.Graphics g)
          Paint the button: the label is centered in both dimensions.
 java.awt.Dimension preferredSize()
          Deprecated. provided for backward compatibility with old layout managers.
 void removeActionListener(java.awt.event.ActionListener l)
          Remove this ActionListener from the buttons internal list.
 void removePropertyChangeListener(java.beans.PropertyChangeListener l)
          Remove this PropertyChangeListener from the buttons internal list.
 void setBackground(java.awt.Color c)
          Set the color the buttons background is drawn with.
 void setDebug(boolean x)
          Enable debugging output.
 void setFont(java.awt.Font f)
          Set the current font and change its size to fit.
 void setFontSize(int x)
          Set the point size of the current font.
 void setForeground(java.awt.Color c)
          Set the color the buttons label is drawn with.
 void setLabel(java.lang.String newLabel)
          Set the buttons label and change it's size to fit.
 void setLargeFont(boolean b)
          Set the font size to 18 if true, 12 otherwise.
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addNotify, addPropertyChangeListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, getAlignmentX, getAlignmentY, getBackground, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphics, getHeight, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getName, getParent, getPeer, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isDisplayable, isDoubleBuffered, isEnabled, isFocusTraversable, isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, paramString, postEvent, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, processFocusEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, remove, removeComponentListener, removeFocusListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeNotify, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, reshape, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus, update, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

OurButton

public OurButton()
Constructs a Button with the a default label.

OurButton

public OurButton(java.lang.String label)
Constructs a Button with the specified label.
Parameters:
label - the label of the button
Method Detail

paint

public void paint(java.awt.Graphics g)
Paint the button: the label is centered in both dimensions.
Overrides:
paint in class java.awt.Component

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent evt)
Specified by:
mouseClicked in interface java.awt.event.MouseListener

mousePressed

public void mousePressed(java.awt.event.MouseEvent evt)
Specified by:
mousePressed in interface java.awt.event.MouseListener

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent evt)
Specified by:
mouseReleased in interface java.awt.event.MouseListener

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent evt)
Specified by:
mouseEntered in interface java.awt.event.MouseListener

mouseExited

public void mouseExited(java.awt.event.MouseEvent evt)
Specified by:
mouseExited in interface java.awt.event.MouseListener

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent evt)
Specified by:
mouseDragged in interface java.awt.event.MouseMotionListener

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent evt)
Specified by:
mouseMoved in interface java.awt.event.MouseMotionListener

addActionListener

public void addActionListener(java.awt.event.ActionListener l)
The specified ActionListeners actionPerformed method will be called each time the button is clicked. The ActionListener object is added to a list of ActionListeners managed by this button, it can be removed with removeActionListener. Note: the JavaBeans specification does not require ActionListeners to run in any particular order.
Parameters:
l - the ActionListener
See Also:
removeActionListener(java.awt.event.ActionListener)

removeActionListener

public void removeActionListener(java.awt.event.ActionListener l)
Remove this ActionListener from the buttons internal list. If the ActionListener isn't on the list, silently do nothing.
Parameters:
l - the ActionListener
See Also:
addActionListener(java.awt.event.ActionListener)

addPropertyChangeListener

public void addPropertyChangeListener(java.beans.PropertyChangeListener l)
The specified PropertyChangeListeners propertyChange method will be called each time the value of any bound property is changed. The PropertyListener object is addded to a list of PropertyChangeListeners managed by this button, it can be removed with removePropertyChangeListener. Note: the JavaBeans specification does not require PropertyChangeListeners to run in any particular order.
Overrides:
addPropertyChangeListener in class java.awt.Component
Parameters:
l - the PropertyChangeListener
See Also:
removePropertyChangeListener(java.beans.PropertyChangeListener)

removePropertyChangeListener

public void removePropertyChangeListener(java.beans.PropertyChangeListener l)
Remove this PropertyChangeListener from the buttons internal list. If the PropertyChangeListener isn't on the list, silently do nothing.
Overrides:
removePropertyChangeListener in class java.awt.Component
Parameters:
l - the PropertyChangeListener
See Also:
addPropertyChangeListener(java.beans.PropertyChangeListener)

fireAction

public void fireAction()
This method has the same effect as pressing the button.
See Also:
addActionListener(java.awt.event.ActionListener)

setDebug

public void setDebug(boolean x)
Enable debugging output. Currently a message is printed each time the button is clicked. This is a bound property.
See Also:
getDebug(), addPropertyChangeListener(java.beans.PropertyChangeListener)

getDebug

public boolean getDebug()
Returns true if debugging output is enabled.
See Also:
setDebug(boolean)

setLargeFont

public void setLargeFont(boolean b)
Set the font size to 18 if true, 12 otherwise. This property overrides the value specified with setFontSize. This is a bound property.
See Also:
isLargeFont(), addPropertyChangeListener(java.beans.PropertyChangeListener)

isLargeFont

public boolean isLargeFont()
Returns true if the font is "large" in the sense defined by setLargeFont.
See Also:
setLargeFont(boolean), setFont(java.awt.Font)

setFontSize

public void setFontSize(int x)
Set the point size of the current font. This is a bound property.
See Also:
getFontSize(), setFont(java.awt.Font), setLargeFont(boolean), addPropertyChangeListener(java.beans.PropertyChangeListener)

getFontSize

public int getFontSize()
Return the current font point size.
See Also:
setFontSize(int)

setFont

public void setFont(java.awt.Font f)
Set the current font and change its size to fit. This is a bound property.
Overrides:
setFont in class java.awt.Component
See Also:
setFontSize(int), setLargeFont(boolean)

setLabel

public void setLabel(java.lang.String newLabel)
Set the buttons label and change it's size to fit. This is a bound property.
See Also:
getLabel()

getLabel

public java.lang.String getLabel()
Returns the buttons label.
See Also:
setLabel(java.lang.String)

getPreferredSize

public java.awt.Dimension getPreferredSize()
Overrides:
getPreferredSize in class java.awt.Component

preferredSize

public java.awt.Dimension preferredSize()
Deprecated. provided for backward compatibility with old layout managers.

Overrides:
preferredSize in class java.awt.Component

getMinimumSize

public java.awt.Dimension getMinimumSize()
Overrides:
getMinimumSize in class java.awt.Component

minimumSize

public java.awt.Dimension minimumSize()
Deprecated. provided for backward compatibility with old layout managers.

Overrides:
minimumSize in class java.awt.Component

setForeground

public void setForeground(java.awt.Color c)
Set the color the buttons label is drawn with. This is a bound property.
Overrides:
setForeground in class java.awt.Component

setBackground

public void setBackground(java.awt.Color c)
Set the color the buttons background is drawn with. This is a bound property.
Overrides:
setBackground in class java.awt.Component