本文整理汇总了Java中javax.microedition.lcdui.Canvas类的典型用法代码示例。如果您正苦于以下问题:Java Canvas类的具体用法?Java Canvas怎么用?Java Canvas使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Canvas类属于javax.microedition.lcdui包,在下文中一共展示了Canvas类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getGameAction
import javax.microedition.lcdui.Canvas; //导入依赖的package包/类
@Override
public int getGameAction(int keyCode) {
// TODO implement as lookup table
int gameAction;
switch (keyCode) {
case -5 :
gameAction = Canvas.FIRE;
break;
case -1 :
gameAction = Canvas.UP;
break;
case -2 :
gameAction = Canvas.DOWN;
break;
case -3 :
gameAction = Canvas.LEFT;
break;
case -4 :
gameAction = Canvas.RIGHT;
break;
default:
gameAction = 0;
}
return gameAction;
}
示例2: onSizeChanged
import javax.microedition.lcdui.Canvas; //导入依赖的package包/类
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
AndroidDeviceDisplay deviceDisplay = (AndroidDeviceDisplay) DeviceFactory.getDevice().getDeviceDisplay();
deviceDisplay.setSize(w, h);
if (gameCanvasBitmap == null || gameCanvasBitmap.getWidth() != w || gameCanvasBitmap.getHeight() != h) {
if (gameCanvasBitmap != null) {
gameCanvasBitmap.recycle();
}
gameCanvasBitmap = Bitmap.createBitmap(deviceDisplay.getFullWidth(), deviceDisplay.getFullHeight(), Bitmap.Config.ARGB_8888);
}
if (gameCanvasGraphics != null) {
gameCanvasGraphics.reset(new android.graphics.Canvas(gameCanvasBitmap));
}
MIDletAccess ma = MIDletBridge.getMIDletAccess();
if (ma == null) {
return;
}
DisplayAccess da = ma.getDisplayAccess();
if (da != null) {
da.sizeChanged();
}
}
示例3: setCurrent
import javax.microedition.lcdui.Canvas; //导入依赖的package包/类
/**
* @inheritDoc
*/
private void setCurrent(Displayable d) {
if (display == null) {
throw new IllegalStateException("First call Display.setDisplay(javax.microedition.lcdui.Display d) method");
}
if(!minimized) {
if (d instanceof Canvas) {
if(!disableFullScreen) {
((Canvas) d).setFullScreenMode(!com.codename1.ui.Display.getInstance().isNativeCommands());
}
}
display.setCurrent(d);
}
}
示例4: handleKeyReleased
import javax.microedition.lcdui.Canvas; //导入依赖的package包/类
protected boolean handleKeyReleased(int keyCode, int gameAction) {
if(super.handleKeyReleased(keyCode, gameAction)) {
//Don't do anything that already does something.
return true;
} else {
if(finished) {
//scrolling should be uninterrupted
switch(gameAction) {
case Canvas.UP:
case Canvas.DOWN:
case Canvas.LEFT:
case Canvas.RIGHT:
return false;
default:
UiAccess.cast(this.getCommandListener()).commandAction(CANCEL,this);
return true;
}
}
return false;
}
}
示例5: handleKeyReleased
import javax.microedition.lcdui.Canvas; //导入依赖的package包/类
protected boolean handleKeyReleased(int keyCode, int gameAction) {
if(super.handleKeyReleased(keyCode, gameAction)) {
//Don't do anything that already does something.
return true;
} else {
if(finished) {
//scrolling should be uninterrupted
switch(gameAction) {
case Canvas.UP:
case Canvas.DOWN:
case Canvas.LEFT:
case Canvas.RIGHT:
return false;
default:
UiAccess.cast(this.getCommandListener()).commandAction(FINISHED,this);
return true;
}
}
return false;
}
}
示例6: JrFormEntryController
import javax.microedition.lcdui.Canvas; //导入依赖的package包/类
public JrFormEntryController(JrFormEntryModel model, String extraKeyMode, boolean audioFailFast, boolean quickEntry, boolean isMinimal) {
super(model);
tryToInitDefaultLanguage(model);
this.extraKeyMode = extraKeyMode;
this.audioFailFast = audioFailFast;
this.quickEntry = quickEntry;
this.isMinimal = isMinimal;
this.mMediaLogger = new PlayerListener() {
public void playerUpdate(Player player, String event, Object eventData) {
FormEntryPrompt fep = JrFormEntryController.this.getModel().getQuestionPrompt();
try {
if (fep != null && fep.getAudioText() != null) {
MediaUtils.logEvent(event, fep.getAudioText());
}
} catch(Exception e) {
//Nothing
}
}
};
//#if device.identifier == Sony-Ericsson/K610i
POUND_KEYCODE = Canvas.KEY_STAR;
//#endif
}
示例7: showCamera
import javax.microedition.lcdui.Canvas; //导入依赖的package包/类
private void showCamera() {
try {
mPlayer = Manager.createPlayer("capture://video");
mPlayer.realize();
mVideoControl = (VideoControl) mPlayer.getControl("VideoControl");
// Command mExitCommand = new Command("Exit", Command.EXIT, 0);
// Command mCameraCommand = new Command("Camera", Command.SCREEN, 0);
mBackCommand = new Command("Back", Command.BACK, 0);
mCaptureCommand = new Command("Capture", Command.SCREEN, 0);
Canvas canvas = new CameraCanvas(null, mVideoControl);
canvas.addCommand(mBackCommand);
canvas.addCommand(mCaptureCommand);
canvas.setCommandListener(this);
J2MEDisplay.setView(canvas);
mPlayer.start();
} catch (IOException ioe) {
handleException(ioe);
} catch (MediaException me) {
handleException(me);
}
}
示例8: handleKeyReleased
import javax.microedition.lcdui.Canvas; //导入依赖的package包/类
protected boolean handleKeyReleased(int keyCode, int gameAction) {
//because we're manually processing these, we need to replicate some
//of the structure we'd normally use for dealing with down/up events
//across native input/etc.
if(loaded) {
try {
if (gameAction == Canvas.UP && keyCode != Canvas.KEY_NUM2) {
stepIndex(false);
refreshList();
return true;
} else if (gameAction == Canvas.DOWN && keyCode != Canvas.KEY_NUM8) {
stepIndex(true);
refreshList();
return true;
} else if (gameAction == Canvas.FIRE && keyCode != Canvas.KEY_NUM5) {
processSelect();
return true;
}
} catch (Exception e) {
Logger.die("gui-keyup", e);
}
}
return super.handleKeyReleased(keyCode, gameAction);
}
示例9: Button
import javax.microedition.lcdui.Canvas; //导入依赖的package包/类
Button(Canvas parent, String text, Runnable clickHandler) throws Exception {
// CanvasGraphicsItem needs a non-zero size for its construction.
super(1, 1);
this.setParent(parent);
this.text = text;
this.clickHandler = clickHandler;
try {
// Create different button states with distinct look and colors
this.normalState = new ButtonState(
this, "midlets/blogwriter/images/NormalButton.png", 0xFFFFFF);
this.pressedState = new ButtonState(
this, "midlets/blogwriter/images/PressedButton.png", 0xFFB600);
this.dimmedState = new ButtonState(
this, "midlets/blogwriter/images/DimmedButton.png", 0xa0a0a0);
} catch (Exception ex) {
throw ex;
}
// Set size based on normal state size
this.setSize(this.normalState.getWidth(), this.normalState.getHeight());
this.updateState();
this.setVisible(true);
this.repaint();
}
示例10: keyPressed
import javax.microedition.lcdui.Canvas; //导入依赖的package包/类
/**
* deal with any key presses
*/
protected void keyPressed(int keyCode) {
switch(keyCode){
case -1: //up
case Canvas.UP:
y = getY(y+=STEP);
break;
case -2: //down
case Canvas.DOWN:
y = getY(y+=-STEP);
break;
case -3: //left
case Canvas.LEFT:
x = getX(x+=STEP);
break;
case -4: //right
case Canvas.RIGHT:
x = getX(x+=-STEP);
break;
default:
}
repaint();
}
示例11: InputManager
import javax.microedition.lcdui.Canvas; //导入依赖的package包/类
private InputManager() {
up = new Input(Canvas.UP);
down = new Input(Canvas.DOWN);
left = new Input(Canvas.LEFT);
right = new Input(Canvas.RIGHT);
fire = new Input(Canvas.FIRE);
gamea = new Input(Canvas.GAME_A);
gameb = new Input(Canvas.GAME_B);
gamec = new Input(Canvas.GAME_C);
gamed = new Input(Canvas.GAME_D);
num0 = new Input(Canvas.KEY_NUM0);
num1 = new Input(Canvas.KEY_NUM1);
num2 = new Input(Canvas.KEY_NUM2);
num3 = new Input(Canvas.KEY_NUM3);
num4 = new Input(Canvas.KEY_NUM4);
num5 = new Input(Canvas.KEY_NUM5);
num6 = new Input(Canvas.KEY_NUM6);
num7 = new Input(Canvas.KEY_NUM7);
num8 = new Input(Canvas.KEY_NUM8);
num9 = new Input(Canvas.KEY_NUM9);
star = new Input(Canvas.KEY_STAR);
pound = new Input(Canvas.KEY_POUND);
}
示例12: createSystemImage
import javax.microedition.lcdui.Canvas; //导入依赖的package包/类
public Image createSystemImage(URL url) throws IOException {
java.awt.Image resultImage = Toolkit.getDefaultToolkit().createImage(url);
// TODO not elegant solution, maybe use ImageObserver in
// image.getWitdth(..) instead
MediaTracker mediaTracker = new MediaTracker(new java.awt.Canvas());
mediaTracker.addImage(resultImage, 0);
try {
mediaTracker.waitForID(0);
} catch (InterruptedException ex) {
}
if (mediaTracker.isErrorID(0)) {
throw new IOException();
}
return new J2SEImmutableImage(resultImage);
}
示例13: keyPressed
import javax.microedition.lcdui.Canvas; //导入依赖的package包/类
protected void keyPressed(int keyCode) {
switch (getGameAction(keyCode)) {
case UP:
case DOWN:
game.select();
break;
case LEFT:
game.markNext(Game.LEFT);
break;
case RIGHT:
game.markNext(Game.RIGHT);
break;
default:
break;
}
if (keyCode == Canvas.KEY_STAR && Config.DEBUG) {
showFps = !showFps;
}
}
示例14: onDraw
import javax.microedition.lcdui.Canvas; //导入依赖的package包/类
@Override
public void onDraw(android.graphics.Canvas androidCanvas) {
super.onDraw(androidCanvas);
MIDletAccess ma = MIDletBridge.getMIDletAccess();
if (ma == null) {
return;
}
initGraphics(androidCanvas.getWidth(), androidCanvas.getHeight(), androidCanvas.getMatrix());
graphics.reset(androidCanvas);
// graphics.setClip(0, 0, view.getWidth(), view.getHeight());
androidCanvas.setMatrix(scale);
ma.getDisplayAccess().paint(graphics);
// androidCanvas.drawBitmap(bitmap, scale, null);
if (overlay != null) {
overlay.onDraw(androidCanvas);
}
}
示例15: getKeyCode
import javax.microedition.lcdui.Canvas; //导入依赖的package包/类
@Override
public int getKeyCode(int gameAction) {
int keyCode;
switch (gameAction) {
case Canvas.FIRE:
keyCode = -5;
break;
case Canvas.UP:
keyCode = -1;
break;
case Canvas.DOWN:
keyCode = -2;
break;
case Canvas.LEFT:
keyCode = -3;
break;
case Canvas.RIGHT:
keyCode = -4;
break;
case Canvas.GAME_A:
keyCode = Canvas.GAME_A;
break;
case Canvas.GAME_B:
keyCode = Canvas.GAME_B;
break;
case Canvas.GAME_C:
keyCode = Canvas.GAME_C;
break;
case Canvas.GAME_D:
keyCode = Canvas.GAME_D;
break;
default:
throw new IllegalArgumentException();
}
return keyCode;
}