Java ME - lwuit 单选按钮
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 ResourceEdit#GUI 上为
RadioButton
指定组名称(对每个RadioButton
使用相同的名称)。使用以下方法返回RadioButton
。所以使用这个方法。更新 1:
使用此代码从生成的类获取表单,
GenelatedClass
- 使用您的类。resources
- 使用您的资源编辑传递该表单到
findRadioButton(...);
更新 2:
您给出了 2 个
RadioButton 称为验证和注册。
因此,请使用以下代码,
并检查 ResourceEdit#GUI 上的
RadioButton Group
名称。并为两个RadioButton 指定相同的名称。更新 3:
在
mainMidlet.java
类中调用StateMachine()
。Give the group name for
RadioButton
on ResourceEdit#GUI(use the same name for eachRadioButton
). Use following method is return theRadioButton
. So use this method.Update 1:
Use this code for getting the form from generated class,
GeneratedClass
- Use your class.resources
- Use your resource editpass that form to
findRadioButton(...);
Update 2:
you given 2
RadioButton
called Verification and Enrollment.So use the following code,
And check the
RadioButton Group
name on ResourceEdit#GUI. And give the same name for bothRadioButton
.Update 3:
Call
StateMachine()
in yourmainMidlet.java
class.