Java ME - lwuit 单选按钮

发布于 2024-11-24 14:56:44 字数 1574 浏览 1 评论 0原文

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.");
        }

};
}
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.");
        }

};
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

故事还在继续 2024-12-01 14:56:44

在 ResourceEdit#GUI 上为 RadioButton 指定组名称(对每个 RadioButton 使用相同的名称)。使用以下方法返回RadioButton。所以使用这个方法。

public com.sun.lwuit.RadioButton findRadioButton(Container root) {
   return (com.sun.lwuit.RadioButton)findByName("RadioButton", root);
        //root - Pass the RadioButton added Component.
}

更新 1:

使用此代码从生成的类获取表单,

GeneratedClass genClass = new GeneratedClass() { };
final Form form = (Form) genClass.startApp(resources, null, true);

GenelatedClass - 使用您的类。
resources - 使用您的资源编辑

传递该表单到 findRadioButton(...);


更新 2:

您给出了 2 个 RadioButton 称为验证和注册。
因此,请使用以下代码,

 GeneratedClass genClass = new GeneratedClass() { };
 Form form = (Form) genClass.startApp(resources, null, true);
 RadioButton rbVerification = genClass.findVerification(form);
 RadioButton rbEnrollment = genClass.findEnrollment(form);

并检查 ResourceEdit#GUI 上的 RadioButton Group 名称。并为两个RadioButton 指定相同的名称。


更新 3:

mainMidlet.java 类中调用 StateMachine()

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");
        }
    }
}

Give the group name for RadioButton on ResourceEdit#GUI(use the same name for each RadioButton). Use following method is return the RadioButton. So use this method.

public com.sun.lwuit.RadioButton findRadioButton(Container root) {
   return (com.sun.lwuit.RadioButton)findByName("RadioButton", root);
        //root - Pass the RadioButton added Component.
}

Update 1:

Use this code for getting the form from generated class,

GeneratedClass genClass = new GeneratedClass() { };
final Form form = (Form) genClass.startApp(resources, null, true);

GeneratedClass - Use your class.
resources - Use your resource edit

pass that form to findRadioButton(...);


Update 2:

you given 2 RadioButton called Verification and Enrollment.
So use the following code,

 GeneratedClass genClass = new GeneratedClass() { };
 Form form = (Form) genClass.startApp(resources, null, true);
 RadioButton rbVerification = genClass.findVerification(form);
 RadioButton rbEnrollment = genClass.findEnrollment(form);

And check the RadioButton Group name on ResourceEdit#GUI. And give the same name for both RadioButton.


Update 3:

Call StateMachine() in your mainMidlet.java class.

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");
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文