Results 1 to 4 of 4

Thread: Sound Alerts in J2ME

  1. #1
    Join Date
    Nov 2009
    Posts
    678

    Sound Alerts in J2ME

    Hi, I want to create Sound Alerts using MIDlet in J2ME, but while doing this I am getting much more error and I am not able to solve those problems. So, will you please give me some solution about this, which will give me details about the sound alert. I want to create a new program which will solve my problem, as there are many more problems exists in existing one. So, if possible give me source code also.

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Re: Sound Alerts in J2ME

    Sound alerts are the alerts in the form of sound. The AlertType() class has only one method as playSound(Display display), which is the boolean type method and used for Alert user by playing the sound.

    Alert Types in J2ME:
    • ALARM
    • CONFIRMATION
    • ERROR
    • INFO
    • WARNING


    The code given below is simplest code to understand working of Sound Alert in J2ME:

    Code:
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    
    public class SoundAlert extends MIDlet implements ItemStateListener, CommandListener
    {
    	private Display dis;    
    	private Form frm;      
    	private Command cmd;     
    	private ChoiceGroup cg; 
    
    	public void startApp()
    	{
    		dis = Display.getDisplay(this);
    		cg = new ChoiceGroup("List of Sound", Choice.EXCLUSIVE);
    		cg.append("Message Tone", null);    
    		cg.append("Confirmation Tone", null);    
    		cg.append("Warning Tone", null);            
    		cg.append("Alarm Tone", null);        
    		cg.append("Error Tone", null);    
    		cmd = new Command("Exit", Command.EXIT, 1);
    		frm = new Form("");
    		frm.append(cg);
    		frm.addCommand(cmd);
    		frm.setCommandListener(this);   
    		frm.setItemStateListener(this);
    		dis.setCurrent(frm);
    	}
    
    	public void pauseApp()
    	{
    	 }
    
    	public void destroyApp(boolean unconditional)
    	{
    		notifyDestroyed();
    	}
    
    	public void commandAction(Command c, Displayable s)
    	{
    		String label = c.getLabel();
    		if(label.equals("Exit"))
    		{
    			destroyApp(false);
    		} 
    	}
    
    	public void itemStateChanged(Item item)
    	{
    		switch (cg.getSelectedIndex())
    		{
    			case 0: 
    				AlertType.INFO.playSound(dis);
    			break;
    
    			case 1:
    				AlertType.CONFIRMATION.playSound(dis);
    			break;
    
    			case 2:
    				AlertType.WARNING.playSound(dis);
    			break;
    			
    			case 3:
    				AlertType.ALARM.playSound(dis);
    			break;
    
    			case 4:
    				AlertType.ERROR.playSound(dis);
    			break;
    		}
    	}
    }

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    Re: Sound Alerts in J2ME

    Hi, I don't have any information about the Sound Alerts in J2ME, but I also wanted to learn this. So, if you able to get more information about the sound alert give it to me also. As it will be helpful to me to gain more knowledge about the J2ME. So, please reply me with the basic details about the Sound alert. I am waiting for your reply. I don't have any knowledge regarding the sound alert. So, give me basic tutorials from which I will able to know what exactly it is.

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    Re: Sound Alerts in J2ME

    I am not having more information regarding the sound alert, but while searching on internet I got the code below which is on Sound alert. So, just check whether it is helpful to you or not.

    Code:
    import javax.microedition.lcdui.*;
    import javax.microedition.midlet.*;
    
    public class soundalert extends MIDlet 
    implements CommandListener 
    {
        Display dis;
        List lstitem;
        List choose;
        TextBox input;
        Ticker ticker = new Ticker("Test GUI Components");
        final Alert soundAlert = new Alert("sound Alert");
        DateField date = new DateField("Today's date: ", DateField.DATE);  
        Form form = new Form("Form for Stuff");
        Form today = new Form("Today's date");
        Gauge gauge = new Gauge("Progress Bar", false, 20, 9);
        TextField textfield = new TextField("TextField Label", "abc", 50, 0);
        static final Command backCommand = new Command("Back", Command.BACK, 0);
        static final Command mainMenuCommand = new Command("Main", Command.SCREEN, 1);
        static final Command exitCommand = new Command("Exit", Command.STOP, 2);
        String currentMenu;
        public soundalert() 
    {
        }
        public void startApp() throws MIDletStateChangeException 
    {
          dis = dis.getDisplay(this);
          lstitem = new List("Test Components", Choice.IMPLICIT);
          lstitem.append("Test TextBox", null);
          lstitem.append("Test List", null);
          lstitem.append("Test Alert", null);
          lstitem.append("Test Date", null);
          lstitem.append("Test Form", null);
          lstitem.addCommand(exitCommand);
          lstitem.setCommandListener(this);
          lstitem.setTicker(ticker);
          mainMenu();
          form.append(gauge);
          form.append(textfield);
          today.append(date);
        }
    
        public void pauseApp() 
    {
          dis = null;
          choose = null;
          lstitem = null;
          ticker = null;
          form = null;
          today = null;
          input = null;
          gauge = null;
          textfield = null;      
        }
    
        public void destroyApp(boolean unconditional) 
    {
          notifyDestroyed();
        }
        void mainMenu() 
    {
          dis.setCurrent(lstitem);
          currentMenu = "Main";
     }
        public void testTextBox() 
    {
          input = new TextBox ("Enter Some Text:", "", 10, TextField.ANY);
          input.setTicker(new Ticker( "Testing TextBox"));
          input.addCommand(backCommand);
          input.setCommandListener(this);
          input.setString("");
          dis.setCurrent(input);
          currentMenu = "input";
        }
    
        public void testList() 
    {
            choose = new List("Choose Items", Choice.MULTIPLE);
            choose.setTicker(new Ticker("Testing List"));
            choose.addCommand(backCommand);
            choose.setCommandListener(this);
            choose.append("Item 1", null);
            choose.append("Item 2", null);
            choose.append("Item 3", null);
            dis.setCurrent(choose);
            currentMenu = "list"; 
       }
       public void testAlert()
     {
          soundAlert.setType(AlertType.ERROR);
          soundAlert.setString("** ERROR **");
          dis.setCurrent(soundAlert);
       }
    
        public void testDate() 
    {
          java.util.Date now = new java.util.Date();
          date.setDate(now);
          today.addCommand(backCommand);
          today.setCommandListener(this);
          dis.setCurrent(today);
          currentMenu = "date";
       }
    
       public void testForm() 
    {
          form.addCommand(backCommand);
          form.setCommandListener(this);
          dis.setCurrent(form);
          currentMenu = "form";
       }
    
       public void commandAction(Command c, disable d)
     {
          String label = c.getLabel();
          if (label.equals("Exit")) 
    {
             destroyApp(true);
          } 
    else if (label.equals("Back")) 
    {
              if(currentMenu.equals("list") || currentMenu.equals("input") ||currentMenu.equals("date")|| currentMenu.equals("form"))
     {
                mainMenu();
              } 
    
          } 
    else 
    {
             List down = (List)dis.getCurrent();
             switch(down.getSelectedIndex()) 
    {
               case 0: testTextBox();
    break;
               case 1: testList();
    break;
               case 2: testAlert();
    break;
               case 3: testDate();
    break;
               case 4: testForm();
    break;
             }
                
          }
      }
    }

Similar Threads

  1. Need to change SMS alerts sound on Blackberry 8130
    By ADELYN in forum Portable Devices
    Replies: 6
    Last Post: 08-08-2011, 10:21 PM
  2. kxml2 and J2ME
    By Galbraith in forum Software Development
    Replies: 4
    Last Post: 17-04-2010, 03:27 AM
  3. How to add Custom Sound Alerts in MAC
    By Paisley007 in forum Operating Systems
    Replies: 5
    Last Post: 06-02-2010, 09:51 AM
  4. J2ME basic Example
    By REDBULL in forum Software Development
    Replies: 3
    Last Post: 10-12-2009, 08:46 AM
  5. J2me
    By manjava in forum Software Development
    Replies: 1
    Last Post: 24-10-2009, 08:56 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,201,909.87610 seconds with 17 queries