Connecting Tech Pros Worldwide Forums | Help | Site Map

Retreive the Label Selected ImageItem in J2ME

Member
 
Join Date: Aug 2008
Posts: 48
#1: Dec 31 '08
Hi All,

I have a problem on retreiving the Label of selected ImageItem in J2ME.
Below one is my Code..
Expand|Select|Wrap|Line Numbers
  1. import javax.microedition.lcdui.Alert;
  2. import javax.microedition.lcdui.AlertType;
  3. import javax.microedition.lcdui.Command;
  4. import javax.microedition.lcdui.CommandListener;
  5. import javax.microedition.lcdui.Display;
  6. import javax.microedition.lcdui.Displayable;
  7. import javax.microedition.lcdui.Form;
  8. import javax.microedition.lcdui.Image;
  9. import javax.microedition.lcdui.ImageItem;
  10. import javax.microedition.lcdui.Item;
  11. import javax.microedition.lcdui.ItemStateListener;
  12. import javax.microedition.midlet.*;
  13.  
  14. public class homepage extends MIDlet {
  15.     private Display disp;
  16.     private Form form,form1;
  17.     private Command cmd,cmd1;
  18.     String[] str={"1","2","3"};
  19.     Image image,image1,image2;
  20.     public homepage(){
  21.         disp=Display.getDisplay(this);
  22.         form=new Form("Hai");
  23.         form1=new Form("Hello");
  24.         cmd=new Command("Exit", Command.EXIT , 1);
  25.         cmd1=new Command("Ok",Command.SCREEN,2);
  26.         form.addCommand(cmd);
  27.         form.addCommand(cmd1);
  28.         try{
  29.             image = Image.createImage("/xm-radio-mobile.jpg");
  30.             image1 = Image.createImage("/Drive-Backup-256x256.png");
  31.             image2 = Image.createImage("/exit.jpg");
  32.             form.append(new ImageItem("Backup", image, ImageItem.LAYOUT_LEFT , null));
  33.             form.append(new ImageItem("Restore", image1, ImageItem.LAYOUT_CENTER, null));
  34.             form.append(new ImageItem("Quit", image2, ImageItem.LAYOUT_RIGHT, null));    }catch (java.io.IOException e){
  35.       System.err.println(e);
  36.     }
  37.         form.setCommandListener(new CommandListener() {
  38.             public void commandAction(Command c, Displayable d) {
  39.                 if(c==cmd){
  40.                     destroyApp(false);
  41.                     notifyDestroyed();
  42.                 }
  43.             }
  44.         });
  45.     }
  46.     public void startApp() {
  47.         disp.setCurrent(form);
  48.     }
  49.     public void pauseApp() {
  50.     }
  51.     public void destroyApp(boolean unconditional) {
  52.     }
  53. }
  54.  
How can I Retreive the Selected Label of an ImageItem..

Thank You ...

Member
 
Join Date: Aug 2008
Posts: 48
#2: Dec 31 '08

re: Retreive the Label Selected ImageItem in J2ME


Hi All,

I have a problem on retreiving the Label of selected ImageItem in J2ME.
Below one is my Code..
Expand|Select|Wrap|Line Numbers
  1. import javax.microedition.lcdui.Alert;
  2. import javax.microedition.lcdui.AlertType;
  3. import javax.microedition.lcdui.Command;
  4. import javax.microedition.lcdui.CommandListener;
  5. import javax.microedition.lcdui.Display;
  6. import javax.microedition.lcdui.Displayable;
  7. import javax.microedition.lcdui.Form;
  8. import javax.microedition.lcdui.Image;
  9. import javax.microedition.lcdui.ImageItem;
  10. import javax.microedition.lcdui.Item;
  11. import javax.microedition.lcdui.ItemStateListener;
  12. import javax.microedition.midlet.*;
  13.  
  14. public class homepage extends MIDlet {
  15.     private Display disp;
  16.     private Form form,form1;
  17.     private Command cmd,cmd1;
  18.     String[] str={"1","2","3"};
  19.     Image image,image1,image2;
  20.     public homepage(){
  21.         disp=Display.getDisplay(this);
  22.         form=new Form("Hai");
  23.         form1=new Form("Hello");
  24.         cmd=new Command("Exit", Command.EXIT , 1);
  25.         cmd1=new Command("Ok",Command.SCREEN,2);
  26.         form.addCommand(cmd);
  27.         form.addCommand(cmd1);
  28.         try{
  29.             image = Image.createImage("/xm-radio-mobile.jpg");
  30.             image1 = Image.createImage("/Drive-Backup-256x256.png");
  31.             image2 = Image.createImage("/exit.jpg");
  32.             form.append(new ImageItem("Backup", image, ImageItem.LAYOUT_LEFT , null));
  33.             form.append(new ImageItem("Restore", image1, ImageItem.LAYOUT_CENTER, null));
  34.             form.append(new ImageItem("Quit", image2, ImageItem.LAYOUT_RIGHT, null));    }catch (java.io.IOException e){
  35.       System.err.println(e);
  36.     }
  37.         form.setCommandListener(new CommandListener() {
  38.             public void commandAction(Command c, Displayable d) {
  39.                 if(c==cmd){
  40.                     destroyApp(false);
  41.                     notifyDestroyed();
  42.                 }
  43.             }
  44.         });
  45.     }
  46.     public void startApp() {
  47.         disp.setCurrent(form);
  48.     }
  49.     public void pauseApp() {
  50.     }
  51.     public void destroyApp(boolean unconditional) {
  52.     }
  53. }
  54.  
How can I Retreive the Selected Label of an ImageItem..

Thank You ...
RedSon's Avatar
Site Moderator
 
Join Date: Jan 2007
Location: America
Posts: 3,393
#3: Dec 31 '08

re: Retreive the Label Selected ImageItem in J2ME


I've merged your posts, please do not double post.
Reply