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

📄 xmenuthree.java

📁 初学者的佳音 初学者的佳音 初学者的佳音
💻 JAVA
字号:
/*
 * Created on 2005-3-5
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */

/**
 * @author softsong
 *
 *Menu style 1 :just draw the menu with rect and string
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package x;
import javax.microedition.lcdui.*;
public class XMenuThree {
	private String[] items;
	public byte itemsNum;
	public int xPos,yPos;
	public int maxItemWidth;
	public byte selectedItem;
	public byte SHOW_ITEMS=3;
	public byte beginItem=0;
	
	private XGame game;
	private int itemSpace;

	private int objectItem;
	public XMenuThree(XGame game,String[] strItems,int yPos,int objectId,int space){
		items=strItems;
		itemsNum=(byte)items.length;
		this.game=game;
		
		this.yPos=yPos;
		maxItemWidth=0;
		//get the max length of menu items
		for(int i=0;i<itemsNum;i++){
			int nWidth=game.font.stringWidth(items[i]);
			if(nWidth>maxItemWidth){
				maxItemWidth=nWidth;
			}
		}
		xPos=(game.width-maxItemWidth)/2;
		objectItem=objectId;
		itemSpace=space;
	}
	
	public void moveDown(){
		//game.("before movedown selectedItem: "+selectedItem+ " beginItem: "+beginItem);
		if(selectedItem<itemsNum-1){
			selectedItem++;
			if(selectedItem-beginItem>=SHOW_ITEMS){
				beginItem++;
			}
		}
		//XMain.pInfo("after movedown selectedItem: "+selectedItem+ " beginItem: "+beginItem);
		
	}
	public void moveUp(){
		//XMain.pInfo("before moveup selectedItem: "+selectedItem+ " beginItem: "+beginItem);
		
		if(selectedItem>0){
			
			selectedItem--;
			if(selectedItem<beginItem){
				beginItem--;
			}
		}
		
		//XMain.pInfo("after moveup selectedItem: "+selectedItem+ " beginItem: "+beginItem);
		
	}
	public void paint(Graphics g,int colorRect,int colorItem,int colorSel){
		int tempX = g.getClipX();
		int tempY = g.getClipY();
		int tempWidth = g.getClipWidth();
		int tempHeight = g.getClipHeight();
		int x=0,y=0;
		//g.setColor(colorRect);
		//g.setClip(xPos-2,yPos-2,maxItemWidth+3,SHOW_ITEMS*(game.fontHeight+1)+3);
		//g.drawRect(xPos-2,yPos-2,maxItemWidth+2,SHOW_ITEMS*(game.fontHeight+1)+2);
		g.setClip(0,0,game.width,game.height);
		
		for (int i=0;i<SHOW_ITEMS;i++){
			if(i+beginItem>=itemsNum){
				break;
			}
			if(i+beginItem==selectedItem){
				g.setColor(colorSel);
			}
			else{
				g.setColor(colorItem);
			}
			x=game.width/2-game.font.stringWidth(items[i+beginItem])/2;
			y=yPos+i*(itemSpace);
			if(objectItem>=0){
				game.drawObject(g,objectItem,0,0,game.width/2,y+game.fontHeight/2);
			}
			g.drawString(items[i+beginItem],x,y,Graphics.TOP|Graphics.LEFT);
		}
		g.setClip(tempX, tempY, tempWidth, tempHeight);
	}
}

⌨️ 快捷键说明

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