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

📄 customitemdemo.java

📁 jBuilderX无线应用开发源代码
💻 JAVA
字号:
import javax.microedition.midlet.MIDlet;
import javax.microedition.lcdui.*;

public class CustomItemDemo extends MIDlet
{
	private Display display;

	public void startApp(){		
		Form form=new Form("CustomItemDemo");
		//创建自定义的item,并将它添加到Form中
		MyItem item=new MyItem("item title","Hello World");
		form.append(item);
		//创建Gauge,并将它添加到Form中
		Gauge gauge=new Gauge("Gauge",false,10,5);
		form.append(gauge);
		display=Display.getDisplay(this);
		display.setCurrent(form);
	}

	public void pauseApp(){
	}

	public void destroyApp(boolean unconditional){
	}
}

class MyItem extends CustomItem{
	private String info="";

	public MyItem (String title, String info){
		super(title);
		this.info=info;
    }

    protected int getMinContentHeight() {
		return 40;
    }

    protected int getMinContentWidth() {
		return 100;
    }

    protected int getPrefContentHeight(int width) {
		return 60;
    }

    protected int getPrefContentWidth(int height) {
		return 150;
    }

    protected void paint(Graphics g, int w, int h) {
		//画出信息边框
		g.setStrokeStyle(Graphics.DOTTED);
		g.drawRect(5, 5, w-10, h-10);
		//用红色显示信息内容
		g.setColor(255,0,0);
		g.drawString(info, w/2, h/2, Graphics.HCENTER|Graphics.BASELINE);
    }
}

⌨️ 快捷键说明

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