SUN LWUIT-Lightweight User Interface Toolkit(轻量级用户界面工具包)简介:
LWUIT是一个轻量级JavaME UI工具包。LWUIT类似Swing 的MVC架构, 支持多种布局(Layouts), 皮肤更换, 字体, 触摸屏, 动画效果, Rich控件, 3D集成, Painter, 模式对画框, I18N/L10N等。
j2me不像.net开发Mobiel应用软件可以有控件拖拉布局界面,初作基于lwuit的页面布局更是让人煞费苦心,这里主要用到了lwuit中Container来进行控件定位实现你想要的效果。
//定义控件
TextField txtUserID = new TextField();
TextField txtPassword = new TextField();
CheckBox CBPWD = new CheckBox("记住密码");
CheckBox CBsilent = new CheckBox("静音登陆");
/* 统一放置于Container中方便控件定位*/
//设置FlowLayout布局方式
Container loginContainner = new Container(
new FlowLayout());
//设置txtUserID距离顶端40像素
loginContainner.getStyle().setMargin(Component.TOP, 40);
//每个控件都要添加到实例化好的 Container中
loginContainner.addComponent(createPair("工 号:", txtUserID));
addComponent(loginContainner);
//要为每个控件实例化一个Container
loginContainner = new Container(new FlowLayout(Component.LEFT));
loginContainner.getStyle().setMargin(Component.TOP, 10);
loginContainner.addComponent(createPair("密 码:", txtPassword));
addComponent(loginContainner);
//控件居中
loginContainner = new Container(new FlowLayout(Component.CENTER));
loginContainner.getStyle().setMargin(Component.TOP, 10);
loginContainner.addComponent(CBPWD);
addComponent(loginContainner);
loginContainner = new Container(new FlowLayout(Component.CENTER));
loginContainner.getStyle().setMargin(Component.TOP, 10);
loginContainner.addComponent(CBsilent);
addComponent(loginContainner);
TextField txtUserID = new TextField();
TextField txtPassword = new TextField();
CheckBox CBPWD = new CheckBox("记住密码");
CheckBox CBsilent = new CheckBox("静音登陆");
/* 统一放置于Container中方便控件定位*/
//设置FlowLayout布局方式
Container loginContainner = new Container(
new FlowLayout());
//设置txtUserID距离顶端40像素
loginContainner.getStyle().setMargin(Component.TOP, 40);
//每个控件都要添加到实例化好的 Container中
loginContainner.addComponent(createPair("工 号:", txtUserID));
addComponent(loginContainner);
//要为每个控件实例化一个Container
loginContainner = new Container(new FlowLayout(Component.LEFT));
loginContainner.getStyle().setMargin(Component.TOP, 10);
loginContainner.addComponent(createPair("密 码:", txtPassword));
addComponent(loginContainner);
//控件居中
loginContainner = new Container(new FlowLayout(Component.CENTER));
loginContainner.getStyle().setMargin(Component.TOP, 10);
loginContainner.addComponent(CBPWD);
addComponent(loginContainner);
loginContainner = new Container(new FlowLayout(Component.CENTER));
loginContainner.getStyle().setMargin(Component.TOP, 10);
loginContainner.addComponent(CBsilent);
addComponent(loginContainner);
上图: