⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 midp1eventgame_canvas.java

📁 MIDP1.0标准按键测试 MIDP1.0标准按键测试 MIDP1.0标准按键测试 MIDP1.0标准按键测试
💻 JAVA
字号:
/*
 *MIDP1.0游戏按键测试
 *MIDP1EventGame_Canvas.java
 *Editer:Jinlong He
 *Date:2008-01-24
 */
 import javax.microedition.lcdui.*;
 public class MIDP1EventGame_Canvas extends Canvas{
 	private int width;		//mobile screen width
 	private int height;		//mobile screen height
 	
 	String text = "MIDP1.0游戏按键测试";
 	
 	/*
 	 *1.构造
 	 *
 	 */
 	MIDP1EventGame_Canvas(){
 		width = this.getWidth();
 		height = this.getHeight();
 		if(this.hasPointerEvents()){
 			text ="特性:设备支持手写笔";
 		}else{
 			text ="特性:设备不支持手写笔";			
 		}
 		if(this.hasPointerMotionEvents()){				//是否支持触控笔拖曳pointerDragged(),和上面的方法是2.0里有的
 			text +="、支持触控笔拖曳";	
 		}else{
 			text +="、不支持触控笔拖曳";
 		}
 		if(this.hasRepeatEvents()){
 			text +="、支持持继按键";
 		}else{
 			text += "、不支持持继按键";
 		}
 		repaint();
 		
 	}
 	
 	/*
 	 *2.实现paint()方法
 	 *
 	 */
 	protected void paint(Graphics g){
 		g.setColor(0,0,255);
 		g.fillRect(0,0,width,height);
 		g.setColor(255,255,255);
 		g.drawString(text,0,height/2,Graphics.LEFT | Graphics.TOP);	//写字符四个参数:字符串、始宽、始高、格式
 		
 	}
 	
 	/*
 	 *3.响应按键事件
 	 *keyReleased为keyPressed的相反事件,松开按钮时触发
 	 */
 	protected void keyPressed(int keyCode){
 		//↓↑←→↖↗↙↘
 		text = "MIDP1.0游戏按键测试";
 		int action = this.getGameAction(keyCode);
 		switch(action){
 			case UP:
 				text+="游戏上";		//"↑" or "2"
 				break;
 			case DOWN:
 				text+="游戏下";		//"↓" or "8"
 				break;
 			case LEFT:
 				text+="游戏左";		//"→" or "6"
 				break;
 			case RIGHT:
 				text+="游戏右";		//"←" or "4"
 				break;
 			case FIRE:
 				text+="游戏开火";	//"OK" or "5"
 				break;
 			case GAME_A:
 				text+="游戏A";		//"1"
 				break;
 			case GAME_B:			
 				text+="游戏B";		//"3"
 				break;
 			case GAME_C:
 				text+="游戏C";		//"7"
 				break;
 			case GAME_D:
 				text+="游戏D";		//"9"
 				break;
 					
 		}	
 		repaint();
 	}
 	
 	/*
 	 *4.响应按键事件
 	 *keyReleased为keyPressed的相反事件,松开按钮时触发
 	 */
 	protected void keyReleased(int keyCode){
 		//↓↑←→↖↗↙↘
 		text = "";
 		int action = this.getGameAction(keyCode);
 		switch(action){
 			case UP:
 				text+="游戏上";		//"↑" or "2"
 				break;
 			case DOWN:
 				text+="游戏下";		//"↓" or "8"
 				break;
 			case LEFT:
 				text+="游戏左";		//"→" or "6"
 				break;
 			case RIGHT:
 				text+="游戏右";		//"←" or "4"
 				break;
 			case FIRE:
 				text+="游戏开火";	//"OK" or "5"
 				break;
 			case GAME_A:
 				text+="游戏A";		//"1"
 				break;
 			case GAME_B:			
 				text+="游戏B";		//"3"
 				break;
 			case GAME_C:
 				text+="游戏C";		//"7"
 				break;
 			case GAME_D:
 				text+="游戏D";		//"9"
 				break;
 					
 		}	
 		repaint();
 	}
 	
 }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -