Class wb.WBButton
All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class wb.WBButton

java.lang.Object
   |
   +----java.awt.Component
           |
           +----java.awt.Canvas
                   |
                   +----wb.WBButton

public class WBButton
extends Canvas
implements GTypes
WBButton, is the base unit for all buttons. It is an extension of canvas which has (more or less) same functionality as buttons and yet does not use ButtonPeer. When add to a layout, it displays a small rectangle onto which method draw can be used to draw anything including an image. A string or label for this button can also be displayed conditionally. In order to use this effectively, derive a class from this, and override the method (fill in) ``draw'' method to display appropriate graphics

Constructor Index

 o WBButton()
Creates an instance of this.
 o WBButton(String, boolean)
Creates an instance of this.
 o WBButton(String, WBDrawPanel, boolean)
Creates an instance of this.
 o WBButton(String, WBDrawPanel, boolean, int)
Creates an instance of this.

Method Index

 o action(Event, Object)
Called if an action occurs in the Component.
 o draw(Graphics)
Only Method that has to be overridden to draw the required on the available canvas.
 o drawFrame(Graphics, int, int, boolean)
Helper Internal Method that takes care of the borders of this button when pressed
 o getLabel()
Gets the label of the button.
 o handleEvent(Event)
Handles the event.
 o inside(int, int)
Internal method that tells the state of coordinates.
 o minimunSize()
Returns the minimum size of this component.
 o mouseDown(Event, int, int)
Called if the mouse is down.
 o mouseEnter(Event, int, int)
Called when the mouse enters the component.
 o mouseExit(Event, int, int)
Called if the mouse exits this component
 o mouseUp(Event, int, int)
Called when the mouse button is Up (released)
 o paint(Graphics)
Paints the component.
 o paramString()
Helper method to return the string representation of this
 o preferredSize()
Returns the preferred size of this component.
 o setPanel(WBDrawPanel)
Helper Method to set the Panel that holds this Button
 o setType(int)
Helper Method to set the type of this button
 o showText(boolean)
Helper Method to alter the state of the label display on the button
 o update(Graphics)
Updates the component.

Constructors

 o WBButton
  public WBButton()
Creates an instance of this.
 o WBButton
  public WBButton(String name,
                  boolean displaytext)
Creates an instance of this.
Parameters:
name - String that holds the name or label of this button
displaytext - boolean to indicate if the label is to be displayed
 o WBButton
  public WBButton(String name,
                  WBDrawPanel above,
                  boolean displaytext)
Creates an instance of this.
Parameters:
name - String that holds the name or label of this button
above - the Panel that holds this
displaytext - boolean to indicate if the label is to be displayed
 o WBButton
  public WBButton(String name,
                  WBDrawPanel above,
                  boolean displaytext,
                  int gtype)
Creates an instance of this.
Parameters:
name - String that holds the name or label of this button
above - the Panel that holds this
displaytext - boolean to indicate if the label is to be displayed
gtype - an int that is assigned to this button

Methods

 o showText
  public void showText(boolean flag)
Helper Method to alter the state of the label display on the button
Parameters:
flag - boolean that tells if the label is to be displayed
 o setPanel
  public void setPanel(WBDrawPanel arg)
Helper Method to set the Panel that holds this Button
Parameters:
arg - the WBDrawPanel that holds this.
 o setType
  public void setType(int gtype)
Helper Method to set the type of this button
Parameters:
gtype - int that is assigned to his button.
 o update
  public void update(Graphics g)
Updates the component. This method is called in response to a call to repaint.
Parameters:
g - the specified Graphics window
Overrides:
update in class Component
See Also:
paint
 o paint
  public void paint(Graphics g)
Paints the component.
Parameters:
g - the specified Graphics window
Overrides:
paint in class Canvas
See Also:
update
 o preferredSize
  public Dimension preferredSize()
Returns the preferred size of this component.
Overrides:
preferredSize in class Component
See Also:
minimumSize
 o minimunSize
  public Dimension minimunSize()
Returns the minimum size of this component.
See Also:
preferredSize, LayoutManager
 o getLabel
  public String getLabel()
Gets the label of the button. Useful for capturing the evt.target when an action event occcurs.
 o handleEvent
  public boolean handleEvent(Event evt)
Handles the event. Returns true if the event is handled and should not be passed to the parent of this component. It is required to overide the parent class handler since we are interested in repaint. did some changes. May be this is not required any more.
Parameters:
evt - the event
Overrides:
handleEvent in class Component
See Also:
mouseEnter, mouseExit, mouseDown, mouseUp
 o action
  public boolean action(Event evt,
                        Object what)
Called if an action occurs in the Component.
Parameters:
evt - the event
what - the action that's occuring
Overrides:
action in class Component
See Also:
handleEvent
 o mouseDown
  public boolean mouseDown(Event evt,
                           int x,
                           int y)
Called if the mouse is down.
Parameters:
evt - the event
x - the x coordinate
y - the y coordinate
Overrides:
mouseDown in class Component
See Also:
handleEvent
 o mouseExit
  public boolean mouseExit(Event evt,
                           int x,
                           int y)
Called if the mouse exits this component
Parameters:
evt - the event
x - the x coordinate
y - the y coordinate
Overrides:
mouseExit in class Component
See Also:
handleEvent
 o mouseEnter
  public boolean mouseEnter(Event evt,
                            int x,
                            int y)
Called when the mouse enters the component.
Parameters:
evt - the event
x - the x coordinate
y - the y coordinate
Overrides:
mouseEnter in class Component
See Also:
handleEvent
 o mouseUp
  public boolean mouseUp(Event evt,
                         int x,
                         int y)
Called when the mouse button is Up (released)
Parameters:
evt - the event
x - the x coordinate
y - the y coordinate
Overrides:
mouseUp in class Component
See Also:
handleEvent
 o draw
  protected void draw(Graphics g)
Only Method that has to be overridden to draw the required on the available canvas. left top = (5, 5) right bottom = (35, 25)
Parameters:
g - Graphics on to which the drawing is to be made.
 o drawFrame
  protected void drawFrame(Graphics g,
                           int width,
                           int height,
                           boolean pressed)
Helper Internal Method that takes care of the borders of this button when pressed
 o inside
  public boolean inside(int x,
                        int y)
Internal method that tells the state of coordinates. Was required to overide Java 's "inside" method. (bug fix)
Parameters:
x - the x-coordinate
y - the y-coordinate
Returns:
boolean true iff the (x,y) is inside this
Overrides:
inside in class Component
 o paramString
  protected String paramString()
Helper method to return the string representation of this
Returns:
String
Overrides:
paramString in class Component

All Packages  Class Hierarchy  This Package  Previous  Next  Index