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

📄 optioncanvas.java

📁 用J2ME写的一种五子连线的手机游戏。ColorLinez是一款由玩家通过功能键移动各色小球
💻 JAVA
字号:
package game;

import javax.microedition.lcdui.*;

public class OptionCanvas extends Canvas
{
	//声明Display对象
    Display display;
	//屏幕的宽度与高度
	private int scrWidth = 0;
	private int scrHeight = 0;
    //声明Image对象
	private Image img = null;
	private Image chose = null; 
	//选项索引
	private int optionIndex = 0;
	
	public OptionCanvas(Display display)
    {
		//获得Display对象
	    this.display = display;
        //设屏全屏
    	this.setFullScreenMode(true);
        //得到屏幕的宽度与高度
    	scrWidth = this.getWidth();
    	scrHeight = this.getHeight();
    	//导入图片
    	try
    	{
    		img = Image.createImage("/res/option.png");
    		chose = Image.createImage("/res/01.png");
    	}
    	catch(Exception e)
    	{
    		System.out.println(e);
    	}
    	optionIndex = ColorLinezMIDlet.gameGrade;
	}
	
	protected void paint(Graphics g)
	{
		//清屏
		g.setColor(0xFFFFFF);
		g.fillRect(0, 0, scrWidth, scrHeight);
		g.setColor(0x000000);
		
		g.drawImage(img, 0, 0, Graphics.TOP | Graphics.LEFT);
		g.drawImage(chose, 52, 47 + optionIndex * 30, Graphics.TOP | Graphics.LEFT);
		g.drawRect(44, 37 + optionIndex * 30, 76, 27);
	}
	
	protected void keyPressed(int keyCode)
	{
		int action = this.getGameAction(keyCode);
	    switch ( action )
	    {
	       case Canvas.UP:
	    	   optionIndex--;
	    	   if ( optionIndex < 1 )
	    	   {
	    		   optionIndex = 3;
	    	   }
	    	   break;
	       case Canvas.DOWN:
	    	   optionIndex++;
	    	   if ( optionIndex > 3 )
	    	   {
	    		   optionIndex = 1;
	    	   }
	    	   break;
	       case Canvas.FIRE:
	    	   ColorLinezMIDlet.gameGrade = optionIndex;
	    	   img = null;
	    	   chose = null;
		       display.setCurrent(new MainMenuCanvas(display));
	    }
	    repaint();
	}
}

⌨️ 快捷键说明

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