My question is how to call main MIDlet
class by clicking on back command
?
Suppose MainMIDlet.java
this class extends Form
and implements ActionListener
and Aboutus.java
this class extends also include Form
with implements ActionListener
. In this class I had not created object of form. So in this class how to call MainMIDlet
class when click on Commmand
back button?
Asked
Active
Viewed 1,522 times
0

gnat
- 6,213
- 108
- 53
- 73

Jeevan Mane
- 49
- 7
1 Answers
2
Pass the MainMIDlet form instance when you call the Aboutus.java. For example,
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
}
}
}

bharath
- 14,283
- 16
- 57
- 95
-
Thanks bhakki yaar.You proovide best solution,but problem is when click on back command there is no action performed,i.e.MainMIDlet form can't be display.In my MainMIDlet class,all componet are add with the help of form object of MainMIDlet [Form form = new Form()]. what is problem? plz give soltion.THANK U – Jeevan Mane Jul 05 '11 at 05:40
-
@Jeevan: Did you add the `addCommandListener` to second form? – bharath Jul 05 '11 at 05:45
-
THANK U VERY MUCH bhakki.I forgot about this method. thanks dude once again.Take care. – Jeevan Mane Jul 05 '11 at 05:53