Results 1 to 6 of 6
Thread: Event Handling
- 05-07-2007, 10:45 AM #1
Member
- Join Date
- May 2007
- Posts
- 11
- Rep Power
- 0
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??
- 05-07-2007, 03:33 PM #2
Member
- Join Date
- Apr 2007
- Location
- Indiana
- Posts
- 83
- Rep Power
- 0
Well, I have a few questions.
first of all do you know you have this code twice:
Exactly what Command package are you using? I see you are using the "==" instead of ".equals" .Java Code:if (c == back){ //Selecciono comando “Atrás” pantalla.setCurrent(listas[0]); }if (c == back){ //Selecciono comando “Atrás” pantalla.setCurrent(listas[0]); }
Just two thoughts right off the top of my head without knowing your imports.
p
- 05-07-2007, 04:23 PM #3
Member
- Join Date
- May 2007
- Posts
- 11
- Rep Power
- 0
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.
- 05-07-2007, 04:25 PM #4
Member
- Join Date
- Apr 2007
- Location
- Indiana
- Posts
- 83
- Rep Power
- 0
exactly what is the package that the Command class is coming from? Can you post your imports please? Thanks
- 05-07-2007, 05:36 PM #5
Member
- Join Date
- Apr 2007
- Location
- Indiana
- Posts
- 83
- Rep Power
- 0
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:
curley braces only around the switchJava Code:switch(i){ case o: doThis(); break; case 1: doThat(); break; }
- 05-07-2007, 06:05 PM #6
Member
- Join Date
- May 2007
- Posts
- 11
- Rep Power
- 0
Similar Threads
-
session handling
By priyanka_t in forum JavaServer Pages (JSP) and JSTLReplies: 10Last Post: 08-11-2009, 12:32 PM -
Event
By nt5515 in forum New To JavaReplies: 0Last Post: 02-15-2008, 04:44 PM -
SWT Event Handling
By Java Tip in forum Java TipReplies: 0Last Post: 12-30-2007, 12:21 PM -
Combo Box Event handling
By smajidali26 in forum AWT / SwingReplies: 1Last Post: 11-29-2007, 05:57 PM -
problem with event handling!!!
By ahdus in forum Java AppletsReplies: 1Last Post: 11-17-2007, 06:24 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks