|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjavax.microedition.lcdui.Displayable
javax.microedition.lcdui.Canvas
javax.microedition.lcdui.game.GameCanvas
net.kbox.component.KGameCanvas
public abstract class KGameCanvas
The event model of GameCanvas is stinking: is A canvas worth of a thread? It
seems sometime we have to face with so many thread which used to control
GameCanvas,or be busying to decide which GameCanvas to be
listening.KGameCanvas is design to solve such problems. It rewrite keypressed
method inherit from Canvas. All the keypressed event will be receive by a
ActionController which is the command listener too.
All the key event was map with a name:
Canvas.UP: "UP"
Canvas.DOWN:"DOWN"
Canvas.LEFT:"LEFT"
Canvas.RIGHT:"RIGHT"
Canvas.FIRE:"FIRE"
Canvas.KEY_NUM0:"0"
Canvas.KEY_NUM1:"1"
Canvas.KEY_NUM2:"2"
Canvas.KEY_NUM3:"3"
Canvas.KEY_NUM4:"4"
Canvas.KEY_NUM5:"5"
Canvas.KEY_NUM6:"6"
Canvas.KEY_NUM7:"7"
Canvas.KEY_NUM8:"8"
Canvas.KEY_NUM9:"9"
Canvas.KEY_NUM#:"#"
Canvas.KEY_NUM*:"*"
These mapping name is used for mapping when forward the event.
If a key pressed event was needed to deal, for example, LEFT key pressed, it
can be deal like this way:
1.Specify the action for dealing this key pressed event in kbox.cfg.property:
...
KEY.[Container ID].LEFT.ACTION=foo.boo.LeftAction
...
[Container ID] is the KGameCanvas which contain product this key pressed
event.
2.Design your deal class:
public LeftAction implements Action{
public void excute(KCommand cmd, Displayable dis, ActionForward
forward,Hashtable parameters){
System.out.println("Left hello!");
}
}
KGameCanvas also have dealt with the repeat key pressed event.
Field Summary | |
---|---|
protected KCommand[] |
cmds
kcommands added to KGameCanvas |
protected ActionController |
controller
the event forward controller. |
protected boolean |
isPressed
true if a key is pressed. |
protected boolean |
isThreadSafe
|
protected int |
keyPressedDelay
keyPressedDelay representing how sensitive the KGameCanvas is. |
protected int |
keyPressedDelayDESC
keyPressedDelayDESC use for reducing the value of keyPressedDelay. |
protected int |
minDelay
minDelay specified the min value of keyPressedDelay. |
protected java.lang.String |
uniqueID
uniqueID used for mapping. |
Fields inherited from class javax.microedition.lcdui.game.GameCanvas |
---|
DOWN_PRESSED, FIRE_PRESSED, GAME_A_PRESSED, GAME_B_PRESSED, GAME_C_PRESSED, GAME_D_PRESSED, LEFT_PRESSED, RIGHT_PRESSED, UP_PRESSED |
Fields inherited from class javax.microedition.lcdui.Canvas |
---|
DOWN, FIRE, GAME_A, GAME_B, GAME_C, GAME_D, KEY_NUM0, KEY_NUM1, KEY_NUM2, KEY_NUM3, KEY_NUM4, KEY_NUM5, KEY_NUM6, KEY_NUM7, KEY_NUM8, KEY_NUM9, KEY_POUND, KEY_STAR, LEFT, RIGHT, UP |
Constructor Summary | |
---|---|
KGameCanvas(java.lang.String uniqueID)
Create a new KGameCanvas. |
|
KGameCanvas(java.lang.String uniqueID,
int keyPressedDelay,
int keyPressedDelayDESC,
int minDelay)
Create a KGameCanvas with specified sensitive value. |
|
KGameCanvas(java.lang.String uniqueID,
int keyPressedDelay,
int keyPressedDelayDESC,
int minDelay,
boolean isThreadSafe)
Create a KGameCanvas with specified sensitive value. |
Method Summary | |
---|---|
void |
addCommand(javax.microedition.lcdui.Command cmd)
Over write addCommand() to make sure that KCommands with same uniqueID will be added just once. |
void |
addCommand(javax.microedition.lcdui.Command cmd,
boolean isUnique)
Add a command. |
KCommand[] |
getKCommand(java.lang.String uniqueId)
Get KCommand with specified uniqueId added to KGameCanvas |
java.lang.String |
getUniqueID()
Return a Unique id used to identify a component. |
boolean |
isThreadSafe()
|
protected void |
keyPressed(int keyCode)
keyPressed event method. |
protected void |
keyReleased(int keyCode)
stop repeat key pressed event. |
protected java.lang.String |
mapKeyCode(int keyCode)
Mapping keyCode to a name. |
void |
removeAllKCommand()
Remove all KCommand; |
KCommand[] |
removeKCommand(java.lang.String uniqueId)
Remove KCommand with specified uniqueId. |
void |
setCommandListener(javax.microedition.lcdui.CommandListener listener)
Bind to a Action Controller. |
void |
setThreadSafe(boolean isThreadSafe)
|
void |
setUniqueID(java.lang.String uniqueID)
|
Methods inherited from class javax.microedition.lcdui.game.GameCanvas |
---|
flushGraphics, flushGraphics, getGraphics, getKeyStates, paint |
Methods inherited from class javax.microedition.lcdui.Canvas |
---|
getGameAction, getKeyCode, getKeyName, hasPointerEvents, hasPointerMotionEvents, hasRepeatEvents, hideNotify, isDoubleBuffered, keyRepeated, pointerDragged, pointerPressed, pointerReleased, repaint, repaint, serviceRepaints, setFullScreenMode, showNotify, sizeChanged |
Methods inherited from class javax.microedition.lcdui.Displayable |
---|
getHeight, getTicker, getTitle, getWidth, isShown, removeCommand, setTicker, setTitle |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected java.lang.String uniqueID
protected ActionController controller
protected boolean isPressed
protected int keyPressedDelay
protected int keyPressedDelayDESC
protected int minDelay
protected KCommand[] cmds
protected boolean isThreadSafe
Constructor Detail |
---|
public KGameCanvas(java.lang.String uniqueID)
uniqueID
- public KGameCanvas(java.lang.String uniqueID, int keyPressedDelay, int keyPressedDelayDESC, int minDelay)
uniqueID
- keyPressedDelay
- keyPressedDelayDESC
- minDelay
- public KGameCanvas(java.lang.String uniqueID, int keyPressedDelay, int keyPressedDelayDESC, int minDelay, boolean isThreadSafe)
uniqueID
- keyPressedDelay
- keyPressedDelayDESC
- minDelay
- isThreadSafe
- Method Detail |
---|
public void addCommand(javax.microedition.lcdui.Command cmd)
addCommand
in class javax.microedition.lcdui.Displayable
public void addCommand(javax.microedition.lcdui.Command cmd, boolean isUnique)
cmd
- the command to be added.isUnique
- if is a unique command.public KCommand[] getKCommand(java.lang.String uniqueId)
uniqueId
- uniqueId of a KCommand
public KCommand[] removeKCommand(java.lang.String uniqueId)
uniqueId
- uniqueId of a KCommand
public void removeAllKCommand()
protected void keyPressed(int keyCode)
keyPressed
in class javax.microedition.lcdui.Canvas
protected java.lang.String mapKeyCode(int keyCode)
keyCode
- protected void keyReleased(int keyCode)
keyReleased
in class javax.microedition.lcdui.Canvas
public void setCommandListener(javax.microedition.lcdui.CommandListener listener)
setCommandListener
in class javax.microedition.lcdui.Displayable
public boolean isThreadSafe()
public void setThreadSafe(boolean isThreadSafe)
public void setUniqueID(java.lang.String uniqueID)
public java.lang.String getUniqueID()
Unique
getUniqueID
in interface Unique
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |