FileDocCategorySizeDatePackage
Layer.javaAPI DocJ2ME MIDP 2.06647Thu Nov 07 12:02:28 GMT 2002javax.microedition.lcdui.game

Layer

public abstract class Layer extends Object
A Layer is an abstract class representing a visual element of a game. Each Layer has position (in terms of the upper-left corner of its visual bounds), width, height, and can be made visible or invisible. Layer subclasses must implement a {@link #paint(Graphics)} method so that they can be rendered.

The Layer's (x,y) position is always interpreted relative to the coordinate system of the Graphics object that is passed to the Layer's paint() method. This coordinate system is referred to as the painter's coordinate system. The initial location of a Layer is (0,0).

since
MIDP 2.0

Fields Summary
int
x
position of layer in x offset
int
y
position of layer in y offset
int
width
width of layer
int
height
height of layer
boolean
visible
If the Layer is visible it will be drawn when paint is called.
Constructors Summary
Layer(int width, int height)
Creates a new Layer with the specified dimensions. This constructor is declared package scope to prevent developers from creating Layer subclasses By default, a Layer is visible and its upper-left corner is positioned at (0,0).

param
width The width of the layer, in pixels
param
height The height of the layer, in pixels

        setWidthImpl(width);
        setHeightImpl(height);
    
Methods Summary
public final intgetHeight()
Gets the current height of this layer, in pixels.

return
the height in pixels
see
#getWidth

	return height;
    
public final intgetWidth()
Gets the current width of this layer, in pixels.

return
the width in pixels
see
#getHeight

	return width;
    
public final intgetX()
Gets the horizontal position of this Layer's upper-left corner in the painter's coordinate system.

return
the Layer's horizontal position.
see
#getY
see
#setPosition
see
#move

        return x;
    
public final intgetY()
Gets the vertical position of this Layer's upper-left corner in the painter's coordinate system.

return
the Layer's vertical position.
see
#getX
see
#setPosition
see
#move

        return y;
    
public final booleanisVisible()
Gets the visibility of this Layer.

return
true if the Layer is visible, false if it is invisible.
see
#setVisible

        return visible;
    
public voidmove(int dx, int dy)
Moves this Layer by the specified horizontal and vertical distances.
The Layer's coordinates are subject to wrapping if the passed parameters will cause them to exceed beyond Integer.MAX_VALUE or Integer.MIN_VALUE.

param
dx the distance to move along horizontal axis (positive to the right, negative to the left)
param
dy the distance to move along vertical axis (positive down, negative up)
see
#setPosition
see
#getX
see
#getY

	
        x += dx;
        y += dy;
    
public abstract voidpaint(javax.microedition.lcdui.Graphics g)
Paints this Layer if it is visible. The upper-left corner of the Layer is rendered at it's current (x,y) position relative to the origin of the provided Graphics object. Applications may make use of Graphics clipping and translation to control where the Layer is rendered and to limit the region that is rendered.

Implementations of this method are responsible for checking if this Layer is visible; this method does nothing if the Layer is not visible.

The attributes of the Graphics object (clip region, translation, drawing color, etc.) are not modified as a result of calling this method.

param
g the graphics object for rendering the Layer
throws
NullPointerException if g is null

voidsetHeightImpl(int height)
Sets the current height of this layer, in pixels. The Layer's height is used to determine its bounds for rendering purposes.

param
height The height in pixels
throws
IllegalArgumentException if the specified height is less than 0
see
#setWidthImpl
see
#getHeight
see
#getWidth

        if (height < 0) {
            throw new IllegalArgumentException();
        }
        this.height = height;
    
public voidsetPosition(int x, int y)
Sets this Layer's position such that its upper-left corner is located at (x,y) in the painter's coordinate system. A Layer is located at (0,0) by default.

param
x the horizontal position
param
y the vertical position
see
#move
see
#getX
see
#getY

        this.x = x;
        this.y = y;
    
public voidsetVisible(boolean visible)
Sets the visibility of this Layer. A visible Layer is rendered when its {@link #paint(Graphics)} method is called; an invisible Layer is not rendered.

param
visible true to make the Layer visible, false to make it invisible
see
#isVisible

        this.visible = visible;
    
voidsetWidthImpl(int width)
Sets the current width of this layer, in pixels. The Layer's width is used to determine its bounds for rendering purposes.

param
width The width in pixels
throws
IllegalArgumentException if the specified width is less than 0
see
#setHeightImpl
see
#getHeight
see
#getWidth

 
        if (width < 0) {
            throw new IllegalArgumentException();
        }
        this.width = width;