0

我已经尝试了两天编写一个拨打电话号码的代码,但我失败了

我编写了一个 midlet 和一个名为 main 作为 Displayable 的表单,该表单包含一个文本字段和

命令 。

当应用程序启动时,表格应出现并拨打所写的拨号号码

按下命令时的文本字段。

拨号过程对我不起作用。

import javax.microedition.io.ConnectionNotFoundException;

import javax.microedition.lcdui.Command; 

import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.Displayable.*;
import javax.microedition.lcdui.Form.*;
 import javax.microedition.midlet.MIDlet;
 import java.io.IOException;
 import java.io.InputStreamReader;
 import javax.microedition.lcdui.*;
 import javax.microedition.midlet.MIDlet;

public class DiallNumber extends MIDlet implements CommandListener
 {
    String num;
 private  Form main;
 private Command call,dial;
 private TextField phoneField;

 Display display;

 public DiallNumber()
    {


 main = new Form("main");
phoneField = new TextField("label","",10,phoneField.PHONENUMBER);
call = new Command("call",call.OK,0);
    main.append(phoneField);
    main.addCommand(call);
    num=this.phoneField.getString().trim();
main.setCommandListener(this);
 }

/**}
 * From MIDlet. Called when the MIDlet is started.
 */
 public void startApp()
 {

 // The initial display is the first form

display = Display.getDisplay(this);
   display.setCurrent(main);





     }

public void call( String number) {
 try {
 platformRequest("tel:"+number);
 } catch (ConnectionNotFoundException ex) {
 // TODO: Exception handling
 }
 }
 public void commandAction(Command c, Displayable d){
     if(d==main)
     {
         if(c==call)

              call(""+num);
     }

 }


 public void pauseApp()
 {
 // No implementation required
 }



/*


 * /
 */


/**
 * From MIDlet. Called to signal the MIDlet to terminate.
 *
* @param unconditional
 * whether the MIDlet has to be unconditionally terminated
 */
 public void destroyApp(boolean unconditional)
 {
 // No implementation required
 }

/**
 * From CommandListener. Called by the system to indicate that a command has
 * been invoked on a particular displayable.
 *
* @param command
 * the command that was invoked
 * @param displayable
 * the displayable where the command was invoked
 */



       }

我的日志跟踪

Copying 1 file to C:\Users\ELHADI\Documents\NetBeansProjects\DiallNumber2\dist\nbrun5217990045006831680
Copying 1 file to C:\Users\ELHADI\Documents\NetBeansProjects\DiallNumber2\dist\nbrun5217990045006831680
Jad URL for OTA execution: http://localhost:8082/servlet/org.netbeans.modules.mobility.project.jam.JAMServlet/C%3A/Users/ELHADI/Documents/NetBeansProjects/DiallNumber2/dist//DiallNumber2.jad
Starting emulator in execution mode
Installing suite from: http://127.0.0.1:49320/DiallNumber2.jad
[WARN] [rms     ] javacall_file_open: _wopen failed for: C:\Users\ELHADI\javame-sdk\3.0\work\0\appdb\_delete_notify.dat
4

1 回答 1

1

我已经解决了这个问题

import javax.microedition.io.ConnectionNotFoundException;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.Displayable.*;
import javax.microedition.lcdui.Form.*;
 import javax.microedition.midlet.MIDlet;
 import java.io.IOException;
 import java.io.InputStreamReader;
 import javax.microedition.lcdui.*;
 import javax.microedition.midlet.MIDlet;

public class DiallNumber extends MIDlet  
 {




    private  Display display;
 private MIDlet midlet;


Form f = new form("f");






/**}
 * From MIDlet. Called when the MIDlet is started.
 */
 public void startApp()
 {


display = Display.getDisplay(this);
  display.setCurrent(f);
}










 public void pauseApp()
 {
 // No implementation required
 }



/*


 * /
 */


/**
 * From MIDlet. Called to signal the MIDlet to terminate.
 *
* @param unconditional
 * whether the MIDlet has to be unconditionally terminated
 */
 public void destroyApp(boolean unconditional)
 {
 // No implementation required
 }
   class form extends   Form  implements CommandListener

           {
           private  Command call;

            private TextField phoneField;
           private String n;
   public form(String title )
       {
       super(title);

       call =new Command("call",call.OK,0);
       this.phoneField =new TextField("number","",20,phoneField.PHONENUMBER);


   addCommand(call);
   append(this.phoneField);

   this.setCommandListener(this);
      }

        public void commandAction(Command c,Displayable  d)
       {

   if(c==call)
   {


   try
   {
       n=phoneField.getString().trim();
      platformRequest("tel:"+n);


   }
  catch(javax.microedition.io.ConnectionNotFoundException e)
  {e.printStackTrace();}
   }


   }

   }




       }
于 2012-12-02T12:56:52.833 回答