waba.ui
Class Button

java.lang.Object
  |
  +--waba.ui.Control
        |
        +--waba.ui.Button

public class Button
extends Control

Button is a push button control.

Here is an example showing a push button being used:

 public class MyProgram extends MainWindow
 {
 Button pushB;

 public void onStart()
 {
    add(pushB = new Button("Push me"), CENTER,TOP); // PS: you can also create an image button with pushB = new Button(new Image("myimage.bmp"));
 }

 public void onEvent(Event event)
 {
   if (event.type == ControlEvent.PRESSED &&
      event.target == pushB)
   {
   ... handle pushB being pressed
 


Field Summary
protected  Color aColor
           
protected  boolean armed
           
protected  byte border
           
static byte BORDER_3D
           
static byte BORDER_NONE
           
static byte BORDER_SIMPLE
           
static int commonGap
          Set commonGap to a value to make all further buttons with the same internal gap.
protected  Color fColor
           
protected  Color[] fourColors
           
protected  int gap
           
protected  int hh
           
protected  boolean ignoreEvents
           
protected  Image img
           
protected  Color imgColor
           
protected  boolean isText
           
protected  Graphics myg
           
protected  String text
           
protected  int ww
           
 
Fields inherited from class waba.ui.Control
AFTER, appId, asContainer, asWindow, backColor, backDis, BEFORE, BOTTOM, CENTER, enabled, FILL, FIT, fm, fmH, focusLess, font, foreColor, foreDis, height, LEFT, parent, PREFERRED, RANGE, RIGHT, SAME, TOP, visible, width, x, x2, y, y2
 
Constructor Summary
Button(Image img)
          Creates a button with the given image.
Button(String text)
          Creates a button displaying the given text.
 
Method Summary
static Button createArrowButton(byte type, int h, Color fore)
          just a handy method to create buttons with an arrow drawed.
 Image getImage()
          Returns the image that is assigned to this Button
 int getPreferredHeight()
          returns the preffered height of this control. added by guich
 int getPreferredWidth()
          returns the preffered width of this control. added by guich
 String getText()
          Gets the text displayed in the button.
protected  void onBoundsChanged()
          Called after an setRect.
protected  void onColorsChanged(boolean colorsChanged)
          Called after a setEnabled, setForeColor and setBackColor and when a control has been added to a Container.
 void onEvent(Event event)
          Called by the system to pass events to the button.
protected  void onFontChanged()
          Called after a setFont
 void onlyShowImage()
          Make this button act like an image control.
 void onPaint(Graphics g)
          Called by the system to draw the button. it cuts the text if the button is too small.
protected  void paintButton(Graphics g, boolean armed)
           
 void press(boolean pressed)
          simulate the press or release of this button. does not generate events
 void setBorder(byte border)
          Sets the style of the border. use the constants BORDER_xxx
 void setGap(int gap)
          Sets the gap between the text/image and the border.
 void setText(String text)
          Sets the text that is displayed in the button.
 
Methods inherited from class waba.ui.Control
addTimer, contains, createGraphics, getAbsoluteRect, getBackColor, getFont, getFontMetrics, getForeColor, getNext, getParent, getParentWindow, getPos, getRect, getSize, isDisplayed, isEnabled, isVisible, onWindowPaintFinished, postEvent, removeTimer, repaint, repaintNow, requestFocus, setBackColor, setBackForeColors, setEnabled, setFocusLess, setFont, setForeColor, setRect, setRect, setRect, setVisible
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, toString, wait, wait
 

Field Detail

BORDER_NONE

public static final byte BORDER_NONE

BORDER_SIMPLE

public static final byte BORDER_SIMPLE

BORDER_3D

public static final byte BORDER_3D

text

protected String text

img

protected Image img

armed

protected boolean armed

isText

protected boolean isText

gap

protected int gap

border

protected byte border

ww

protected int ww

hh

protected int hh

fColor

protected Color fColor

imgColor

protected Color imgColor

aColor

protected Color aColor

myg

protected Graphics myg

fourColors

protected Color[] fourColors

ignoreEvents

protected boolean ignoreEvents

commonGap

public static int commonGap
Set commonGap to a value to make all further buttons with the same internal gap. This is useful when you're creating the buttons but don't want to keep calling the setGap method. Note that this value will be added to the value of gap. Remember to save the current value and restore it when done.
Constructor Detail

Button

public Button(String text)
Creates a button displaying the given text.

Button

public Button(Image img)
Creates a button with the given image. The transparentColor property of the Image must be set before calling this constructor.
Method Detail

setText

public void setText(String text)
Sets the text that is displayed in the button.

onlyShowImage

public void onlyShowImage()
Make this button act like an image control. The button will have no border and will ignore all events

setBorder

public void setBorder(byte border)
Sets the style of the border. use the constants BORDER_xxx

setGap

public void setGap(int gap)
Sets the gap between the text/image and the border. The default is 1. used when the size is set using the PREFERRED constant.

getText

public String getText()
Gets the text displayed in the button.

getPreferredWidth

public int getPreferredWidth()
returns the preffered width of this control. added by guich
Overrides:
getPreferredWidth in class Control

getPreferredHeight

public int getPreferredHeight()
returns the preffered height of this control. added by guich
Overrides:
getPreferredHeight in class Control

onEvent

public void onEvent(Event event)
Called by the system to pass events to the button.
Overrides:
onEvent in class Control
Tags copied from class: Control
Parameters:
event - the event to process
See Also:
Event, KeyEvent, PenEvent

press

public void press(boolean pressed)
simulate the press or release of this button. does not generate events

onPaint

public void onPaint(Graphics g)
Called by the system to draw the button. it cuts the text if the button is too small.
Overrides:
onPaint in class Control
Tags copied from class: Control
Parameters:
g - the graphics object for drawing
See Also:
Graphics

onFontChanged

protected void onFontChanged()
Description copied from class: Control
Called after a setFont
Overrides:
onFontChanged in class Control

onBoundsChanged

protected void onBoundsChanged()
Description copied from class: Control
Called after an setRect.
Overrides:
onBoundsChanged in class Control

onColorsChanged

protected void onColorsChanged(boolean colorsChanged)
Description copied from class: Control
Called after a setEnabled, setForeColor and setBackColor and when a control has been added to a Container. If colorsChanged is true, it was called from setForeColor/setBackColor/Container.add; otherwise, it was called from setEnabled
Overrides:
onColorsChanged in class Control

paintButton

protected void paintButton(Graphics g,
                           boolean armed)

createArrowButton

public static Button createArrowButton(byte type,
                                       int h,
                                       Color fore)
just a handy method to create buttons with an arrow drawed.
Parameters:
byte - Graphics.ARROW_UP or Graphics.ARROW_DOWN or Graphics.ARROW_LEFT or Graphics.ARROW_RIGHT
h - same of Graphics.drawArrow
fore - the foreground color for the arrow. the background color will be the required transparent color.
See Also:
Graphics.drawArrow(int, int, int, byte, boolean, boolean, Color)

getImage

public Image getImage()
Returns the image that is assigned to this Button