Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-07-2007, 11:45 AM
Member
 
Join Date: May 2007
Posts: 11
luisarca is on a distinguished road
Event Handling
Hi to every one!

I have problems with my program, because I have 4 different list:The first list show the possibilities to choose among "photos Russia", "photos Finland" and "Photos Spain". The second list is the Photos Russia list, and the user can choose between 2 pictures to watch. The third list is Photos Finland, and the last one is Phostos Spain.
So, when the user choose, from the first list, "photos Russia",The user must see on the mobile screen the name of the pictures. Then, he can choose one of them, and the picture will be showed on the screen.
My problem is with the method Command Action, because it doesnt work properly. The function is as follows:
public void commandAction(Command c, Displayable d){

if (c == back){ //Selecciono comando “Atrás”

pantalla.setCurrent(listas[0]);
}if (c == back){ //Selecciono comando “Atrás”

pantalla.setCurrent(listas[0]);
}

else if (d==listas[0]){
System.err.println("Entro en la lista 0: \n");
if(c==listas[0].SELECT_COMMAND){// Si selecciono
switch(listas[0].getSelectedIndex()){ //opcion del menu
case 2:{ pantalla.setCurrent(listas[1]);break;}
case 1:{ pantalla.setCurrent(listas[2]);break;}
case 0:{pantalla.setCurrent(listas[3]);break;} // pantalla.setCurrent(listas[3]);break;
}
}
}else if(d==listas[1]){
System.err.println("Entro en la lista 1: \n");
if(c==List.SELECT_COMMAND){
int i=listas[1].getSelectedIndex();
switch(i){ //opcion del menu
case 1:{ canvas = new mostrarfotos(fotos[0]);
canvas.addCommand(exit);
canvas.addCommand(back);
canvas.setCommandListener(this) ;
pantalla.setCurrent(canvas);}
case 0:{canvas = new mostrarfotos(fotos[1]);
canvas.addCommand(exit);
canvas.addCommand(back);
canvas.setCommandListener(this) ;
pantalla.setCurrent(canvas);}
}
}
}else if(d==listas[2]){
System.err.println("Entro en la lista 2: \n");
if(c==List.SELECT_COMMAND){
int i=listas[2].getSelectedIndex();
switch(i){ //opcion del menu
case 1:{ canvas = new mostrarfotos(fotos[3]);
canvas.addCommand(exit);
canvas.addCommand(back);
canvas.setCommandListener(this) ;
pantalla.setCurrent(canvas);}
case 0:{canvas = new mostrarfotos(fotos[2]);
canvas.addCommand(exit);
canvas.addCommand(back);
canvas.setCommandListener(this) ;
pantalla.setCurrent(canvas);}
}
}
}else if(d==listas[3]){
System.err.println("Entro en la lista 3: \n");
if(c==List.SELECT_COMMAND){
int i=listas[3].getSelectedIndex();
switch(i){ //opcion del menu
case 1:{ canvas = new mostrarfotos(fotos[5]);
canvas.addCommand(exit);
canvas.addCommand(back);
canvas.setCommandListener(this) ;
pantalla.setCurrent(canvas);}
case 0:{canvas = new mostrarfotos(fotos[4]);
canvas.addCommand(exit);
canvas.addCommand(back);
canvas.setCommandListener(this) ;
pantalla.setCurrent(canvas);}
}
}
}


if (c == back){ //Selecciono comando “Atrás”

pantalla.setCurrent(listas[0]);
}
}

Where Listas[0] contains the main list, Listas[1] contains "Photos Russia", Listas[2] contains "Photos Spain" and so on.
But it does not work, and I do not know why. Can somebody help me??
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 05-07-2007, 04:33 PM
Member
 
Join Date: Apr 2007
Location: Indiana
Posts: 84
pegitha is on a distinguished road
Send a message via Skype™ to pegitha
Well, I have a few questions.
first of all do you know you have this code twice:
Code:
if (c == back){ //Selecciono comando “Atrás” pantalla.setCurrent(listas[0]); }if (c == back){ //Selecciono comando “Atrás” pantalla.setCurrent(listas[0]); }
Exactly what Command package are you using? I see you are using the "==" instead of ".equals" .
Just two thoughts right off the top of my head without knowing your imports.
p
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 05-07-2007, 05:23 PM
Member
 
Join Date: May 2007
Posts: 11
luisarca is on a distinguished road
Thank you very much
First of all, thank you very much for your reply.
Yes, I know that I have twice the command back, but there is not important in this case. I think it is not my problem.

The second question, .equals. I know that it is better to use .equals, but in a program that I did before I used .equals instead of (==) and the result was the same... But if you think I should change it, I will do, but I dont know if it is going to solve my problem.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 05-07-2007, 05:25 PM
Member
 
Join Date: Apr 2007
Location: Indiana
Posts: 84
pegitha is on a distinguished road
Send a message via Skype™ to pegitha
exactly what is the package that the Command class is coming from? Can you post your imports please? Thanks
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 05-07-2007, 06:36 PM
Member
 
Join Date: Apr 2007
Location: Indiana
Posts: 84
pegitha is on a distinguished road
Send a message via Skype™ to pegitha
Another issue with the code, each case is supposed to always have "break;" as the last liine.
case 1: canvas = new mostrarfotos(fotos[5]);
canvas.addCommand(exit);
canvas.addCommand(back);
canvas.setCommandListener(this) ;
pantalla.setCurrent(canvas);
break;
I have never used curley braces with the case either as you seem to have in your code. Mine look like this:
Code:
switch(i){ case o: doThis(); break; case 1: doThat(); break; }
curley braces only around the switch
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 05-07-2007, 07:05 PM
Member
 
Join Date: May 2007
Posts: 11
luisarca is on a distinguished road
It Works!
Thank you very much, Pegitha. It works, the program works. As you could have seen I am not an expert in J2ME.
Thank you very much for your help.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Event nt5515 New To Java 0 02-15-2008 05:44 PM
SWT Event Handling Java Tip Java Tips 0 12-30-2007 01:21 PM
session handling priyanka_t JavaServer Pages (JSP) and JSTL 9 12-17-2007 10:11 AM
Combo Box Event handling smajidali26 AWT / Swing 1 11-29-2007 06:57 PM
problem with event handling!!! ahdus Java Applets 1 11-17-2007 07:24 PM


All times are GMT +3. The time now is 12:24 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org