我的问题是如何通过单击MIDlet
来调用主command
课程?
假设MainMIDlet.java
此类扩展Form
并实现ActionListener
和Aboutus.java
此类扩展还包括Form
和实现ActionListener
。在这堂课中,我没有创造形式的对象。那么在本课程中,如何在点击MainMIDlet
后退按钮时调用Commmand
类?
答案 0 :(得分:2)
调用Aboutus.java时传递MainMIDlet表单实例。 例如,
<强> MainMIDlet.java 强>
public class MainMIDlet extends MIDlet implements ActionListener {
Form form = new form();
...
...
public void actionPerformed(ActionEvent ae)
{
Command cmd = ae.getCommand();
String cmdname= cmd.getCommandName();
if (cmdname.equals("Aboutus"))
{
Aboutus aboutus = new Aboutus(form); // pass the current form
aboutus.show();
}
}
}
<强> Aboutus.java 强>
public class Aboutus extends Form implements ActionListener {
Form mainform;
public Aboutus(Form form) {
this.mainform = form;
...
...
Command backCommand = new Command("Back",null,1);
this.setBackCommand(backCommand);
}
...
...
public void actionPerformed(ActionEvent ae)
{
Command cmd = ae.getCommand();
String cmdname= cmd.getCommandName();
if (cmdname.equals("Back"))
{
mainform.showBack(); // show the Main Midlet form here
}
}
}