All Packages This Package Class Hierarchy Class Search Index
java.lang.Object | +----java.awt.Component | +----java.awt.Canvas | +----aima.examples.OurButton
A simple Java Beans button. OurButton is a "from-scratch" GUI component that's derived from Canvas. 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.tint.TinyButtonPeer.
public class OurButton extends java.awt.Canvas implements java.io.Serializable, java.awt.event.MouseListener, java.awt.event.MouseMotionListener { // Constructors 2 public OurButton(); public OurButton(String); // Methods 28 public synchronized void addActionListener(ActionListener); public void addPropertyChangeListener(PropertyChangeListener); public void fireAction(); public boolean getDebug(); public int getFontSize(); public String getLabel(); public Dimension getMinimumSize(); public Dimension getPreferredSize(); public boolean isLargeFont();public Dimension minimumSize(); public void mouseClicked(MouseEvent); public void mouseDragged(MouseEvent); public void mouseEntered(MouseEvent); public void mouseExited(MouseEvent); public void mouseMoved(MouseEvent); public void mousePressed(MouseEvent); public void mouseReleased(MouseEvent); public synchronized void paint(Graphics);public Dimension preferredSize(); public synchronized void removeActionListener(ActionListener); public void removePropertyChangeListener(PropertyChangeListener); public void setBackground(Color); public void setDebug(boolean); public void setFont(Font); public void setFontSize(int); public void setForeground(Color); public void setLabel(String); public void setLargeFont(boolean); }
public OurButton()
Constructs a Button with the a default label.
public OurButton(String label)
Constructs a Button with the specified label.
Parameter Description label the label of the button
public synchronized void paint(Graphics g)
Paint the button: the label is centered in both dimensions.
- Overrides:
- paint in class Canvas
public void mouseClicked(MouseEvent evt)
- Implements:
- mouseClicked in interface MouseListener
public void mousePressed(MouseEvent evt)
- Implements:
- mousePressed in interface MouseListener
public void mouseReleased(MouseEvent evt)
- Implements:
- mouseReleased in interface MouseListener
public void mouseEntered(MouseEvent evt)
- Implements:
- mouseEntered in interface MouseListener
public void mouseExited(MouseEvent evt)
- Implements:
- mouseExited in interface MouseListener
public void mouseDragged(MouseEvent evt)
- Implements:
- mouseDragged in interface MouseMotionListener
public void mouseMoved(MouseEvent evt)
- Implements:
- mouseMoved in interface MouseMotionListener
public synchronized void addActionListener(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.
Parameter Description l the ActionListener
See Also: removeActionListener
public synchronized void removeActionListener(ActionListener l)
Remove this ActionListener from the buttons internal list. If the ActionListener isn't on the list, silently do nothing.
Parameter Description l the ActionListener
See Also: addActionListener
public void addPropertyChangeListener(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.
Parameter Description l the PropertyChangeListener
See Also: removePropertyChangeListener
public void removePropertyChangeListener(PropertyChangeListener l)
Remove this PropertyChangeListener from the buttons internal list. If the PropertyChangeListener isn't on the list, silently do nothing.
Parameter Description l the PropertyChangeListener
See Also: addPropertyChangeListener
public void fireAction()
This method has the same effect as pressing the button.
See Also: addActionListener
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
public boolean getDebug()
Returns true if debugging output is enabled.
See Also: setDebug
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
public boolean isLargeFont()
Returns true if the font is "large" in the sense defined by setLargeFont.
See Also: setLargeFont, setFont
public void setFontSize(int x)
Set the point size of the current font. This is a bound property.
See Also: getFontSize, setFont, setLargeFont, addPropertyChangeListener
public int getFontSize()
Return the current font point size.
See Also: setFontSize
public void setFont(Font f)
Set the current font and change its size to fit. This is a bound property.
- Overrides:
- setFont in class Component
See Also: setFontSize, setLargeFont
public void setLabel(String newLabel)
Set the buttons label and change it's size to fit. This is a bound property.
See Also: getLabel
public String getLabel()
Returns the buttons label.
See Also: setLabel
public Dimension getPreferredSize()
- Overrides:
- getPreferredSize in class Component
public Dimension preferredSize()
Note: preferredSize() is deprecated provided for backward compatibility with old layout managers.
- Overrides:
- preferredSize in class Component
public Dimension getMinimumSize()
- Overrides:
- getMinimumSize in class Component
public Dimension minimumSize()
Note: minimumSize() is deprecated provided for backward compatibility with old layout managers.
- Overrides:
- minimumSize in class Component
public void setForeground(Color c)
Set the color the buttons label is drawn with. This is a bound property.
- Overrides:
- setForeground in class Component
public void setBackground(Color c)
Set the color the buttons background is drawn with. This is a bound property.
- Overrides:
- setBackground in class Component
All Packages This Package Class Hierarchy Class Search IndexFreshly brewed Java API Documentation automatically generated with polardoc Version 1.0.4