Java ME-lwuit单选按钮
为ResourceEdit#GUI上的Java ME-lwuit单选按钮,java,java-me,lwuit,Java,Java Me,Lwuit,为ResourceEdit#GUI上的RadioButton提供组名(对每个RadioButton使用相同的名称)。使用以下方法返回单选按钮。所以使用这个方法 public class StateMachine extends StateMachineBase implements ActionListener { Resources resources; RadioButton Verifi=new RadioButton("Verification") ; RadioButton
RadioButton
提供组名(对每个RadioButton
使用相同的名称)。使用以下方法返回单选按钮
。所以使用这个方法
public class StateMachine extends StateMachineBase implements ActionListener {
Resources resources;
RadioButton Verifi=new RadioButton("Verification") ;
RadioButton Enroll=new RadioButton("Enrollment");
StateMachineBase cl=new StateMachineBase()
{};
ButtonGroup bg=new ButtonGroup();
static Form fo,f;
public StateMachine(String resFile) {
super(resFile);
}
StateMachine()
{
try{
resources = Resources.open("/NEW AADHAR.res");
}
catch(java.io.IOException err)
{ err.printStackTrace(); }
cl.setHomeForm("Welcome");
//fo = (Form)cl.startApp(resources,null,true);
fo=Display.getInstance().getCurrent();
f=cl.findWelcome(fo);
Verifi=cl.findVerification(f);
Enroll=cl.findEnrollment(f);
bg.add(Enroll);
bg.add(Verifi);
//f.addCommandListener(this);
Verifi.addActionListener(listener);Enroll.addActionListener(listener);
}
protected void initVars() {
}
public void actionPerformed(ActionEvent ae) {
throw new UnsupportedOperationException("Not supported yet.");
}
ActionListener listener=new ActionListener(){
protected void onWelcome_ButtonAction(Component c, ActionEvent event)
{
Verifi.addActionListener(listener);
if(Verifi.hasFocus())
{
showForm("Login",null);
}
else if (Enroll.hasFocus())
{
showForm("Authentication",null);
}
else
Dialog.show("INFORMATION","Select","OK","Cancel");
}
public void actionPerformed(ActionEvent ae) {
throw new UnsupportedOperationException("Not supported yet.");
}
};
}
更新1: 使用此代码从生成的类获取表单
public com.sun.lwuit.RadioButton findRadioButton(Container root) {
return (com.sun.lwuit.RadioButton)findByName("RadioButton", root);
//root - Pass the RadioButton added Component.
}
GeneratedClass
-使用您的类。
资源
-使用您的资源编辑
将该表单传递给findRadioButton(…)代码>
更新2:
您提供了2个名为“验证和注册”的单选按钮。
所以使用下面的代码
GeneratedClass genClass = new GeneratedClass() { };
final Form form = (Form) genClass.startApp(resources, null, true);
并检查ResourceEdit#GUI上的单选按钮组
名称。并为两个单选按钮提供相同的名称
更新3:
在mainMidlet.java
类中调用StateMachine()
GeneratedClass genClass = new GeneratedClass() { };
Form form = (Form) genClass.startApp(resources, null, true);
RadioButton rbVerification = genClass.findVerification(form);
RadioButton rbEnrollment = genClass.findEnrollment(form);
高拉夫:你为什么要感谢这个新话题?如果答案是确定的,则表示开始接受答案。好的,但我对您的StateMachine类中的上述问题感到困惑,您在该类中初始化注册、验证和bg
?公共类StateMachine扩展StateMachineBase实现ActionListener{Resources Resources;StateMachineBase cl=new StateMachineBase(){};RadioButton bgVerification;RadioButton bgEnrollment;ButtonGroup bg=new ButtonGroup();;在statemachine类及以上的构造函数库中,Bharath。我明白你的意思。请告诉我必须调用FindAdioButton()方法或findByName()方法和根目录中,我必须传递我已添加单选按钮的表单名称?如果您想获得单选按钮
意味着使用findRadioButton()
,并且在哪里添加单选按钮
?我已在formhey Bharath上添加了我的单选按钮。您在方法最终表单=(表单)中的资源是什么意思genClass.startApp(参考资料,null,true)
public class StateMachine extends StateMachineBase implements ActionListener {
Resources resources;
RadioButton Verification;
RadioButton Enrollment;
public StateMachine(String resFile) {
super(resFile);
}
/**
* this method should be used to initialize variables instead of
* the constructor/class scope to avoid race conditions
*/
StateMachine() {
}
protected void initVars() {
}
/**
* @param c
* @param event
*/
public void actionPerformed(ActionEvent ae) {
throw new UnsupportedOperationException("Not supported yet.");
}
protected boolean onWelcomeEXIT() {
boolean val = super.onWelcomeEXIT();
return val;
}
protected void onWelcome_ButtonAction(Component c, ActionEvent event) {
super.onSampleRB_RadioButtonAction(c, event);
Verification = (RadioButton) c; // initialize here
if (Verification.hasFocus()) {
showForm("Login",null);
} else {
Dialog.show("INFORMATION", "Please select option", "OK", "Cancel");
}
}
}