我知道用System.loadLibrary()加载动态库,但在applet中如何可以调用动态库?

解决方案 »

  1.   

    这是applet的程序代码package localmethod;import java.awt.*;
    import java.awt.event.*;
    import java.applet.*;/**
     * <p>Title: </p>
     * <p>Description: </p>
     * <p>Copyright: Copyright (c) 2003</p>
     * <p>Company: </p>
     * @author unascribed
     * @version 1.0
     */public class Applet1 extends Applet {
      private boolean isStandalone = false;
      private BorderLayout borderLayout1 = new BorderLayout();
      private Button button1 = new Button();
      private TextArea textArea1 = new TextArea();
      //Get a parameter value
      public String getParameter(String key, String def) {
        return isStandalone ? System.getProperty(key, def) :
          (getParameter(key) != null ? getParameter(key) : def);
      }  //Construct the applet
      public Applet1() {
      }
      //Initialize the applet
      public void init() {
        try {
          jbInit();
        }
        catch(Exception e) {
          e.printStackTrace();
        }
      }
      //Component initialization
      private void jbInit() throws Exception {
        this.setLayout(borderLayout1);
        button1.setLabel("button1");
        button1.addActionListener(new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            button1_actionPerformed(e);
          }
        });
        textArea1.setText("textArea1");
        this.add(button1, BorderLayout.NORTH);
        this.add(textArea1,  BorderLayout.CENTER);
      }
      //Get Applet information
      public String getAppletInfo() {
        return "Applet Information";
      }
      //Get parameter info
      public String[][] getParameterInfo() {
        return null;
      }  void button1_actionPerformed(ActionEvent e) {
        String s1 = "";
        try{
          LocalMethodDemo lmd1 = new LocalMethodDemo();
    //      textArea1.setText(lmd1.msg);
          s1 = lmd1.LocalMethod1();
          textArea1.setText(s1);    }
        catch(Exception e1){
          textArea1.setText(e1.getMessage());    }
      }}
      

  2.   

    //这是LocalMethodDemo.java的内容:package localmethod;
    public class LocalMethodDemo {
    public native static String LocalMethod1( );
    public native static int LocalMethod2( );
            public static String msg="";
    static{
              try{
    System.loadLibrary("LocalMethodDemo");
              }
              catch(Exception e){
                msg = e.getMessage();
              }
    }
    public static void main(String[] args){
    String sRet = ""; int iRet=0;
    try{
    System.out.println( "Call LocalMethod1" );
    sRet = LocalMethod1(  );
    System.out.println( "Return:" + sRet );
    System.out.println( "Call LocalMethod1 successfully :-)");
    }
    catch(Exception e){
    System.out.println("Call LocalMethod1 failed :-(");
    }
    try{
    System.out.println( "Call LocalMethod2" );
    iRet = LocalMethod2( );
    System.out.println("return = " + iRet );
    System.out.println( "Call LocalMethod2 successfully :-)");
    }
    catch(Exception e){
    System.out.println("Call LocalMethod2 failed :-(");
    } }
    }