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

📄 qtogglebutton.java

📁 j2me 高级UI
💻 JAVA
字号:
/**
 * 作者:cat 戚永城
 * 时间:2008-3-1
 * QQ:415898635
 * E-Mail:	415898635@qq.com
 * 			qyc_12345@163.com
 * 
 * */
package org.qui.conmponent;

import javax.microedition.lcdui.Graphics;
import org.qui.image.JiugongDiv;
import org.qui.info.Attribute;
import org.qui.manager.QAbstructButton;
import org.qui.manager.UIManager;

public class QToggleButton extends QAbstructButton
{

	public QToggleButton()
	{
		super();
	}

	public QToggleButton(int x, int y, int width, int height)
	{
		super(x, y, width, height);
	}

	public QToggleButton(int x, int y, int width, int height, String label)
	{
		super(x, y, width, height);
		this.label = label;
	}

	public void drawFocus(Graphics g)
	{

	}

	public void setLabel(String label)
	{
		this.label = label;
		int charsWidth = font.stringWidth(label);
		if (charsWidth > width)
		{
			width = charsWidth;
		}
		int charsHeight = font.getHeight();
		if (charsHeight > height)
		{
			height = charsHeight;
		}
	}

	public void paint(Graphics g)
	{
		if (focus)
		{
			if (selected || keyPressed)
			{
				JiugongDiv.drawJiuGong(g, UIManager.button_focus_pressed, x
						+ ui.offx + btn_offx, y + ui.offy + btn_offy, width,
						height);
			} else
			{
				JiugongDiv.drawJiuGong(g, UIManager.button_focus, x + ui.offx
						+ btn_offx, y + ui.offy + btn_offy, width, height);
			}
		} else
		{
			if (selected)
			{
				JiugongDiv.drawJiuGong(g, UIManager.button_normal_pressed, x
						+ ui.offx + btn_offx, y + ui.offy + btn_offy, width,
						height);
			} else
			{
				JiugongDiv.drawJiuGong(g, UIManager.button_normal, x + ui.offx
						+ btn_offx, y + ui.offy + btn_offy, width, height);
			}
		}

		if (label != null)
		{
			g.setFont(font);
			g.setColor(fr, fg, fb);
			g.drawString(label, x + width / 2 + ui.offx + btn_offx, y
					+ (height - fontHeight) / 2 + fontHeight + ui.offy
					+ btn_offy, Graphics.BOTTOM | Graphics.HCENTER);
		}
		// paint shadow

	}

	private int btn_offx = 0;

	private int btn_offy = 0;

	public void keyPressed(int keyCode)
	{
		if (Attribute.skin == Attribute.SKIN_PLAIN)
		{
			btn_offx++;
			btn_offy++;
		}
		super.keyPressed(keyCode);
	}

	public void keyReleased(int keyCode)
	{
		if (Attribute.skin == Attribute.SKIN_PLAIN)
		{
			btn_offx--;
			btn_offy--;
		}
		super.keyReleased(keyCode);
	}

}

⌨️ 快捷键说明

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