Search This Blog

Tuesday, 18 July 2023

Exercise 3 of Mobile Application Development Lab

0 comments

Development of Menu Creation using Option Buttons

(Experiment 3)







import javax.microedition.midlet.*;
import javax.microedition.lcdui.*; 

public class ChoiceGroupMidlet extends MIDlet  implements CommandListener, ItemStateListener
{
     public ChoiceGroup ch;
     public Form form;
     public Display display; 
     public Command cmdExit; 
     public StringItem st;

     public ChoiceGroupMidlet() 
     { 
         display = Display.getDisplay(this); 
         ch=new ChoiceGroup("Edit",Choice.EXCLUSIVE); 
         ch.append("cut",null); 
         ch.append("copy",null); 
         ch.append("paste",null); 
         ch.append("delete",null); 
         ch.append("select all",null); 
         ch.append("unselect all",null); 
         ch.setSelectedIndex(0, true); 
          
         form=new Form(""); 
         form.append(ch); 
         st=new StringItem("","The selected Option is Cut"); 
         form.append(st);
         cmdExit = new Command("Exit",Command.OK,1);
         form.addCommand(cmdExit);
         form.setCommandListener(this); 
         form.setItemStateListener(this);
     } 

    public void startApp() {
        display.setCurrent(form); 
    }
    
    public void pauseApp() {}

    public void destroyApp(boolean unconditional) {}
    
    public void commandAction(Command command,Displayable displayable) { 
        if(command == cmdExit)
        {
            destroyApp(true); 
            notifyDestroyed();
        }
    }
    
    public void itemStateChanged(Item item)
    {
     st.setText(""); 
            st.setText("The selected Option is " + ch.getString(ch.getSelectedIndex())); 
            form.append(st); 
    }
}

Output:




Leave a Reply