By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,667 Members | 1,613 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,667 IT Pros & Developers. It's quick & easy.

J2ME Novice: Screen Navigation?

P: n/a
How do you navigate between screens in J2ME? I would like to navigate to the
next screen using the default emulator in KToolbar. Here is a snippit of my
commandAction method:
public void commandAction(Command c, Displayable s) {
if (c == mMenuCommand)
{
mMenuForm = new Form("SampleMIDlet");
final String[] menuItems = { "Games" , "Calculator", "Alarm Clock" };
final List list = new List("Select a Item", List.IMPLICIT, menuItems, null);

final Command nextCommand = new Command("Next", Command.SCREEN, 0);
Command quitCommand = new Command("Quit", Command.SCREEN, 0);
list.addCommand(nextCommand);
list.addCommand(quitCommand);
list.setCommandListener(new CommandListener()
{
public void commandAction(Command c, Displayable s)
{
if (c == nextCommand || c == List.SELECT_COMMAND)
{
int index = list.getSelectedIndex();
System.out.println("Your selection: " + menuItems[index]);

// Move on to the next screen. Here, we just exit.
notifyDestroyed();
} else notifyDestroyed();
}
});
Display.getDisplay(this).setCurrent(list);
}

if (c == mExitCommand) notifyDestroyed();
}

Thanks!
Gilgantic
Jul 17 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
gilgantic wrote:
How do you navigate between screens in J2ME?


See the Javadoc for javax.microedition.lcdui.Display.setCurrent for more
information.

--
Darryl L. Pierce <mc******@myrealbox.com>
Visit the Infobahn Offramp - <http://bellsouthpwp.net/m/c/mcpierce>
"What do you care what other people think, Mr. Feynman?"
Jul 17 '05 #2

P: n/a
gilgantic wrote:
How do you navigate between screens in J2ME? <snip>


Sorry, I didn't read your entire message previously. You have to explicitly
tell the Display what the Displayable is that you want to show. There's no
way in the MIDP to tell the VM what the screens are and in what order they
should be displayed.

--
Darryl L. Pierce <mc******@myrealbox.com>
Visit the Infobahn Offramp - <http://bellsouthpwp.net/m/c/mcpierce>
"What do you care what other people think, Mr. Feynman?"
Jul 17 '05 #3

P: n/a
"Darryl L. Pierce" <mc******@myrealbox.com> wrote in message news:<d9******************************@free.terane ws.com>...
gilgantic wrote:
How do you navigate between screens in J2ME? <snip>


Sorry, I didn't read your entire message previously. You have to explicitly
tell the Display what the Displayable is that you want to show. There's no
way in the MIDP to tell the VM what the screens are and in what order they
should be displayed.


Well are there any online examples of an entire application. The ones I have
seen just have minimum amount of navigation. I will check into the javadoc
for the Display class.
Jul 17 '05 #4

P: n/a
gilgantic wrote:
> How do you navigate between screens in J2ME? <snip>


Sorry, I didn't read your entire message previously. You have to
explicitly tell the Display what the Displayable is that you want to
show. There's no way in the MIDP to tell the VM what the screens are and
in what order they should be displayed.


Well are there any online examples of an entire application. The ones I
have
seen just have minimum amount of navigation. I will check into the
javadoc for the Display class.


There's not really much to it. In your commandAction() method, you
determine which command the user selected and then programmatically set the
next Displayable by calling:

Display.getDisplay([reference to your MIDlet]).setCurrent([the Displayable])

There's no underlying system for registering Displayables or mapping them,
though such would be a cool side project. :)

--
Darryl L. Pierce <mc******@myrealbox.com>
Visit the Infobahn Offramp - <http://bellsouthpwp.net/m/c/mcpierce>
"What do you care what other people think, Mr. Feynman?"
Jul 17 '05 #5

P: n/a
Ok, I tried this with the following code below, but got the exception listed
below ..

code snippet from MyMidlet
==============================
public void commandAction(
Command c, Displayable d ){
if (c == exitCommand) exitMIDlet();
if (c == selectCommand)
{
Display.getDisplay(new HelloMIDlet()).setCurrent(d);
}
}

exception during selectCommand
==============================
java.lang.SecurityException: Application not authorized to access the restricted API

at com.sun.midp.security.SecurityToken.checkIfPermiss ionAllowed(+40)
at com.sun.midp.security.SecurityToken.checkIfPermiss ionAllowed(+7)
at com.sun.midp.midletsuite.MIDletSuiteImpl.checkIfPe rmissionAllowed(+8)
at com.sun.midp.midlet.MIDletState.<init>(+66)
at javax.microedition.midlet.MIDletProxy.<init>(+5)
at javax.microedition.midlet.MIDlet.<init>(+13)
at HelloMIDlet.<init>(+4)
at MyMIDlet.commandAction(+27)
at javax.microedition.lcdui.Display$DisplayAccessor.c ommandAction(+284)
at javax.microedition.lcdui.Display$DisplayManagerImp l.commandAction(+10
at com.sun.midp.lcdui.DefaultEventHandler.commandEven t(+68)
at com.sun.midp.lcdui.AutomatedEventHandler.commandEv ent(+47)
at com.sun.midp.lcdui.DefaultEventHandler$QueuedEvent Handler.run(+250)

"Darryl L. Pierce" <mc******@myrealbox.com> wrote in message news:<ef******************************@free.terane ws.com>...
gilgantic wrote:
> How do you navigate between screens in J2ME? <snip>

Sorry, I didn't read your entire message previously. You have to
explicitly tell the Display what the Displayable is that you want to
show. There's no way in the MIDP to tell the VM what the screens are and
in what order they should be displayed.


Well are there any online examples of an entire application. The ones I
have
seen just have minimum amount of navigation. I will check into the
javadoc for the Display class.


There's not really much to it. In your commandAction() method, you
determine which command the user selected and then programmatically set the
next Displayable by calling:

Display.getDisplay([reference to your MIDlet]).setCurrent([the Displayable])

There's no underlying system for registering Displayables or mapping them,
though such would be a cool side project. :)

