472,353 Members | 1,891 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 software developers and data experts.

J2ME Novice: Screen Navigation?

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
7 9029
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
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
"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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: gilgantic | last post by:
I am trying to discover how to download a J2ME application to a physical cell phone after testing using the emulator. How do I do this? Looking at...
6
by: Oz Mortimer | last post by:
Hi, Is there any way that I can scroll a canvas - i.e. if there are too many items on the canvas you can still access by pressing down. I know...
0
by: Dave Rathnow | last post by:
We are looking at using J2ME in a embedded device that will be deployed in an industrial application and I've been doing some research to see how...
1
by: Sveta | last post by:
Hi, all! I am new with J2ME. I have application that has form with 2 commands (exit and select). All UI uses are high level API, and it is...
0
by: 29A | last post by:
Hi, I am new to J2ME, and I need to get the pixel values of the image drawn on screen. What method do I need for this. I found out that PixelGrabber...
3
by: nickyeng | last post by:
I have a j2me application which will be tested on motorola and sony ericsson phone. the j2me application will loads a image PNG format 6.36kb...
0
by: WaluigiCubed | last post by:
Hi all, I'm designing a phone application using J2ME that uses the Open Source Diamond Powder methodology. The below getSchema method will...
1
by: WaluigiCubed | last post by:
Hi all, I just have a few small questions related to J2ME (specifically MIDP 2.0) programming. I appreciate any help that I will receive. 1)...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.