473,326 Members | 2,023 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 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 9113
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 using Sprint and Motorola for now, but any cell...
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 Form does this (apparently) but I need to do it...
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 practical J2ME would be for our application. Most...
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 very important to leave it high-level. This...
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 has not implementation in J2ME
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 in size and length is 146x38 pixels ON startup for...
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 eventually read in data to build screens on the phone...
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) When I use the LoginScreen Displayable control for...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.