Apache Pivot教程 -- TextInput

Apache Pivot教程

周末不写文章,休息一下,估计要急死读者了…
TextInput,就是输入框,相当于HTML标签<input type=“text”>
TextInput的方法很多

void copy();
void cut();
char getCharacterAt(int Index);//获取某一位的字符
int getCharacterCount();//获取字符数量
int getInsertPoint(int Index);
String getPrompt();//获取提示
String getSelectedText();//获取选中的文字
int getSelectionLength();//获取选中文字的长度
int getSelectionStart();//获取选中文字开始的地方
Span getSelection();//获取选中信息
String getText();//获取输入文字
String getText(int beginIndex, int ednIndex);//获取指定文字
boolean isEditable();//获取可不可以编辑
boolean isPassword();//获取是不是密码输入框
void clearSelection();//清除选中
void setPassword(boolean password);//设置是不是密码输入框
void setEditable(boolean editable);

上面是比较典型的,可以从get推出set,所以就不多讲了

package text;

import org.apache.pivot.wtk.*;
import org.apache.pivot.collections.*;

public class text_java implements Application
{
	private Window window=null;
	public static void main(String [] args)
	{
		try
		{
			DesktopApplicationContext.main(text_java.class, args);
		}
		catch(Throwable err)
		{
		}
	}
	@Override
	public void startup(Display display, Map<String, String>properties)
	{
		window=new Window();
		BoxPane panel=new BoxPane();
		TextInput textinput1=new TextInput();
		textinput1.setText("hello");
		panel.add(textinput1);
		
		PushButton button1=new PushButton();
		button1.setButtonData("getIndex0");
		button1.getButtonPressListeners().add(new ButtonPressListener()
				{
			@Override
			public void buttonPressed(Button button)
			{
				Alert.alert(Character.toString(textinput1.getCharacterAt(0)), window);
			}
				});
		panel.add(button1);
		PushButton button2=new PushButton();
		button2.setButtonData("getCharacterNumber");
		button2.getButtonPressListeners().add(new ButtonPressListener()
				{
			@Override
			public void buttonPressed(Button button)
			{
				Alert.alert(Integer.toString(textinput1.getCharacterCount()), window);
			}
				});
		panel.add(button2);
		PushButton button3=new PushButton();
		button3.setButtonData("Information");
		button3.getButtonPressListeners().add(new ButtonPressListener()
				{
			@Override
			public void buttonPressed(Button button)
			{
				textinput1.setSelection(1, 4);
				System.out.println(textinput1.getMaximumLength());
				System.out.println(textinput1.getPrompt());
				System.out.println(textinput1.getSelectedText());
				System.out.println(textinput1.getSelectionLength());
				System.out.println(textinput1.getSelectionStart());
				System.out.println(textinput1.getSelection());
				System.out.println(textinput1.getText());
				System.out.println(textinput1.getText(0, 5));
				System.out.println(textinput1.isEditable());
				System.out.println(textinput1.isPassword());
				textinput1.clearSelection();
				textinput1.setPassword(true);
			}
				});
		panel.add(button3);
		
		window.setContent(panel);
		window.setTitle("TextInput");
		window.setMaximized(true);
		window.open(display);
	}
	@Override
	public boolean shutdown(boolean optional)
	{
		if(window!=null)
		{
			window.close();
		}
		return false;
	}
	@Override
	public void suspend()
	{
	}
	@Override
	public void resume()
	{
	}
}


Information比较重要

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值