Jul 17 '05 #6

P: n/a
Peace to Darryl and Gilgantic!

I'm not sure what you really mean by Screen Navigation, but if you
mean being able to use the extra buttons such as those on the Nokia
9210i, I did try using the following app, which is the first I tried
to adapt from the provided SDK:

import com.symbian.devnet.crystal.awt.*;
import com.symbian.epoc.awt.*;
import java.awt.*;

class app1 extends CFrame {

EikCommandButtonGroup buttons;
final static int TBUTTON1 = EikCommandButtonGroup.BUTTON1;
final static int TBUTTON2 = EikCommandButtonGroup.BUTTON2;
final static int TBUTTON3 = EikCommandButtonGroup.BUTTON3;
final static int TBUTTON4 = EikCommandButtonGroup.BUTTON4;

public static void main (String args[]) {
new app1();
}

public app1() {
buttons = new EikCommandButtonGroup();
setTitle("Title");
add(buttons);
buttons.setText(TBUTTON1,"1");
buttons.setText(TBUTTON2,"");
buttons.setText(TBUTTON3,"3");
buttons.setText(TBUTTON4,"Close");
buttons.addCBAListener(new CBAListener() {
public void cbaActionPerformed (CBAEvent e) {
if (e.getID()==TBUTTON4) {
System.exit(0);
}
}
}
);
}
}

You'll have to download the additional Symbian classes but its worth
it if you can get those buttons to work the magic for you.

"Darryl L. Pierce" <mc******@myrealbox.com> wrote in message news:<ca******************************@free.terane ws.com>...
gilgantic wrote:
<snip>
if (c == selectCommand)
{
Display.getDisplay(new HelloMIDlet()).setCurrent(d);
}

<snip>

No. You can't instantiate a MIDlet to do this job. You have to have a
reference to the currently running MIDlet when attempting to get a Display
reference. The usually pattern is to have a setCurrent(Displayable) API in
your MIDlet class and set displays that way:

public class FooMIDlet extends MIDlet
{
private static FooMIDlet instance = null;

public FooMIDlet()
{
instance = this;
}

// ....

public static void setCurrent(Displayable screen)
{
Display.getDisplay(instance).setCurrent(screen);
}
}

Jul 17 '05 #7

P: n/a
From the examples I've seen, and what I've done personally, you should have
a class
that derives from midlet. Create a member variable of type Display in this
class, and
in the StartApp method of your derived class just set the display variable.
Now you always
have access to the display. I think creating a new Midlet inside a midlet
already running might be
your problem, but I'm new to this as well, so I'm not sure about that.

Code

public class Driver extends MIDlet {
Display m_display;
Driver {}
protected void startApp( ) {
m_display = Display.getDisplay( this );
}
}

Now just pass the m_display variable whenever you need access to the
display. Hope this helps.

Brandon
"gilgantic" <gi*******@yahoo.com> wrote in message
news:d6**************************@posting.google.c om...
Ok, I tried this with the following code below, but got the exception listed below ..

code snippet from MyMidlet
==============================
public void commandAction(
Command c, Displayable d ){
if (c == exitCommand) exitMIDlet();
if (c == selectCommand)
{
Display.getDisplay(new HelloMIDlet()).setCurrent(d);
}
}

exception during selectCommand
==============================
java.lang.SecurityException: Application not authorized to access the restricted API
at com.sun.midp.security.SecurityToken.checkIfPermiss ionAllowed(+40)
at com.sun.midp.security.SecurityToken.checkIfPermiss ionAllowed(+7)
at com.sun.midp.midletsuite.MIDletSuiteImpl.checkIfPe rmissionAllowed(+8)
at com.sun.midp.midlet.MIDletState.<init>(+66)
at javax.microedition.midlet.MIDletProxy.<init>(+5)
at javax.microedition.midlet.MIDlet.<init>(+13)
at HelloMIDlet.<init>(+4)
at MyMIDlet.commandAction(+27)
at javax.microedition.lcdui.Display$DisplayAccessor.c ommandAction(+284)
at javax.microedition.lcdui.Display$DisplayManagerImp l.commandAction(+10
at com.sun.midp.lcdui.DefaultEventHandler.commandEven t(+68)
at com.sun.midp.lcdui.AutomatedEventHandler.commandEv ent(+47)
at com.sun.midp.lcdui.DefaultEventHandler$QueuedEvent Handler.run(+250)

"Darryl L. Pierce" <mc******@myrealbox.com> wrote in message

news:<ef******************************@free.terane ws.com>...
gilgantic wrote:
> > How do you navigate between screens in J2ME? <snip>
>
> Sorry, I didn't read your entire message previously. You have to
> explicitly tell the Display what the Displayable is that you want to
> show. There's no way in the MIDP to tell the VM what the screens are and> in what order they should be displayed.

Well are there any online examples of an entire application. The ones I have
seen just have minimum amount of navigation. I will check into the
javadoc for the Display class.


There's not really much to it. In your commandAction() method, you
determine which command the user selected and then programmatically set the next Displayable by calling:

Display.getDisplay([reference to your MIDlet]).setCurrent([the Displayable])
There's no underlying system for registering Displayables or mapping them, though such would be a cool side project. :)

Jul 17 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.