当前位置: 首页>>代码示例>>Java>>正文


Java Canvas类代码示例

本文整理汇总了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;
}
 
开发者ID:Helltar,项目名称:AMPASIDE,代码行数:27,代码来源:AndroidInputMethod.java

示例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();
	}
}
 
开发者ID:Helltar,项目名称:AMPASIDE,代码行数:27,代码来源:AndroidCanvasUI.java

示例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);
    }
}
 
开发者ID:codenameone,项目名称:CodenameOne,代码行数:19,代码来源:GameCanvasImplementation.java

示例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;
    }
}
 
开发者ID:dimagi,项目名称:commcare-j2me,代码行数:22,代码来源:CommCareOTAFailView.java

示例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;
    }
}
 
开发者ID:dimagi,项目名称:commcare-j2me,代码行数:22,代码来源:CommCareOTARestoreView.java

示例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
}
 
开发者ID:dimagi,项目名称:commcare-j2me,代码行数:26,代码来源:JrFormEntryController.java

示例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);
    }
}
 
开发者ID:dimagi,项目名称:commcare-j2me,代码行数:26,代码来源:ImageCaptureState.java

示例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);
}
 
开发者ID:dimagi,项目名称:commcare-j2me,代码行数:27,代码来源:EntitySelectView.java

示例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();
}
 
开发者ID:mozilla,项目名称:pluotsorbet,代码行数:24,代码来源:Button.java

示例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();

}
 
开发者ID:mozilla,项目名称:pluotsorbet,代码行数:27,代码来源:PanoramaCanvas.java

示例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);
}
 
开发者ID:RobDangerous,项目名称:Jademula,代码行数:25,代码来源:InputManager.java

示例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);
}
 
开发者ID:freeVM,项目名称:freeVM,代码行数:18,代码来源:J2SEDeviceDisplay.java

示例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;
     }
 }
 
开发者ID:jom16antonio,项目名称:jtongits,代码行数:20,代码来源:GameScreen.java

示例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);
            }
        }
 
开发者ID:BombusMod,项目名称:BombusMod,代码行数:18,代码来源:AndroidCanvasUI.java

示例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;
}
 
开发者ID:Helltar,项目名称:AMPASIDE,代码行数:38,代码来源:AndroidInputMethod.java


注:本文中的javax.microedition.lcdui.Canvas类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。