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

📄 qlabel.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.QItem;
import org.qui.manager.UIManager;

public class QLabel extends QItem {

	public final static int LEFT_ALIGNMENT = 0;

	public final static int MIDDLE_ALIGNMENT = 2;

	public final static int RIGHT_ALIGNMENT = 1;

	private int alignment = 0;

	private String label = "label";

	public QLabel(){
		super();
	}
	
	public QLabel(int x, int y, int width, int height) {
		super(x, y, width, height);
		br=Attribute.text_backR;
		bg=Attribute.text_backG;
		bb=Attribute.text_backB;
	}

	public QLabel(int x, int y) {
		super(x, y, 36, 20);
		br=Attribute.text_backR;
		bg=Attribute.text_backG;
		bb=Attribute.text_backB;
	}
	
	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 setAlignment(int alignment){
		this.alignment=alignment;
	}
	public void drawFocus(Graphics g) {

	}

	public void paint(Graphics g) {
		//back
		if(!noback){
			g.setColor(br,bg,bb);
			g.fillRect(x + ui.offx, y + ui.offy, width, height);
		}
		//fore
		g.setColor(fr,fg,fb);
		g.setFont(font);
		if (alignment == LEFT_ALIGNMENT) {
			g.drawString(label, x + ui.offx, y + ui.offy, Graphics.LEFT | Graphics.TOP);
		} else if (alignment == MIDDLE_ALIGNMENT) {
			g.drawString(label, x  + ui.offx + width / 2, y + ui.offy, Graphics.HCENTER
					| Graphics.TOP);
		} else if (alignment == RIGHT_ALIGNMENT) {
			g.drawString(label, x  + ui.offx + width, y + ui.offy, Graphics.RIGHT | Graphics.TOP);
		}
		//if focus
		if(focus){
			JiugongDiv.drawJiuGong(g, UIManager.light, x + ui.offx -8, y + ui.offy -8, width+16,height+16);
		}
	}
}

⌨️ 快捷键说明

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