开发者

Java ME - lwuit radio button

开发者 https://www.devze.com 2023-03-20 12:04 出处:网络
public class StateMachine extends StateMachineBase implements ActionListener { Resources resources; RadioButton Verifi=new RadioButton(\"Verification\") ;
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.");
        }

};
}


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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号