Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: code for sending and recieving message in j2me usingg sun wireless toolkit

  1. #1
    Junior Member
    Join Date
    Mar 2011
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default code for sending and recieving message in j2me usingg sun wireless toolkit

    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    import javax.microedition.io.Connector;
    import javax.wireless.messaging.*;
    import java.io.*;
    import javax.microedition.io.PushRegistry;
    public class ui extends MIDlet implements CommandListener,Runnable,MessageListener
    {
    public Display display;
    public Form userint;
    public Command exit;
    public Command send;
    public TextField username;
    public TextField pin;
    public String un;
    public String pn;
    public TextMessage mymsg;
    public Alert disalert;
    //public String dest="123456";
    //public String dest_port;
    //public String dest_add="sms://" +dest+":"+dest_port;
    public MessageConnection mycon=null;
    public ui()
    {
    	//dest_port=getAppProperty("SMS-Port");
    	display=Display.getDisplay(this);
    	send=new Command("SEND",Command.SCREEN,1);
    	exit=new Command("EXIT",Command.EXIT,0);
    	username=new TextField("USERNAME:","",20,TextField.ANY);
    	pin=new TextField("PIN:","",10,TextField.PASSWORD);
    	userint=new Form("USERINTERFACE");
    	userint.append(username);
    	userint.append(pin);
    	userint.addCommand(send);
    	userint.addCommand(exit);
    	userint.setCommandListener(this);
     
     
     
    }
    public void startApp()
    {
     
    	display.setCurrent(userint);
    }
    public void pauseApp()
    {
    }
    public void destroyApp(boolean abc)
    {
    	notifyDestroyed();
    }
    public void commandAction(Command c,Displayable d)
    {
    	if(c==send)
    	{
    		un=username.getString();
    		pn=pin.getString();
            //sendmsg();
    		new Thread(this).start();
    		//destroyApp(true);
     
    		//notifyDestroyed();
    		disalert=new Alert("DATA SENT","WAIT FOR A MESSAGE ",null,AlertType.INFO);
    				disalert.setTimeout(50000);
    				disalert.addCommand(exit);
    				disalert.setCommandListener(this);
    		display.setCurrent(disalert);
     
     
    	}
    	if(c==exit)
    	{
    		destroyApp(true);
     
    	}
    }
    public void run()
    {
    	try
    				{
    					mycon=(MessageConnection)Connector.open(/*dest_add*/"sms://:6000");
    					mymsg=(TextMessage)mycon.newMessage(MessageConnection.TEXT_MESSAGE);
    			mymsg.setPayloadText(un+pn);
    			mycon.send(mymsg);
    			mycon.setMessageListener(this);
    			//mycon.close();
    			/*public void notifyIncomingMessage(MessageConnection mycon)
    						      {
     
    						         Message msg = mycon.receive();
    						         //do whatever you want with the message
    						         if(msg instanceof TextMessage) {
    						            //TextMessage tmsg = (TextMessage) msg;
     
    						            System.out.println(mymsg.getPayloadText());
     
    							}
     
    								}*/
     
    				}
    			catch(Exception ex1)
    			{
    		    }
    		    // Time to receive one.
    			//get reference to MessageConnection object
    	}
    			      public void notifyIncomingMessage(MessageConnection mycon)
    			      {
    					  try
    					  {
    			         Message msg = mycon.receive();
    			         //do whatever you want with the message
    			         if(msg instanceof TextMessage) {
    			            //TextMessage tmsg = (TextMessage) msg;
     
    			            System.out.println(mymsg.getPayloadText());
    					}
    				}
    					catch(Exception e)
    					{
    					}
     
    					}
     
     
     
    }
    //please help me with d port number and address..


  2. #2
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 286 Times in 225 Posts
    Blog Entries
    4

    Default Re: code for sending and recieving message in j2me usingg sun wireless toolkit

    Moved to - Mobile Applications

    Is there a question here neha?! What is the problem?
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

    Looking for a Java job? Visit - Java Programming Careers

  3. #3
    Junior Member
    Join Date
    Mar 2011
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: code for sending and recieving message in j2me usingg sun wireless toolkit

    with the above code i m not able to figure out where my message is gng.. i tried changing the port no and address still the same problem its not gng to its recepient..
    teme wats wrong in dis code
    Last edited by neha; March 3rd, 2011 at 01:18 PM.

  4. #4
    Junior Member
    Join Date
    Mar 2011
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: code for sending and recieving message in j2me usingg sun wireless toolkit

    with the above code i m able to figure out where my message is gng.. i tried changing the port no and address still the same problem its not gng to its recepient..
    teme wats wrong in dis code

Similar Threads

  1. Replies: 2
    Last Post: March 3rd, 2011, 01:22 PM
  2. Tracking raw wireless data
    By gnome in forum Java Networking
    Replies: 1
    Last Post: January 1st, 2011, 03:44 PM
  3. Toolkit.getSystemSelection problem
    By Paul.Baker in forum AWT / Java Swing
    Replies: 0
    Last Post: October 19th, 2010, 12:28 PM
  4. Java program to encrypt an image using crypto package
    By vikas in forum Java Networking
    Replies: 1
    Last Post: July 7th, 2009, 11:00 AM
  5. Sending and Receiving mail using J2ME without server
    By chals in forum Java ME (Mobile Edition)
    Replies: 5
    Last Post: June 2nd, 2009, 09:59 AM

Tags for this Thread