|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.j4me.ui.components.Component
public abstract class Component
Components are UI widgets that appear on forms. Examples of components include
labels, text boxes, and check boxes. The Dialog
class calls methods on
this interface to layout, paint, and manage components.
Field Summary | |
---|---|
protected Component |
container
A component this one is embedded within. |
protected static int |
HIGHLIGHTED_BORDER_WIDTH
Components that highlight entry boxes should use this value as a width for their borders. |
Constructor Summary | |
---|---|
Component()
Constructs a component and attaches it to a screen. |
Method Summary | |
---|---|
boolean |
acceptsInput()
Tells if this component accepts user input or not. |
int |
getHeight()
|
int |
getHorizontalAlignment()
|
protected abstract int[] |
getPreferredComponentSize(Theme theme,
int viewportWidth,
int viewportHeight)
Returns the desired width and height of this component in pixels. |
int[] |
getPreferredSize(Theme theme,
int viewportWidth,
int viewportHeight)
Returns the desired width and height of this component in pixels. |
DeviceScreen |
getScreen()
|
int |
getWidth()
|
int |
getX()
|
int |
getY()
|
protected void |
hideNotify()
An event raised whenever the component is removed from the screen. |
protected void |
invalidate()
Signals that the Component's size needs to be updated. |
boolean |
isShown()
Returns if this component is shown on the screen now. |
void |
keyPressed(int keyCode)
Called when a key is pressed. |
void |
keyReleased(int keyCode)
Called when a key is released. |
void |
keyRepeated(int keyCode)
Called when a key is repeated (held down). |
void |
paint(javax.microedition.lcdui.Graphics g,
Theme theme,
DeviceScreen screen,
int x,
int y,
int width,
int height,
boolean selected)
Paints the component using g . |
protected abstract void |
paintComponent(javax.microedition.lcdui.Graphics g,
Theme theme,
int width,
int height,
boolean selected)
Implemented by the subclass to render the item within its container. |
protected static int |
paintRect(javax.microedition.lcdui.Graphics g,
Theme theme,
int x,
int y,
int width,
int height,
boolean selected)
Paints a rectangle used within a component. |
void |
pointerDragged(int x,
int y)
Called when the pointer is dragged. |
void |
pointerPressed(int x,
int y)
Called when the pointer is pressed. |
void |
pointerReleased(int x,
int y)
Called when the pointer is released. |
void |
repaint()
Forces this component to repaint itself. |
void |
setHorizontalAlignment(int alignment)
|
protected void |
showNotify()
An event raised whenever the component is made visible on the screen. |
void |
visible(boolean visible)
Sets if the component is currently shown on the screen or not. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static final int HIGHLIGHTED_BORDER_WIDTH
protected Component container
null
.
Constructor Detail |
---|
public Component()
Method Detail |
---|
public final void paint(javax.microedition.lcdui.Graphics g, Theme theme, DeviceScreen screen, int x, int y, int width, int height, boolean selected)
g
. The top-left corner is at (0,0)
and the component fills the rectangle bounded by width
and
height
.
g
- is the Graphics
object to be used for rendering the item.theme
- is the application's theme. Use it to get fonts and colors.screen
- is the screen object displaying this component.x
- is the left corner pixel of the component.y
- is the top corner pixel of the component.width
- is the width, in pixels, to paint the component.height
- is the height, in pixels, to paint the component.selected
- is true
when this components is currently selected
and false
when it is not.protected abstract void paintComponent(javax.microedition.lcdui.Graphics g, Theme theme, int width, int height, boolean selected)
Graphic
s context's destination is the content area of
this Component
(or back buffer for it). The translation is set so that
the upper left corner of the content area is at (0,0), and the clip is set
to the area to be painted. The application must paint every pixel within
the given clip area. The item is allowed to modify the clip area, but the
system must not allow any modification to result in drawing outside the
bounds of the item's content area. The w
and h
passed in are the width
and height of the content area of the item. These values will always be
set to the clip width and height and are passed here for convenience.
Other values of the Graphics
object are as follows:
Theme.getFontColor()
;
Theme.getFont()
;
SOLID
;
The paint()
method will be called only when at least a portion of the
item is actually visible on the display.
g
- is the Graphics
object to be used for rendering the item.theme
- is the application's theme. Use it to get fonts and colors.width
- is the width, in pixels, to paint the component.height
- is the height, in pixels, to paint the component.selected
- is true
when this components is currently selected
and false
when it is not.public final int[] getPreferredSize(Theme theme, int viewportWidth, int viewportHeight)
theme
- is the application's Theme
.viewportWidth
- is the width of the screen in pixels.viewportHeight
- is the height of the screen in pixels.
protected abstract int[] getPreferredComponentSize(Theme theme, int viewportWidth, int viewportHeight)
theme
- is the application's Theme
.viewportWidth
- is the width of the viewable area, in pixels,
the component can use.viewportHeight
- is the height of the viewable area, in pixels,
the component can use.
public boolean acceptsInput()
The default implementation returns false
. Override this method
to return true
if the component accepts input.
true
if the component accepts user input; false
if
it does not.public DeviceScreen getScreen()
public int getX()
public int getY()
public int getWidth()
public int getHeight()
public int getHorizontalAlignment()
Graphics.LEFT
, Graphics.HCENTER
, and Graphics.RIGHT
.public void setHorizontalAlignment(int alignment)
alignment
- is how the text in the label is justified. It is one of
Graphics.LEFT
, Graphics.HCENTER
, and Graphics.RIGHT
.public void visible(boolean visible)
show(true)
must be made before paint
.
When the component is no longer visible call show(false)
so that the component may clean up any resources.
visible
- when true
indicates the component is painted (or
about to be) on the screen.public boolean isShown()
true
if this component is currently visible on the
screen; false
if not.protected void showNotify()
paintComponent
method.
The default implementation does nothing. Override it to initialize any resources required by the component.
protected void hideNotify()
The default implementation does nothing. Override it to clean up any resources required by the component.
protected void invalidate()
Dialog.invalidate()
public void repaint()
public void keyPressed(int keyCode)
DeviceScreen
class. Note to
receive key events the component must override acceptsInput
to return true
.
The default implementation does nothing. If a component requires keypad interaction, such as to enter text, it should override this method.
keyCode
- is the key code of the key that was pressed.public void keyRepeated(int keyCode)
DeviceScreen
class. Note to
receive key events the component must override acceptsInput
to return true
.
The default implementation does nothing. If a component requires keypad interaction, such as to enter text, it should override this method.
keyCode
- is the key code of the key that was held down.public void keyReleased(int keyCode)
DeviceScreen
class. Note to
receive key events the component must override acceptsInput
to return true
.
The default implementation does nothing. If a component requires keypad interaction, such as to enter text, it should override this method.
keyCode
- is the key code of the key that was released.public void pointerPressed(int x, int y)
x
- is the horizontal location where the pointer was pressed
relative to the top-left corner of the component.y
- is the vertical location where the pointer was pressed
relative to the top-left corner of the component.public void pointerReleased(int x, int y)
x
- is the horizontal location where the pointer was released
relative to the top-left corner of the component.y
- is the vertical location where the pointer was released
relative to the top-left corner of the component.public void pointerDragged(int x, int y)
x
- is the horizontal location where the pointer was dragged
relative to the top-left corner of the component.y
- is the vertical location where the pointer was dragged
relative to the top-left corner of the component.protected static int paintRect(javax.microedition.lcdui.Graphics g, Theme theme, int x, int y, int width, int height, boolean selected)
selected
it will have rounded edges and be highlighted. If it
is not it will have square edges and be slightly inset from
(x
, y
). The border color, highlight color, and inner
part of the rectangle (background color) all come from the theme
.
g
- is the Graphics
object to be used for rendering the item.theme
- is the application's theme. Use it to get fonts and colors.x
- is the left side of the box.y
- is the top of the box.width
- is the width, in pixels, to paint the component.height
- is the height, in pixels, to paint the component.selected
- is true
when this components is currently selected
and false
when it is not.
(x + offset, y + offset,
width - 2 * offset, height - 2 * offset)
.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |