button.java

来自「MMAE1.0开发者版源代码 用于扩展java me移动开发引擎,这是1.0版」· Java 代码 · 共 59 行

JAVA
59
字号
/**
*按钮控件
*@CopyRight:Move2008
*@Author:bedlang
*@Version 1.0 2003/8/5
*/

package mmae.ui;

import javax.microedition.lcdui.*;
import mmae.util.Tool;

public class Button extends Base
{
	String text;
	Image img;
	
	public Button(Image I, String Caption, int X, int Y)
	{
		img = I;
		setPosition(X, Y);
		text = Caption;
	}
	
	public Button(Image I, String Caption)
	{
		img = I;
		text = Caption;
	}	
	
	public void draw(Graphics g, int x, int y)
	{
		setPosition(x, y);
		draw(g);
	}
	
	public void draw(Graphics g)
	{
		g.drawImage(img, left, top, g.TOP|g.LEFT);

		if(colorBackR==-1)
			g.setColor(0);
		else
			g.setColor(colorBackR, colorBackG, colorBackB);
		g.drawString(text, (img.getWidth()-Tool.getStrWidth(text))/2+left, 
						   (img.getHeight()-Tool.getFontHeight())/2+top, g.TOP|g.LEFT);
	}
	
	public int getWidth()
	{
		return img.getWidth();
	}

	public int getHeight()
	{
		return img.getHeight();
	}
	
}

⌨️ 快捷键说明

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