J2ME Novice: Screen Navigation?
Question posted by: gilgantic
(Guest)
on
July 17th, 2005 09:41 PM
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
Would you like to answer this question?
Sign up for a free account, or Login (if you're already a member).
|
|
July 17th, 2005 09:41 PM
# 2
|
Re: J2ME Novice: Screen Navigation?
gilgantic wrote:
[color=blue]
> How do you navigate between screens in J2ME?[/color]
See the Javadoc for javax.microedition.lcdui.Display.setCurrent for more
information.
--
Darryl L. Pierce <mcpierce@myrealbox.com>
Visit the Infobahn Offramp - <http://bellsouthpwp.net/m/c/mcpierce>
"What do you care what other people think, Mr. Feynman?"
|
|
July 17th, 2005 09:41 PM
# 3
|
Re: J2ME Novice: Screen Navigation?
gilgantic wrote:
[color=blue]
> How do you navigate between screens in J2ME? <snip>[/color]
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 <mcpierce@myrealbox.com>
Visit the Infobahn Offramp - <http://bellsouthpwp.net/m/c/mcpierce>
"What do you care what other people think, Mr. Feynman?"
|
|
July 17th, 2005 09:41 PM
# 4
|
Re: J2ME Novice: Screen Navigation?
"Darryl L. Pierce" <mcpierce@myrealbox.com> wrote in message news:<d9dc010c5a10104976d43be08504583f@free.teranews.com >...[color=blue]
> gilgantic wrote:
>[color=green]
> > How do you navigate between screens in J2ME? <snip>[/color]
>
> 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.[/color]
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.
|
|
July 17th, 2005 09:41 PM
# 5
|
Re: J2ME Novice: Screen Navigation?
gilgantic wrote:[color=blue][color=green][color=darkred]
>> > How do you navigate between screens in J2ME? <snip>[/color]
>>
>> 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.[/color]
>
> 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.[/color]
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 <mcpierce@myrealbox.com>
Visit the Infobahn Offramp - <http://bellsouthpwp.net/m/c/mcpierce>
"What do you care what other people think, Mr. Feynman?"
|
|
July 17th, 2005 09:41 PM
# 6
|
Re: J2ME Novice: Screen Navigation?
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" <mcpierce@myrealbox.com> wrote in message news:<ef87acf347ecb7be859c33c43d38f300@free.teranews.com >...[color=blue]
> gilgantic wrote:[color=green][color=darkred]
> >> > 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.[/color]
> >
> > 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.[/color]
>
> 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. :)[/color]
|
|
July 17th, 2005 09:42 PM
# 7
|
Re: J2ME Novice: Screen Navigation?
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" <mcpierce@myrealbox.com> wrote in message news:<ca0c0be694766ea5d47d61352c744f2d@free.teranews.com >...[color=blue]
> gilgantic wrote:
> <snip>[color=green]
> > if (c == selectCommand)
> > {
> > Display.getDisplay(new HelloMIDlet()).setCurrent(d);
> > }[/color]
> <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);
> }
> }[/color]
|
|
July 17th, 2005 09:42 PM
# 8
|
Re: J2ME Novice: Screen Navigation?
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" <gilgantic@yahoo.com> wrote in message
news:d6052717.0308081206.7b613758@posting.google.c om...[color=blue]
> Ok, I tried this with the following code below, but got the exception[/color]
listed[color=blue]
> 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[/color]
restricted API[color=blue]
>
> 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" <mcpierce@myrealbox.com> wrote in message[/color]
news:<ef87acf347ecb7be859c33c43d38f300@free.teranews.com >...[color=blue][color=green]
> > gilgantic wrote:[color=darkred]
> > >> > 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[/color][/color][/color]
and[color=blue][color=green][color=darkred]
> > >> in what order they should be displayed.
> > >
> > > Well are there any online examples of an entire application. The ones[/color][/color][/color]
I[color=blue][color=green][color=darkred]
> > > have
> > > seen just have minimum amount of navigation. I will check into the
> > > javadoc for the Display class.[/color]
> >
> > There's not really much to it. In your commandAction() method, you
> > determine which command the user selected and then programmatically set[/color][/color]
the[color=blue][color=green]
> > next Displayable by calling:
> >
> > Display.getDisplay([reference to your MIDlet]).setCurrent([the[/color][/color]
Displayable])[color=blue][color=green]
> >
> > There's no underlying system for registering Displayables or mapping[/color][/color]
them,[color=blue][color=green]
> > though such would be a cool side project. :)[/color][/color]
Not the answer you were looking for? Post your question . . .
182,329 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).
|
|
|
Top Community Contributors
|