J2ME Novice: Screen Navigation?

G

gilgantic

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
 
D

Darryl L. Pierce

gilgantic said:
How do you navigate between screens in J2ME?

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

Darryl L. Pierce

gilgantic said:
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.
 
G

gilgantic

Darryl L. Pierce said:
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.
 
D

Darryl L. Pierce

gilgantic said:
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. :)
 
G

gilgantic

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.checkIfPermissionAllowed(+40)
at com.sun.midp.security.SecurityToken.checkIfPermissionAllowed(+7)
at com.sun.midp.midletsuite.MIDletSuiteImpl.checkIfPermissionAllowed(+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.commandAction(+284)
at javax.microedition.lcdui.Display$DisplayManagerImpl.commandAction(+10
at com.sun.midp.lcdui.DefaultEventHandler.commandEvent(+68)
at com.sun.midp.lcdui.AutomatedEventHandler.commandEvent(+47)
at com.sun.midp.lcdui.DefaultEventHandler$QueuedEventHandler.run(+250)



Darryl L. Pierce said:
gilgantic said:
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. :)
 
N

Nick

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top