How to use JNI in an Applet?

Can a native method can be invoken in an Applet?If it can,which knowledge of Java should be used and how to use it?

You could I suppose if yo sign the applet (which, if the user accepts it, will allow it to use features otherwise not available to an applet because of the secure sandbox). However, I am not sure how you would deploy the necessary native library since it must be available to the native OS loader (ie, a file on the client machine). If you are deploying the applets (see WebStart perhaps) you could do it.
But generally it is a poor idea to try to use JNI in an Applet, and this is probably something that you would not want to use outside of an intranet environment.
Chuck

Similar Messages

  • How to use JNI?

    hi all,
    i know that pure java can't disable alt+tab,i must use JNI with C language. i have a pile of codes to disable the alt+tab in C but i do not know how to do it in JNI...can anyone help?thanks in advance...
    these are my codes in C:
    Private Declare Function SystemParametersInfo Lib "user32" _
    Alias "SystemParametersInfoA" (ByVal uAction As Long, _
    ByVal uParam As Long, lpvParam As Any, ByVal fuWinIni As Long) As Long
    Private Const SPI_SCREENSAVERRUNNING = 97
    Dim ret As Integer
    Dim pOld As Boolean
    Private Sub Form_Load()
    'The line below calls the function and passes
    'the constant and TRUE to fool Windows into thinking
    'the screensaver is running and FALSE to do the opposite...
    ret = SystemParametersInfo(SPI_SCREENSAVERRUNNING, True, pOld, 0)
    End Sub
    Private Sub Form_Unload(Cancel As Integer)
    'NOTE: THIS MUST BE SET TO FALSE WHEN
    'THE FORM OR APP CLOSES
    'If you do not set it to false, these keys will not work
    'with any app, or with anything in the Windows Environment...
    ret = SystemParametersInfo(SPI_SCREENSAVERRUNNING, False, pOld, 0)
    End Sub

    There really isn't a lot to using JNI.
    There are examples on Sun's website:
    http://developer.java.sun.com/developer/onlineTraining/Programming/JDCBook/jniexamp.html
    There is also a little more simple example at:
    http://www.inonit.com/cygwin/jni/helloWorld/java.html
    Basically, here are the steps:
    1) Create a simple java applet that will call your C/C++ code.
    For practise, I would just use the HelloWorld example from www.inonit.com:
    package example.jni;
    public class HelloWorld {
         private static native void writeHelloWorldToStdout();
         public static void main(String[] args) {
              writeHelloWorldToStdout();
    2) Name the file with the code above HelloWorld.java and compile it:
    javac HelloWorld.java
    3) Use javah to generate the C header file:
    javah example.jni.HelloWorld
    (You may need to cd to the parent directory of 'example', in this case)
    4) The above line should create a example_jni_HelloWorld.h header file.
    Use this header file in your C/C++ DLL. Make sure your C/C++ compile knows where to find jni.h. In my compiler, I added the following paths:
    C:\J2SDK1.4.1\INCLUDE\
    C:\J2SDK1.4.1\INCLUDE\WIN32
    5) The trickiest part about JNI is passing in and returning parameters.
    If you don't have to pass in or return any parameters, then you're almost done. Replace your C/C++ function protocol with the protocol in the header file you generated. Compile your DLL.
    6) Copy the DLL to a path that it will be found by your Java Applet. (If running on Windows, this would be your System32 or System directory.)
    7) I also had to edit my Path environment variable to include the Java Runtime bin directory. On my machine it was: C:\J2SDK1.4.1\jre\bin
    8) Try running your java applet:
    Java example.jni.HelloWorld
    Good Luck!

  • How to use DOMParser from an Applet / Or, how to parse XML from an Applet?

    Hey,
    As stating in the subject line, I wonder how to do it without getting an �Access Denied� error.
    I would like to parse a XML file that has external DTD pointing to a SYSTEM location. Yes, I can change it to a public location. However, in either way, I have problems to use DOMBuilder to parse the xml file. The application always throws the security exception.
    I tried to use the DOMParser from org.apache.xerces.parsers to parse the xml file. I set the DOMParser to ignore parsing the external DTD, and use the DOMParser.parse(InputSource) to parse the xml file from a giving URL. However, I get null of the result document.
    Does anyone know how to parse the XML from an Applet? Or, does anyone know how to use the DOMParser from an Applet?
    Thank you very much,

    If the document resides on the local filesystem, you will need to sign a CAB or JAR for the applet to circumvent the sandbox's security restrictions. There are dozens of posts on how to do this. Basically, that will turn the applet into an application, from a Java security perspective.
    - Saish
    "My karma ran over your dogma." - Anon

  • How to use jsp:plugin type="applet" in jsp

    Hi ,
    I have a JSP File.
    How to use jsp:plugin tag in that.
    When I specify the file name in code="applet.class" Then it is giving an error saying that It could not find the class.
    What is the solution for this.

    its not working.. it shows exception class not found exception.
    i have placed the jsp and applet class in the same folder. but its not working.
    jsp file path : OracleSpatial\mypackage\webmap.jsp
    applet class : OracleSpatial\mypackage\demoApplet.class
    demoApplet class inside package "mypackage".
    code inside JSP is :
    <jsp:plugin type="applet"
    code="mypackage.demoApplet.class" width = "100%" height = "100%" >
    </jsp:plugin>

  • How to use jni with ervlets

    Hi
    i was trying to do some example with JNI. I can use JNI with standalone Java application but I just cannot figure out how I can use JNI with Servlet.
    Can some one show me a sample code using JNI with Servlets.
    thanks very much

    JNI is done in servlets that same way as other java.
    I suspect your problem is in the environment and perhaps how servlets work. It doesn't have anything to do with JNI itself.

  • How to use JNI with Servlets

    Hi
    i was trying to do some example with JNI. I can use JNI with standalone Java application but I just cannot figure out how I can use JNI with Servlet.
    Can some one show me a sample code using JNI with Servlets.
    thanks very much

    hi,
    I am also facing the same problem,
    when I am using JNI with stand alone application it works fine but when i tried to use it with a servlet It gives unsatisfied linker error
    stack: java.lang.UnsatisfiedLinkError: createSocket
         at RelayConnector.createSocket(Native Method)
         at RelayServlet.doGet(RelayServlet.java:70)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at com.iplanet.server.http.servlet.NSServletRunner.invokeServletService(NSServletRunner.java:891)
         at com.iplanet.server.http.servlet.NSServletRunner.Service(NSServletRunner.java:458)
    It seems i have to do some path settings in my iplenet web server.
    If some one have faced the problem i would be glad to know the solution for this, i am literally bugged up,....

  • How to Use JNI for linux based C programs

    Hi all,
    I am doing my project in JAVA for my Institute. There is a Central server. All the API's have written in C. The C APIs are Linux based.
    The problem is getting records from the database through API.
    I tried the Java Native Methods. I am able to do that in console with out problem. Since my project is web based I want to fetch the records through the C APIs in JSP. Is it possible? How to do that?
    Please Help me.
    -Prathap

    Why can't you use JDBC?
    I tried the Java Native Methods. I am able to do that in console with out problem. Since my project is web based I want to fetch the records through the C APIs in JSP. Is it possible? How to do that?JSP runs in a server. Which is just a big console application. Same as any other.
    Basic process.
    1. Write the JNI
    2. Insure the JNI is in the servers shared library path. This can depend on the user that the server runs under (unlikely to be you.)
    3. Add the java code into the server.

  • How to use JNI and run javah

    When using a DLL I'm supposed to use javah on my class file, for creation of a C headerfile. How's this done in JDeveloper?

    JDeveloper doesn't include a wizard for this. You can run setvars.bat from the JDeveloper\Bin directory from a command prompt and that will set up your path and CLASSPATH for using the command line tools.
    You can then run the javah command directly to generate the header files to use when creating your C/C++ JNI code.
    Take Care,
    Rob
    null

  • Help !! How to use SmtpClient in an Applet?

    Hi,
    I have 2 TextFields and a button in an Applet. On click of the button, I wanted to get connected to an email server (e.g pop.mail.yahoo.com) and post my message using (smtp.mail.yahoo.com) to "[email protected]" . I tried this programme using both URL and Sockets. But in both cases I am getting "NullPointerException". Can any one help me with this problem by giving some source code?
    Here is my code:
    if (ae.getSource().equals(button1))
    System.out.println("Clicked Send");
    try
    sendmail = new SmtpClient("smtp.mail.yahoo.com");
    //sendmail = new SmtpClient("java.sun.com");
    System.out.println("connecting......");
    System.out.println("SendMail:" +sendmail);
    sendmail.from(getString);
    sendmail.to("mailto:[email protected]");
    //sendmail.to("[email protected]");
    ps = sendmail.startMessage();
    System.out.println("PS :" +ps);
    //succeed = true;
    catch(Exception e)
    //e.printStackTrace();
    System.out.println("Couldn't reach you through javasoft, trying your local machine instead. You probably are behind a firewall.");
    The source code has been provided, can any one help me?
    Thanks
    [email protected]

    well the answer is simple
    "sendmail" object is NULL and ur trying to access the methods from it.
    When u instantiate SmtpClient. It just creates a Object. it does not actually connect to the MailServer. u would probably need to luk into API and find out the appropriate method for connect......well i haven't myself luked into the API so i am not too sure about this
    Manja

  • How to use JNI to access Active X control ?

    I need to access EFTPOS devices which provides Active X control inerface. Can I wrap Active X into dll so that I can use java native interface to access it ?
    Thanks.

    Hi Mahesh!
    If nobody has answered by now...maybe you managed alone. Anyway here are some notes that might be useful:
    The first thing to do is write your Java class with the native definitions. Now 'Build Project'.
    Of course you shouldn't forget to have a line with
    System.loadLibrary("your library name");Next you need to make the .h file. I think it's best to do this manually. In Netbeans you can add a line to the ant build script like:
    <target name="-post-jar">
           <javah destdir="c" class="--your class full name--" classpath="${dist.jar}" />
        </target>but I don't know how to do this in Eclipse. Instead you will have to run javah manually like:
    javah -classpath build -verbose  -d "c"   "--your class full name--"Do this from the main project directory.
    Now create a separate C/C++ project with the name you used in the loadLibrary above, and make C files to implement the functionality you need (copy the function headers from the .h file). You should include the .h file and tell Eclipse where to find it. In Eclipse 3.4 there are workspace relative paths - and you can use those to add the include file.
    The C project should be of type 'shared library'. On Windows it will produce a DLL.
    Once you have your C project compiling, go back to the Java project, and edit the project class path. Under the 'source' tab expand your project source, and you will see a line for 'Native library location'. Select that, click the 'edit' button and add the path of the DLL (just the directory).
    Now run or debug the Java program, and when you load the library, watch to make sure there is no exception.
    How to debug: There are ways of debugging both the Java and C at the same time, but it's probably easiest just to put logging statements in the C (printf's) to see what's going on there.

  • How to use JNI in JSP???

    I have jsp on tomcat. I'd like to get some method from JNI in JSP. I'm already test JNI with java application, it's work well. But I don't know how to adapt in JSP. Could anyone help?
    Thanks and Best Regards,

    Hello,
    Thanks for your reply.
    I 've already write a seperate class that includes the JNI call but I've got jspwrapper error.
    Could you please suggest me?

  • How to use drawLine not in Applet

    I need your help.
    I am new in Java programming.
    I use bean to display 3 photos on a web page.
    One is very big and the two last are like labels.
    I would like to draw a line from these labels to that big photo.
    And I did not succeed to use the drawLine method.
    Someone can help me please??
    Thanks
    Gwan

    Hi rapy_xjb!
    It's troublesome, would need to deploy applet and all dependent classes! A lot of files to download (in jar file or not)! Think in benefits to user after installing Java plug-in. My lemma: Java and diamonds are forever!
    Best regards.

  • Need a Big Help please on how to use getAppletContext() method

    I have three classes, first one extends JApplet, second class I use two create my popup menus, third class I use for my main actions to be done. I need when a popup menu is clicked to load a page, but I am getting this error.
    java.lang.NullPointerException
    at java.applet.Applet.getAppletContext(Applet.java:171)
    at Popup_Menus$1.actionPerformed(Popup_Menus.java:90)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1764)
    at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1817)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:419)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:257)
    at javax.swing.AbstractButton.doClick(AbstractButton.java:289)
    at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:1113)
    at javax.swing.plaf.basic.BasicMenuItemUI$MouseInputHandler.mouseReleased(BasicMenuItemUI.java:943)
    at java.awt.Component.processMouseEvent(Component.java:5134)
    at java.awt.Component.processEvent(Component.java:4931)
    at java.awt.Container.processEvent(Container.java:1566)
    at java.awt.Component.dispatchEventImpl(Component.java:3639)
    at java.awt.Container.dispatchEventImpl(Container.java:1623)
    at java.awt.Component.dispatchEvent(Component.java:3480)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3450)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3165)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3095)
    at java.awt.Container.dispatchEventImpl(Container.java:1609)
    at java.awt.Component.dispatchEvent(Component.java:3480)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:450)
    at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Ev
    My Code is messy, but here it is: -
    Class One
    //package final_project;
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.sql.*;
    import java.util.*;
    import java.io.*;
    import java.applet.*;
    import java.net.*;
    public class Main_Interface extends JApplet implements Runnable {
    GUICanvas MainCanvas;
    int counter = 0;
    protected int delay = 10000;
    private Thread timeThread= null;
         public void init() {
         Container contentPane = getContentPane();
    MainCanvas = new GUICanvas();
    contentPane.setBounds(0,0,850,650);
         contentPane.add(MainCanvas);
    public void start() {
    timeThread = new Thread(this);
    timeThread.start();
    public void run() {
    Thread myThread = Thread.currentThread();
    while (timeThread == myThread) {
    try {
    Thread.currentThread().sleep(delay);
    } catch (InterruptedException e){}
    counter ++;
    MainCanvas.TheKing();
    Class Two
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.sql.*;
    import java.util.*;
    import java.io.*;
    import java.applet.*;
    import java.net.*;
    import java.applet.*;
    public class Popup_Menus extends Applet implements MouseListener {
    JPopupMenu ar[] = new JPopupMenu[16];
    JMenuItem it[] = new JMenuItem[84];
    public Popup_Menus() {
    for (int i=0;i<16;i++)
    ar[i] = new JPopupMenu();
    for (int i=0;i<84;i++)
    it[i] = new JMenuItem();
    it.setBackground(Color.orange);
    it[i].setForeground(Color.cyan);
    it[16]= new JMenuItem("Shop Details");
    it[17]= new JMenuItem("NoOfStaff");
    it[18]= new JMenuItem("ShopAssest");
    it[0] = new JMenuItem("Oracle");
    ar[0].add(it[0]);
    it[1] = new JMenuItem("Macrosoft");
    ar[1].add(it[1]);
    it[2] = new JMenuItem("SunMicro");
    ar[2].add(it[2]);
    it[3] = new JMenuItem("PeopleSoft");
    ar[3].add(it[3]);
    it[4] = new JMenuItem("HP");
    ar[4].add(it[4]);
    it[5] = new JMenuItem("Dell");
    ar[5].add(it[5]);
    it[6] = new JMenuItem("Compact");
    ar[6].add(it[6]);
    it[7] = new JMenuItem("Apple");
    ar[7].add(it[7]);
    it[8] = new JMenuItem("Sony");
    ar[8].add(it[8]);
    it[9] = new JMenuItem("Philipes");
    ar[9].add(it[9]);
    it[10] = new JMenuItem("Bush");
    ar[10].add(it[0]);
    it[11] = new JMenuItem("Granada");
    ar[11].add(it[11]);
    it[12] = new JMenuItem("PC");
    ar[12].add(it[12]);
    it[13] = new JMenuItem("Macintosh");
    ar[13].add(it[13]);
    it[14] = new JMenuItem("Laptop");
    ar[14].add(it[14]);
    it[15] = new JMenuItem("Solaris");
    ar[15].add(it[15]);
    it[0].addActionListener(new ActionListener()
    public void actionPerformed(ActionEvent e)
    ar[0].add(it[16]);
    ar[0].add(it[17]);
    ar[0].add(it[18]);
    System.out.println("Working");
    // ma = new Main_Interface();
    try
    System.out.println("menuitem");
    String s="ali";
    URL url = new URL("http://www.google.com");
    getAppletContext().showDocument(url,s);
    catch(MalformedURLException malformedurlexception)
    System.err.println(malformedurlexception);
    public void mouseClicked(java.awt.event.MouseEvent e) {
    //ar[0].show(this,30,30);
    public void mouseEntered(java.awt.event.MouseEvent mouseEvent) {
    public void mouseExited(java.awt.event.MouseEvent mouseEvent) {
    public void mousePressed(java.awt.event.MouseEvent mouseEvent) {
    public void mouseReleased(java.awt.event.MouseEvent mouseEvent) {
    Class Three
    //package final_project;
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.sql.*;
    import java.util.*;
    import java.io.*;
    import java.applet.*;
    import java.net.*;
    public class GUICanvas extends JPanel implements MouseMotionListener,ActionListener,MouseListener
    private Color color;
    Popup_Menus popup = new Popup_Menus();
    private Font font;
    double a1, Q = 0,Z = 0,P = 1, S1;
    String Percentages;
    double Aa=0,Ba=0,Ca=0,Da=0;
    double Aa1=0,Ba1=0,Ca1=0,Da1=0;
    double Aa2=0,Ba2=0,Ca2=0,Da2=0;
    double Aa3=0,Ba3=0,Ca3=0,Da3=0;
    double Aa4=0,Ba4=0,Ca4=0,Da4=0;
    double Sum = 0,Sum1 = 0, Sum2 = 0, Sum3 = 0, Sum4 = 0;
    double A=0, B=0, C=0, D=0;
    double A1=0, B1=0, C1=0, D1=0,A2=0, B2=0, C2=0, D2=0;
    double k1=0,k2=0,l1=0,l2=0,r1=0,r2=0,u1=0,u2=0;
    int xpos,ypos,popcounter=0;
    double DC1[] = new double[4];
    double DC2[] = new double[4];
    double DC3[] = new double[4];
    double DC4[] = new double[4];
    boolean rect1Active[] = new boolean[4];
    boolean rect1Active2[] = new boolean[4];
    boolean rect1Active3[] = new boolean[4];
    boolean rect1Active4[] = new boolean[4];
    double DF1[] = new double[4];
    double DF2[] = new double[4];
    double DF3[] = new double[4];
    double DF4[] = new double[4];
    double Ap[] = new double[4];
    double Bp[] = new double[4];
    double Cp[] = new double[4];
    double Dp[] = new double[4];
    int rect1width[] = new int[4];
    int rect1height[] = new int[4];
    int rect1xco[] = new int[4];
    int rect1yco[] = new int[4];
    int rect1width2[] = new int[4];
    int rect1height2[] = new int[4];
    int rect1xco2[] = new int[4];
    int rect1yco2[] = new int[4];
    int rect1width3[] = new int[4];
    int rect1height3[] = new int[4];
    int rect1xco3[] = new int[4];
    int rect1yco3[] = new int[4];
    int rect1width4[] = new int[4];
    int rect1height4[] = new int[4];
    int rect1xco4[] = new int[4];
    int rect1yco4[] = new int[4];
    double rect1width5[] = new double[4];
    double rect1height5[] = new double[4];
    double rect1xco5[] = new double[4];
    double rect1yco5[] = new double[4];
    public GUICanvas() {
    setBackground( Color.black );
    TheKing();
    addMouseListener(this);
    addMouseMotionListener(this);
    public void TheKing()
    double X=740, Y=470, Ap=0,Bp=0,Cp=0,Dp=0;
    String line[] = new String[4];
    /* try {
    URL url = new URL(
         "http://localhost:111/test/servlet/TestServlet");
    BufferedReader in = new BufferedReader(
         new InputStreamReader(url.openStream()));
    for (int i = 0; i<4; i++)
    line[i] = in.readLine();
    in.close();
    }catch (Exception e){
    e.printStackTrace();
    line[0] = "200";
    line[1] = "200";
    line[2] = "200";
    line[3] = "200";
    Aa = s2d(line[0]);
    Ba = s2d(line[1]);
    Ca = s2d(line[2]);
    Da = s2d(line[3]);
    rect1xco5[0] = 20;
    rect1yco5[0] = 20;
    Sum=Aa+Ba+Ca+Da;
    Ap = (Aa/Sum)*100;
    Bp = (Ba/Sum)*100;
    Cp = (Ca/Sum)*100;
    Dp = (Da/Sum)*100;
    A= (Ap/100)*(X*Y);
    B= (Bp/100)*(X*Y);
    C= (Cp/100)*(X*Y);
    D= (Dp/100)*(X*Y);
    Q = ((A*C)+(X*Y*D)+(X*C*Y)+(B*X*Y)-(Y*A*X)-((X*X)*(Y*Y))-(B*D))/((X*(Y*Y))-(Y*D)-(C*Y));
    Z = (((X*X)*Y*A)-(X*C*A)-(B*X*A))/((X*(Y*Y))-(Y*D)-(C*Y));
    A1 =((-Q) + (Math.sqrt((Q*Q)-(4*P*Z))))/(2*P);
    A2=A/A1;
    B1=X-A1;
    B2=B/B1;
    D2=Y-A2;
    D1=D/D2;
    C1=X-D1;
    C2=C/C1;
    S1=B2+C2;
    rect1width5[0] = d2i(A1);
    rect1height5[0] = d2i(A2);
    rect1width5[1] = d2i(B1);
    rect1height5[1] = d2i(B2);
    rect1width5[2] = d2i(D1);
    rect1height5[2] = d2i(D2);
    rect1width5[3] = d2i(C1);
    rect1height5[3] = d2i(C2);
    rect1xco5[1] = rect1xco5[0] + rect1width5[0];
    rect1yco5[1] = rect1xco5[0];
    rect1xco5[2] = rect1xco5[0];
    rect1yco5[2] = rect1yco5[0] + rect1height5[0];
    rect1xco5[3] = rect1xco5[0] + rect1width5[2];
    rect1yco5[3] = rect1yco5[0] + rect1height5[1];
    k1=rect1xco5[0]+rect1width5[0];
    k2=rect1yco5[0]+rect1height5[0];
    l1=rect1width5[1]-20;
    l2=rect1yco5[1]+rect1height5[1];
    r1=rect1xco5[0]+rect1width5[2];
    r2=rect1height5[2]-20;
    u1=rect1width5[3]-20;
    u2=rect1height5[3]-20;
    RegionOne(k1, k2);
    RegionTwo(l1,l2);
    RegionThree(r1, r2);
    RegionFour(u1, u2);
    public void RegionOne(double X1, double Y1)
    String line[] = new String[4];
    /* try {
    URL url = new URL(
         "http://localhost:111/test/servlet/TestServlet1?name=ONE");
    BufferedReader in = new BufferedReader(
         new InputStreamReader(url.openStream()));
    for (int i = 0; i<4; i++)
    line[i] = in.readLine();
    in.close();
    }catch (Exception e){
    e.printStackTrace();
    line[0] = "1200";
    line[1] = "2100";
    line[2] = "1200";
    line[3] = "2100";
    DC1[0] = Aa1 ;
    DC1[1] = Ba1 ;
    DC1[2] = Ca1;
    DC1[3] = Da1;
    Aa1 = s2d(line[0]);
    Ba1 = s2d(line[1]);
    Ca1 = s2d(line[2]);
    Da1 = s2d(line[3]);
    DF1[0] = Aa1 ;
    DF1[1] = Ba1 ;
    DF1[2] = Ca1;
    DF1[3] = Da1;
    rect1xco[0] = 20;
    rect1yco[0] = 20;
    Sum1=Aa1+Ba1+Ca1+Da1;
    Ap[0] = (Aa1/Sum1)*100;
    Bp[0] = (Ba1/Sum1)*100;
    Cp[0] = (Ca1/Sum1)*100;
    Dp[0] = (Da1/Sum1)*100;
    A= (Ap[0]/100)*(X1*Y1);
    B= (Bp[0]/100)*(X1*Y1);
    C= (Cp[0]/100)*(X1*Y1);
    D= (Dp[0]/100)*(X1*Y1);
    Q = ((A*C)+(X1*Y1*D)+(X1*C*Y1)+(B*X1*Y1)-(Y1*A*X1)-((X1*X1)*(Y1*Y1))-(B*D))/((X1*(Y1*Y1))-(Y1*D)-(C*Y1));
    Z = (((X1*X1)*Y1*A)-(X1*C*A)-(B*X1*A))/((X1*(Y1*Y1))-(Y1*D)-(C*Y1));
    A1 =((-Q) + (Math.sqrt((Q*Q)-(4*P*Z))))/(2*P);
    A2=A/A1;
    B1=X1-A1;
    B2=B/B1;
    D2=Y1-A2;
    D1=D/D2;
    C1=X1-D1;
    C2=C/C1;
    S1=B2+C2;
    rect1width[0] = d2i(A1);
    rect1height[0] = d2i(A2);
    rect1width[1] = d2i(B1);
    rect1height[1] = d2i(B2);
    rect1width[2] = d2i(D1);
    rect1height[2] = d2i(D2);
    rect1width[3] = d2i(C1);
    rect1height[3] = d2i(C2);
    rect1xco[1] = rect1xco[0] + rect1width[0];
    rect1yco[1] = rect1xco[0];
    rect1xco[2] = rect1xco[0];
    rect1yco[2] = rect1yco[0] + rect1height[0];
    rect1xco[3] = rect1xco[0] + rect1width[2];
    rect1yco[3] = rect1yco[0] + rect1height[1];
    public void RegionTwo(double X2, double Y2)
    String line[] = new String[4];
    /* try {
    URL url = new URL(
         "http://localhost:111/test/servlet/TestServlet1?name=TWO");
    BufferedReader in = new BufferedReader(
         new InputStreamReader(url.openStream()));
    for (int i = 0; i<4; i++)
    line[i] = in.readLine();
    in.close();
    catch (Exception e){
    e.printStackTrace();
    line[0] = "1200";
    line[1] = "2100";
    line[2] = "1200";
    line[3] = "2100";
    DC2[0] = Aa2;
    DC2[1] = Ba2;
    DC2[2] = Ca2;
    DC2[3] = Da2;
    Aa2 = s2d(line[0]);
    Ba2 = s2d(line[1]);
    Ca2 = s2d(line[2]);
    Da2 = s2d(line[3]);
    DF2[0] = Aa2 ;
    DF2[1] = Ba2 ;
    DF2[2] = Ca2;
    DF2[3] = Da2;
    rect1xco2[0] = rect1xco[1]+rect1width[1];
    rect1yco2[0] = 20;
    Sum2=Aa2+Ba2+Ca2+Da2;
    Ap[1] = (Aa2/Sum2)*100;
    Bp[1] = (Ba2/Sum2)*100;
    Cp[1] = (Ca2/Sum2)*100;
    Dp[1] = (Da2/Sum2)*100;
    A= (Ap[1]/100)*(X2*Y2);
    B= (Bp[1]/100)*(X2*Y2);
    C= (Cp[1]/100)*(X2*Y2);
    D= (Dp[1]/100)*(X2*Y2);
    Q = ((A*C)+(X2*Y2*D)+(X2*C*Y2)+(B*X2*Y2)-(Y2*A*X2)-((X2*X2)*(Y2*Y2))-(B*D))/((X2*(Y2*Y2))-(Y2*D)-(C*Y2));
    Z = (((X2*X2)*Y2*A)-(X2*C*A)-(B*X2*A))/((X2*(Y2*Y2))-(Y2*D)-(C*Y2));
    A1 =((-Q) + (Math.sqrt((Q*Q)-(4*P*Z))))/(2*P);
    A2=A/A1;
    B1=X2-A1;
    B2=B/B1;
    D2=Y2-A2;
    D1=D/D2;
    C1=X2-D1;
    C2=C/C1;
    rect1width2[0] = d2i(A1);
    rect1height2[0] = d2i(A2);
    rect1width2[1] = d2i(B1);
    rect1height2[1] = d2i(B2);
    rect1width2[2] = d2i(D1);
    rect1height2[2] = d2i(D2);
    rect1width2[3] = d2i(C1);
    rect1height2[3] = d2i(C2);
    rect1xco2[1] = rect1xco2[0] + rect1width2[0];
    rect1yco2[1] = rect1yco2[0];
    rect1xco2[2] = rect1xco2[0];
    rect1yco2[2] = rect1yco2[0] + rect1height2[0];
    rect1xco2[3] = rect1xco2[0] + rect1width2[2];
    rect1yco2[3] = rect1yco2[0] + rect1height2[1];
    public void RegionThree(double X3, double Y3)
    String line[] = new String[4];
    /* try {
    URL url = new URL(
         "http://localhost:111/test/servlet/TestServlet1?name=THREE");
    BufferedReader in = new BufferedReader(
         new InputStreamReader(url.openStream()));
    for (int i = 0; i<4; i++)
    line[i] = in.readLine();
    in.close();
    catch (Exception e){
    e.printStackTrace();
    line[0] = "1200";
    line[1] = "2100";
    line[2] = "1200";
    line[3] = "2100";
    DC3[0] = Aa3 ;
    DC3[1] = Ba3 ;
    DC3[2] = Ca3;
    DC3[3] = Da3;
    Aa3 = s2d(line[0]);
    Ba3 = s2d(line[1]);
    Ca3 = s2d(line[2]);
    Da3 = s2d(line[3]);
    DF3[0] = Aa3 ;
    DF3[1] = Ba3;
    DF3[2] = Ca3;
    DF3[3] = Da3;
    rect1xco3[0] = 20;
    rect1yco3[0] = rect1yco[2]+rect1height[2];
    Sum3=Aa3+Ba3+Ca3+Da3;
    Ap[2] = (Aa3/Sum3)*100;
    Bp[2] = (Ba3/Sum3)*100;
    Cp[2] = (Ca3/Sum3)*100;
    Dp[2] = (Da3/Sum3)*100;
    A= (Ap[2]/100)*(X3*Y3);
    B= (Bp[2]/100)*(X3*Y3);
    C= (Cp[2]/100)*(X3*Y3);
    D= (Dp[2]/100)*(X3*Y3);
    Q = ((A*C)+(X3*Y3*D)+(X3*C*Y3)+(B*X3*Y3)-(Y3*A*X3)-((X3*X3)*(Y3*Y3))-(B*D))/((X3*(Y3*Y3))-(Y3*D)-(C*Y3));
    Z = (((X3*X3)*Y3*A)-(X3*C*A)-(B*X3*A))/((X3*(Y3*Y3))-(Y3*D)-(C*Y3));
    A1 =((-Q) + (Math.sqrt((Q*Q)-(4*P*Z))))/(2*P);
    A2=A/A1;
    B1=X3-A1;
    B2=B/B1;
    D2=Y3-A2;
    D1=D/D2;
    C1=X3-D1;
    C2=C/C1;
    rect1width3[0] = d2i(A1);
    rect1height3[0] = d2i(A2);
    rect1width3[1] = d2i(B1);
    rect1height3[1] = d2i(B2);
    rect1width3[2] = d2i(D1);
    rect1height3[2] = d2i(D2);
    rect1width3[3] = d2i(C1);
    rect1height3[3] = d2i(C2);
    rect1xco3[1] = rect1xco3[0] + rect1width3[0];
    rect1yco3[1] = rect1yco[3] + rect1height[3];
    rect1xco3[2] = rect1xco3[0];
    rect1yco3[2] = rect1yco3[0] + rect1height3[0];
    rect1xco3[3] = rect1xco3[0] + rect1width3[2];
    rect1yco3[3] = rect1yco3[0] + rect1height3[1];
    public void RegionFour(double X4, double Y4)
    String line[] = new String[4];
    /*try {
    URL url = new URL(
         "http://localhost:111/test/servlet/TestServlet1?name=FOUR");
    BufferedReader in = new BufferedReader(
         new InputStreamReader(url.openStream()));
    for (int i = 0; i<4; i++)
    line[i] = in.readLine();
    in.close();
    catch (Exception e){
    e.printStackTrace();
    line[0] = "1200";
    line[1] = "2100";
    line[2] = "1200";
    line[3] = "2100";
    DC4[0] = Aa4 ;
    DC4[1] = Ba4 ;
    DC4[2] = Ca4;
    DC4[3] = Da4;
    Aa4 = s2d(line[0]);
    Ba4 = s2d(line[1]);
    Ca4 = s2d(line[2]);
    Da4 = s2d(line[3]);
    DF4[0] = Aa4 ;
    DF4[1] = Ba4 ;
    DF4[2] = Ca4;
    DF4[3] = Da4;
    rect1xco4[0] = rect1xco3[1]+rect1width3[1];
    rect1yco4[0] = rect1yco2[2]+rect1height2[2];
    Sum4=Aa4+Ba4+Ca4+Da4;
    Ap[3] = (Aa4/Sum4)*100;
    Bp[3] = (Ba4/Sum4)*100;
    Cp[3] = (Ca4/Sum4)*100;
    Dp[3] = (Da4/Sum4)*100;
    A= (Ap[3]/100)*(X4*Y4);
    B= (Bp[3]/100)*(X4*Y4);
    C= (Cp[3]/100)*(X4*Y4);
    D= (Dp[3]/100)*(X4*Y4);
    Q = ((A*C)+(X4*Y4*D)+(X4*C*Y4)+(B*X4*Y4)-(Y4*A*X4)-((X4*X4)*(Y4*Y4))-(B*D))/((X4*(Y4*Y4))-(Y4*D)-(C*Y4));
    Z = (((X4*X4)*Y4*A)-(X4*C*A)-(B*X4*A))/((X4*(Y4*Y4))-(Y4*D)-(C*Y4));
    A1 =((-Q) + (Math.sqrt((Q*Q)-(4*P*Z))))/(2*P);
    A2=A/A1;
    B1=X4-A1;
    B2=B/B1;
    D2=Y4-A2;
    D1=D/D2;
    C1=X4-D1;
    C2=C/C1;
    rect1width4[0] = d2i(A1);
    rect1height4[0] = d2i(A2);
    rect1width4[1] = d2i(B1);
    rect1height4[1] = d2i(B2);
    rect1width4[2] = d2i(D1);
    rect1height4[2] = d2i(D2);
    rect1width4[3] = d2i(C1);
    rect1height4[3] = d2i(C2);
    rect1xco4[1] = rect1xco4[0] + rect1width4[0];
    rect1yco4[1] = rect1yco2[2]+rect1height2[2];
    rect1xco4[2] = rect1xco4[0];
    rect1yco4[2] = rect1yco4[0] + rect1height4[0];
    rect1xco4[3] = rect1xco4[0] + rect1width4[2];
    rect1yco4[3] = rect1yco4[0] + rect1height4[1];
    static int d2i(double d) {return (int) Math.round(d);}
    static double i2d(int i) {return (double) i;}
    static double s2d(String s)
    double i=0;
    try{  return i = Double.parseDouble(s);}
    catch(NumberFormatException e)
    {  e.printStackTrace();}
    return i;
    public void paintComponent(Graphics g) {
    super.paintComponent(g);
    int k11=d2i(k1);
    int k21=d2i(k2);
    int l11=d2i(l1);
    int l21=d2i(l2);
    int r11=d2i(r1);
    int r21=d2i(r2);
    int u11=d2i(u1);
    int u21=d2i(u2);
    g.setColor(Color.magenta);
    g.drawRect(rect1xco[0]-2,rect1yco[0]-2,k11+2,k21+2);
    g.drawRect(rect1xco[0]-1,rect1yco[0]-1,k11+2,k21+1);
    g.drawRect(rect1xco2[0]+1,rect1yco2[0]-1,l11+1,l21+1);
    g.drawRect(rect1xco2[0]+1,rect1yco2[0]-2,l11+2,l21+2);
    g.drawRect(rect1xco3[0]-1,rect1yco3[0]+1,r11+2,r21+1);
    g.drawRect(rect1xco3[0]-2,rect1yco3[0]+1,r11+2,r21+2);
    g.drawRect(rect1xco4[0]+1,rect1yco4[0]+1,u11+2,u21+1);
    g.drawRect(rect1xco4[0]+1,rect1yco4[0]+1,u11+1,u21+2);
    g.setColor(Color.cyan);
    g.drawRect(16,16,749,479);
    g.drawRect(17,17,747,477);
    if (rect1Active[0])
    // First Rectangle's coloring of the Region One
    if(DC1[0] == DF1[0])
    g.setColor(Color.black);
    g.fillRect(rect1xco[0]+2,rect1yco[0]+2,rect1width[0]-4,rect1height[0]-4);
    g.setColor(Color.yellow);
    g.drawRect(rect1xco[0],rect1yco[0],rect1width[0]-1,rect1height[0]-1);
    g.drawRect(rect1xco[0]+1,rect1yco[0]+1,rect1width[0]-3,rect1height[0]-3);
    else if(DC1[0] > DF1[0])
    g.setColor(Color.red);
    g.fillRect(rect1xco[0]+2,rect1yco[0]+2,rect1width[0]-4,rect1height[0]-4);
    g.setColor(Color.yellow);
    g.drawRect(rect1xco[0],rect1yco[0],rect1width[0]-1,rect1height[0]-1);
    g.drawRect(rect1xco[0]+1,rect1yco[0]+1,rect1width[0]-3,rect1height[0]-3);
    else if(DC1[0] < DF1[0])
    g.setColor(Color.green);
    g.fillRect(rect1xco[0]+2,rect1yco[0]+2,rect1width[0]-4,rect1height[0]-4);
    g.setColor(Color.yellow);
    g.drawRect(rect1xco[0],rect1yco[0],rect1width[0]-1,rect1height[0]-1);
    g.drawRect(rect1xco[0]+1,rect1yco[0]+1,rect1width[0]-3,rect1height[0]-3);
    else
    if(DC1[0] == DF1[0])
    g.setColor(Color.black);
    g.fillRect(rect1xco[0],rect1yco[0],rect1width[0],rect1height[0]);
    else if(DC1[0] > DF1[0])
    g.setColor(Color.red);
    g.fillRect(rect1xco[0],rect1yco[0],rect1width[0],rect1height[0]);
    else if(DC1[0] < DF1[0])
    g.setColor(Color.green);
    g.fillRect(rect1xco[0],rect1yco[0],rect1width[0],rect1height[0]);
    if (rect1Active[1])
    // Second Rectangle's coloring of the Region One
    if(DC1[1] == DF1[1])
    g.setColor(Color.black);
    g.fillRect(rect1xco[1]+2,rect1yco[1]+2,rect1width[1]-4,rect1height[1]-4);
    g.setColor(Color.yellow);
    g.drawRect(rect1xco[1],rect1yco[1],rect1width[1]-1,rect1height[1]-1);
    g.drawRect(rect1xco[1]+1,rect1yco[1]+1,rect1width[1]-3,rect1height[1]-3);
    else if(DC1[1] > DF1[1])
    g.setColor(Color.red);
    g.fillRect(rect1xco[1]+2,rect1yco[1]+2,rect1width[1]-4,rect1height[1]-4);
    g.setColor(Color.yellow);
    g.drawRect(rect1xco[1],rect1yco[1],rect1width[1]-1,rect1height[1]-1);
    g.drawRect(rect1xco[1]+1,rect1yco[1]+1,rect1width[1]-3,rect1height[1]-3);
    else if(DC1[1] < DF1[1])
    g.setColor(Color.green);
    g.fillRect(rect1xco[1]+2,rect1yco[1]+2,rect1width[1]-4,rect1height[1]-4);
    g.setColor(Color.yellow);
    g.drawRect(rect1xco[1],rect1yco[1],rect1width[1]-1,rect1height[1]-1);
    g.drawRect(rect1xco[1]+1,rect1yco[1]+1,rect1width[1]-3,rect1height[1]-3);
    else
    if(DC1[1] == DF1[1])
    g.setColor(Color.black);
    g.fillRect(rect1xco[1],rect1yco[1],rect1width[1],rect1height[1]);
    else if(DC1[1] > DF1[1])
    g.setColor(Color.red);
    g.fillRect(rect1xco[1],rect1yco[1],rect1width[1],rect1height[1]);
    else if(DC1[1] < DF1[1])
    g.setColor(Color.green);
    g.fillRect(rect1xco[1],rect1yco[1],rect1width[1],rect1height[1]);
    if (rect1Active [2])
    // Third Rectangle's coloring of the Region One
    if(DC1[2] == DF1[2])
    g.setColor(Color.black);
    g.fillRect(rect1xco[2]+2,rect1yco[2]+2,rect1width[2]-4,rect1height[2]-4);
    g.setColor(Color.yellow);
    g.drawRect(rect1xco[2],rect1yco[2],rect1width[2]-1,rect1height[2]-1);
    g.drawRect(rect1xco[2]+1,rect1yco[2]+1,rect1width[2]-3,rect1height[2]-3);
    else if(DC1[2] > DF1[2])
    g.setColor(Color.red);
    g.fillRect(rect1xco[2]+2,rect1yco[2]+2,rect1width[2]-4,rect1height[2]-4);
    g.setColor(Color.yellow);
    g.drawRect(rect1xco[2],rect1yco[2],rect1width[2]-1,rect1height[2]-1);
    g.drawRect(rect1xco[2]+1,rect1yco[2]+1,rect1width[2]-3,rect1height[2]-3);
    else if(DC1[2] < DF1[2])
    g.setColor(Color.green);
    g.fillRect(rect1xco[2]+2,rect1yco[2]+2,rect1width[2]-4,rect1height[2]-4);
    g.setColor(Color.yellow);
    g.drawRect(rect1xco[2],rect1yco[2],rect1width[2]-1,rect1height[2]-1);
    g.drawRect(rect1xco[2]+1,rect1yco[2]+1,rect1width[2]-3,rect1height[2]-3);
    else
    if(DC1[2] == DF1[2])
    g.setColor(Color.black);
    g.fillRect(rect1xco[2],rect1yco[2],rect1width[2],rect1height[2]);
    else if(DC1[2] > DF1[2])
    g.setColor(Color.red);
    g.fillRect(rect1xco[2],rect1yco[2],rect1width[2],rect1height[2]);
    else if(DC1[2] < DF1[2])
    g.setColor(Color.green);
    g.fillRect(rect1xco[2],rect1yco[2],rect1width[2],rect1height[2]);
    if (rect1Active [3])
    //Fourth Rectangle's coloring of the Region One
    if(DC1[3] == DF1[3])
    g.setColor(Color.black);
    g.fillRect(rect1xco[3]+2,rect1yco[3]+2,rect1width[3]-4,rect1height[3]-4);
    g.setColor(Color.yellow);
    g.drawRect(rect1xco[3],rect1yco[3],rect1width[3]-1,rect1height[3]-1);
    g.drawRect(rect1xco[3]+1,rect1yco[3]+1,rect1width[3]-3,rect1height[3]-3);
    else if(DC1[3] > DF1[3])
    g.setColor(Color.red);
    g.fillRect(rect1xco[3]+2,rect1yco[3]+2,rect1width[3]-4,rect1height[3]-4);
    g.setColor(Color.yellow);
    g.drawRect(rect1xco[3],rect1yco[3],rect1width[3]-1,rect1height[3]-1);
    g.drawRect(rect1xco[3]+1,rect1yco[3]+1,rect1width[3]-3,rect1height[3]-3);
    else if(DC1[3] < DF1[3])
    g.setColor(Color.green);
    g.fillRect(rect1xco[3]+2,rect1yco[3]+2,rect1width[3]-4,rect1height[3]-4);
    g.setColor(Color.yellow);
    g.drawRect(rect1xco[3],rect1yco[3],rect1width[3]-1,rect1height[3]-1);
    g.drawRect(rect1xco[3]+1,rect1yco[3]+1,rect1width[3]-3,rect1height[3]-3);
    else
    if(DC1[3] == DF1[3])
    g.setColor(Color.black);
    g.fillRect(rect1xco[3],rect1yco[3],rect1width[3],rect1height[3]);
    else if(DC1[3] > DF1[3])
    g.setColor(Color.red);
    g.fillRect(rect1xco[3],rect1yco[3],rect1width[3],rect1height[3]);
    else if(DC1[3] < DF1[3])
    g.setColor(Color.green);
    g.fillRect(rect1xco[3],rect1yco[3],rect1width[3],rect1height[3]);
    if (rect1Active2[0])
    // First Rectangle's coloring of the Region Two
    if(DC2[0] == DF2[0])
    g.setColor(Color.black);
    g.fillRect(rect1xco2[0]+4,rect1yco2[0]+2,rect1width2[0]-4,rect1height2[0]-4);
    g.setColor(Color.yellow);
    g.drawRect(rect1xco2[0]+2,rect1yco2[0],rect1width2[0]-1,rect1height2[0]-1);
    g.drawRect(rect1xco2[0]+3,rect1yco2[0]+1,rect1width2[0]-3,rect1height2[0]-3);
    else if(DC2[0] > DF2[0])
    g.setColor(Color.red);
    g.fillRect(rect1xco2[0]+4,rect1yco2[0]+2,rect1width2[0]-4,rect1height2[0]-4);
    g.setColor(Color.yellow);
    g.drawRect(rect1xco2[0]+2,rect1yco2[0],rect1width2[0]-1,rect1height2[0]-1);
    g.drawRect(rect1xco2[0]+3,rect1yco2[0]+1,rect1width2[0]-3,rect1height2[0]-3);
    else if(DC2[0] < DF2[0])
    g.setColor(Color.green);
    g.fillRect(rect1xco2[0]+4,rect1yco2[0]+2,rect1width2[0]-4,rect1height2[0]-4);
    g.setColor(Color.yellow);
    g.drawRect(rect1xco2[0]+2,rect1yco2[0],rect1width2[0]-1,rect1height2[0]-1);
    g.drawRect(rect1xco2[0]+3,rect1yco2[0]+1,rect1width2[0]-3,rect1height2[0]-3);
    else
    if(DC2[0] == DF2[0])
    g.setColor(Color.black);
    g.fillRect(rect1xco2[0]+2,rect1yco2[0],rect1width2[0],rect1height2[0]);
    else if(DC2[0] > DF2[0])
    g.setColor(Color.red);
    g.fillRect(rect1xco2[0]+2,rect1yco2[0],rect1width2[0],rect1height2[0]);
    else if(DC2[0] < DF2[0])
    g.setColor(Color.green);
    g.fillRect(rect1xco2[0]+2,rect1yco2[0],rect1width2[0],rect1height2[0]);
    if (rect1Active2[1])
    // Second Rectangle's coloring of the Region Two
    if(DC2[1] == DF2[1])
    g.setColor(Color.black);
    g.fillRect(rect1xco2[1]+4,rect1yco2[1]+2,rect1width2[1]-4,rect1height2[1]-4);
    g.setColor(Color.yellow);
    g.drawRect(rect1xco2[1]+2,rect1yco2[1],rect1width2[1]-1,rect1height2[1]-1);
    g.drawRect(rect1xco2[1]+3,rect1yco2[1]+1,rect1width2[1]-3,rect1height2[1]-3);

    Could you show me how to use it as an applet. If you
    can modify my code and make it working it would be
    very helpful.
    Best regards
    AliPerhaps you could start [url http://java.sun.com/docs/codeconv/html/CodeConvTOC.doc.html]here[url                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • How to invoke a window using JNI?

    Hello,
    I need to invoke a C++ DLL from a Java Applet using JNI. The DLL should display an image in a separate window. Further I should be able to set the position of the DLL window, and should be able to minimize, maximize the DLL window from the Applet.
    Well I am fairly new to C++. Any suggestions regarding how I should proceed?
    GLim

    Hi jschell,
    Thanks for the reply.
    But I am sorry that I am not sure whether I understood your point. What I understood is I make an exe that displays the image and run it from Java like SHELL function in VB. In that case can I specify a particular image to be loaded from the applet? The applet and exe needs to be constant touch as the location , size etc of the window displaying the image could be controlled by the applet.
    I have created a DLL which displays the specified the image in a modeless dialog box. I have succeded in invoking the DLL from applet. But the dll window hangs as soon as it loads! I got a suggestion to implement the display of modeless dialog box inside thread. Now I am investigating how to implement thread :) Please send in your advice if you have any?
    Also it could be real help if you could mentions common problems that might occur in such situations.
    Thanks in advance
    gLim

  • JNI - How to use the error reporting mechanism?

    I've developed a C++ DLL which is loaded from a commercial Win32 application (not written by me) as a plug-in for external calculations. On its initialization the C++ DLL launches the Java VM via the JNI invocation interface. When the DLL functions are called by the application, they forward the calls to Java objects inside the Java VM, again via JNI invocation interface.
    This works well, but I have encountered a weird error.
    From Java I open a JFrame containing a JTextArea as small console for debug output messages. If I turn output to this debug console off (my printToConsole routine checks whether a boolean flag is set), the string concatenation operator may lead to a crash of the Java VM.
    For example, if in one of the Java functions called from the
    DLL via JNI invocation interface the following is the first statement,
    it leads to a crash of the Java VM and the application that loaded the C++ proxy DLL.
    String test=""+Math.random(); // String test not used later
    Interestingly, if I comment this statement out, the Java code works fine WITHOUT any crash. I've already thought about potential races and synchronization issues in my code, but I don't see where this is the case. And the string concatenation error fails as well, if I insert sleep() statements in front of it and at other places in the code. However, if I turn on log messages printed to my JFrame debug console (containing a JTextArea), the String concatenation works without problems.
    So maybe the JNI interface has a bug and affects the Java VM; I don't see where my JNI code is wrong.
    One problem is that I do not get any stdout output, as the C++ proxy DLL is loaded by the Windows application, even if I start the Windows application from the DOS command line (under Windows).
    Does anyone know how to use the error reporting mechanism?
    http://java.sun.com/j2se/1.4.2/docs/guide/vm/error-handling.html
    Is it possible that the JVM, when it crashes, writes debug information about the crash into a file instead of stdout/stderr?
    My C++ proxy DLL was compiled in debug mode, but the commercial application (which loaded the DLL) is very likely not.
    I do not know hot to find the reason why the String concatenation fails inside the Java function called from the C++ DLL via JNI.

    Yes, I've initially thought about errors in the C++ code too. But the C++ code is actually very simple and short. It doesn't allocate anything on the C++ side. It allocates a couple of ByteBuffers inside the Java VM however via JNI invocation interface calls of env->NewDirectByteBuffer(). The native memory regions accessed via the ByteBuffers are allocated not by my own C++ code, but by the program that calls my DLL (the program is Metastock).
    The interesting thing is that everything works fine if output to my debug console is enabled, which means that in the Java print routine getConsoleLoggingState() returns true and text is appended to the jTextArea.
    static synchronized void print(String str)
    { MetaStockMonitor mMon=getInstance();
    if ( mMon.getFileLoggingState() && mMon.logFileWriter!=null) {
    mMon.logFileWriter.print(str);
    mMon.logFileWriter.flush();
    if ( mMon.getConsoleLoggingState() ) {
    mMon.jTextArea1.append(str);
    Only if output to the JTextArea is turned off (ie. getConsoleLoggingState()==false), the crash happens when the FIRST statement in the Java routine called via JNI invocation interface is a (useless) String concatenation operation, as described above.
    String test=""+Math.random(); // String test not used later
    Moreover, the crash happens BEFORE the allocated ByteBuffer objects are accessed in the Java code. But again, if console output is turned on, it works stable. If console output is turned off, it works when the (useless) String concatenation operation is removed in the Java routine called from C++.
    I've already thought about potential races (regarding multiple threads), but this can be ruled out in my case. It almost appears as if the JVM can have problems when called by the invocation interface (I tested it with Java 1.4.2 b28).
    All the calls between C++ and Java go ALWAYS in the direction from C++ code to Java. Unfortunately, there is no special JRE version with extensive logging capabilities to facilitate debugging. And the problem is not easily reproducible either.
    JNIEnv* JNI_GetEnv()
    JNIEnv *env;
    cached_jvm->AttachCurrentThread((void**)&env,NULL);
    fprintf(logfile,"env=%i\n",env);
    fflush(logfile);
    return env;
    // function called by Metastock's MSX plug-in interface
    BOOL __stdcall createIndEngine (const MSXDataRec *a_psDataRec,
    const MSXDataInfoRecArgsArray *a_psDataInfoArgs,
    const MSXNumericArgsArray *a_psNumericArgs,
    const MSXStringArgsArray *a_psStringArgs,
    const MSXCustomArgsArray *a_psCustomArgs,
    MSXResultRec *a_psResultRec)
    a_psResultRec->psResultArray->iFirstValid=0;
    a_psResultRec->psResultArray->iLastValid=-1;
    jthrowable ex;
    jmethodID mid;
    JNIEnv* env=JNI_GetEnv();
    jobject chart=getChart(env, a_psDataRec);
    if ( chart==NULL) {
    return MSX_ERROR;
    jobject getChart (JNIEnv* env, const MSXDataRec *a_psDataRec)
    jthrowable ex;
    jmethodID mid;
    int closeFirstValid, closeLastValid;
    closeFirstValid=a_psDataRec->sClose.iFirstValid;
    closeLastValid=a_psDataRec->sClose.iLastValid;
    long firstDate, firstTime;
    if (closeFirstValid>=1 && closeFirstValid<=closeLastValid) {
    firstDate = a_psDataRec->psDate[closeFirstValid].lDate;
    firstTime = a_psDataRec->psDate[closeFirstValid].lTime;
    } else {
    firstDate=0;
    firstTime=0;
    jclass chartFactoryClass = env->FindClass("wschwendt/metastock/msx/ChartFactory");
    if (ex= env->ExceptionOccurred() ) {
    env->ExceptionDescribe();
    env->ExceptionClear();
    sprintf(sbuf, "DLL: Cannot find class ChartFactory\n");
    printSBufViaJava(sbuf);
    return NULL;
    mid = env->GetStaticMethodID(chartFactoryClass, "getInstance", "()Lwschwendt/metastock/msx/ChartFactory;");
    if (ex= env->ExceptionOccurred() ) {
    env->ExceptionDescribe();
    env->ExceptionClear();
    sprintf(sbuf, "DLL: Cannot find method ID for ChartFactory.getInstance()\n");
    printSBufViaJava(sbuf);
    return NULL;
    jobject chartFactory=env->CallStaticObjectMethod(chartFactoryClass, mid);
    if (ex= env->ExceptionOccurred() ) {
    env->ExceptionDescribe();
    env->ExceptionClear();
    sprintf(sbuf, "DLL: Exception while calling ChartFactory.getInstance()");
    printSBufViaJava(sbuf);
    return NULL;
    mid = env->GetMethodID(chartFactoryClass, "getChartID", "(Ljava/nio/ByteBuffer;Ljava/nio/ByteBuffer;Ljava/nio/ByteBuffer;Ljava/nio/ByteBuffer;IIIIIII)F");
    if (ex= env->ExceptionOccurred() ) {
    env->ExceptionDescribe();
    env->ExceptionClear();
    sprintf(sbuf, "DLL: Cannot find method ID for ChartFactory.getChartID()\n");
    printSBufViaJava(sbuf);
    return NULL;
    jobject symbolBuf=env->NewDirectByteBuffer(a_psDataRec->pszSymbol, strlen(a_psDataRec->pszSymbol) );
    if (ex= env->ExceptionOccurred() ) {
    env->ExceptionDescribe();
    env->ExceptionClear();
    sprintf(sbuf, "DLL: Cannot allocate symbolBuf\n");
    printSBufViaJava(sbuf);
    return NULL;
    jobject securityNameBuf=env->NewDirectByteBuffer(a_psDataRec->pszSecurityName, strlen(a_psDataRec->pszSecurityName) );
    if (ex= env->ExceptionOccurred() ) {
    env->ExceptionDescribe();
    env->ExceptionClear();
    sprintf(sbuf, "DLL: Cannot allocate securityNameBuf\n");
    printSBufViaJava(sbuf);
    return NULL;
    jobject securityPathBuf=env->NewDirectByteBuffer(a_psDataRec->pszSecurityPath, strlen(a_psDataRec->pszSecurityPath) );
    if (ex= env->ExceptionOccurred() ) {
    env->ExceptionDescribe();
    env->ExceptionClear();
    sprintf(sbuf, "DLL: Cannot allocate securityPathBuf\n");
    printSBufViaJava(sbuf);
    return NULL;
    jobject securityOnlineSourceBuf=env->NewDirectByteBuffer(a_psDataRec->pszOnlineSource, strlen(a_psDataRec->pszOnlineSource) );
    if (ex= env->ExceptionOccurred() ) {
    env->ExceptionDescribe();
    env->ExceptionClear();
    sprintf(sbuf, "DLL: Cannot allocate onlineSourceBuf\n");
    printSBufViaJava(sbuf);
    return NULL;
    // Java Function call leads to crash, if console output is turned off and
    // the first statement in the Java routine is a (useless) string concatenation.
    // Otherwise it works stable.
    jfloat chartID=env->CallFloatMethod(chartFactory, mid, securityNameBuf, symbolBuf,
    securityPathBuf, securityOnlineSourceBuf, (jint)(a_psDataRec->iPeriod),
    (jint)(a_psDataRec->iInterval), (jint)(a_psDataRec->iStartTime),
    (jint)(a_psDataRec->iEndTime), (jint)(a_psDataRec->iSymbolType),
    (jint)firstDate, (jint)firstTime );
    if (ex= env->ExceptionOccurred() ) {
    env->ExceptionDescribe();
    env->ExceptionClear();
    sprintf(sbuf, "DLL: Exception while calling ChartFactory.getChartID()");
    printSBufViaJava(sbuf);
    return NULL;

Maybe you are looking for

  • HTML online editor and accented letter

    Hi all gurus, please forgive the nooby question, I'm a newbie about Portal and I've searched sdn forum without success for the following task. Strictly; I have to publish an HTML file in an iview of the Portal. This task was accomplished quite easily

  • Please help me with my mac. when i turned it on, a small question mark icon (?) appears at the center.

    hi, Please help me out with my MAC model m6497. when i turned it on, only a smallquestion mark appears at the center and does not proceed to its descktop at all

  • What's new in version 7?

    Version 7 is less an overhaul of version 4 than it is a refinement of it. The interface itself is virtually unchanged, although its task-directed system of tabs and buttons is even more intuitive. Themes, title templates and DVD and BluRay templates

  • I want my Mountain Lion wallpaper...

    Snow Leopard.... I had a Snow Leopard Lion... Yes, I had a lion... Mountain Lion, I have a galaxy thing.. or a choice of 30 other crappy pics or the snow leopard or lion I used to have. Yes I can google mountain lion pics and throw one on my screen b

  • Problem while loading metadata in IDX2

    Hi I tried to load metadata in IDX2 .I passed the parameters IDOC TYPE and SOURCE PORT .when i asked to continue it is showing me the that " <b>No RFC destination is maintained for the port</b> ". When I checked that particular port in IDX1 I am able