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

📄 input.java

📁 手机程序
💻 JAVA
字号:
package com.gameislive.browser.element;

import com.gameislive.browser.Browser;
import javax.microedition.lcdui.Graphics;

public class Input extends Element implements FormElement{

	String name;
	
	String value;
	
	String showValue;
	
	int size;
	
	int maxLength;
	
	Browser browser;
	
	public Input(int hyperlinksId,int lineId,byte type,Browser browser){
		// 文本框肯定可以选择,所以第一个参数为true
		super(true,hyperlinksId,lineId,type);
		this.browser = browser;
		height = browser.fontHeight;
	}
	
	public void setName(String name){
		this.name = name;
	}
	
	public String getName(){
		return name;
	}
	
	public void setValue(String value){
		this.value = value;

		// 只显示size指定数量的文字
		if(value.length() > size){
			showValue = value.substring(0,size);
		}else{
			showValue = value;
		}
		
		if(type == PASSWORD_INPUT){
			int l = showValue.length();
			showValue = "";
			for(int i=0;i<l;i++) showValue += "*";
		}
	}
	
	public String getValue(){
		return value;
	}
	
	public void setSize(int size){
		int w = browser.strWidth("W");
		if(size > (browser.width - 20)/w) size = (browser.width - 20)/w;
		this.size = size;
		// 假设每个字符都和W一样大,则W的宽度与size的积为该元素的宽度
		width = w * size;
	}
	
	public void setMaxLength(int maxLength){
		this.maxLength = maxLength;
	}
	
	public int getMaxLength(){
		return maxLength;
	}
	
	public int getWidth(){
		return width;
	}
	
	public int getHeight(){
		return height + 2;
	}
	
	public void draw(int y,int hyperlinks,Graphics g){

		// 黑色的边框线条
		g.setColor(0x000000);
		g.drawRect(x, y, width, height);
		
		if(hyperlinksId == hyperlinks){
			// 选中时用浅蓝色填充
			g.setColor(0x0000ff);
			g.fillRect(x+2, y+2, width-3, height-3);
			g.setColor(0xffffff);
		}else{
			// 未选中时用白色填充
			g.setColor(0xffffff);
			g.fillRect(x+2, y+2, width-3, height-3);
			g.setColor(0x000000);
		}
		
		// 显示黑色的文字
		if(showValue!=null){
			g.drawString(showValue,x+2,y,Graphics.TOP|Graphics.LEFT);
		}
	}	
}

⌨️ 快捷键说明

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