Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4145476

Can't find SimplePanelTest class

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.2.0
    • hotspot
    • sparc
    • solaris_2.5.1



      Name: rm29839 Date: 06/03/98


      My source files:
      :::::::::::::
      invoke.c
      :::::::::::::
      #include <jni.h>
      CallJVM() {
      JNIEnv *env;
      JavaVM *jvm;
      jint res;
      jclass cls;
      jmethodID mid;
      jstring jstr;
      jobjectArray args;

      JavaVMOption options[1];
      JavaVMInitArgs vm_args;

      /* Set up the options */
      options[0].name = "classpath";
      options[0].value.p = "/dkise1/oggioni/EXAMPLES/AWTONLY:/dkise3/JAVA/JDK12BETA3/jdk1.2beta3/lib/classes.zip";
      vm_args.version = 0x00010002;
      vm_args.options = options;
      vm_args.nOptions = 1;
      vm_args.result = NULL;
      /* Set the vm_args members as required, eg: classpath
      verifyMode, maxHeapSize, etc. */

      res = JNI_CreateJavaVM(&jvm, &env, &vm_args);
      if (res < 0) {
      fprintf(stderr, "Can't create Java VM\n");
      exit(1);
      }

      cls = (*env)->FindClass(env, "SimplePanelTest");
      printf("Dopo la find class \n");
      if (cls == 0) {
      fprintf(stderr, "Can't find SimplePanelTest class\n");
      exit(1);
      }
       
      mid = (*env)->GetStaticMethodID(env, cls, "CreateFirstFrame", "([Ljava/lang/String;)V");
      if (mid == 0) {
      fprintf(stderr, "Can't find SimplePanelTest.CreateFirstFrame\n");
      exit(1);
      }

      jstr = (*env)->NewStringUTF(env, "First Daisy panel");
      if (jstr == 0) {
      fprintf(stderr, "Out of memory\n");
      exit(1);
      }
      args = (*env)->NewObjectArray(env, 1, (*env)->FindClass(env, "java/lang/String"), jstr);
      if (args == 0) {
      fprintf(stderr, "Out of memory\n");
      exit(1);
      }
      (*env)->CallStaticVoidMethod(env, cls, mid, args);
      (*jvm)->DestroyJavaVM(jvm);
      }
      main() { CallJVM(); }
      :::::::::::::
      SimplePanelTest.java
      :::::::::::::
      import java.awt.*;
      import java.awt.event.*;
      import java.util.Vector;

      // Subclass Frame so you can display a window
      public class SimplePanelTest extends Frame {

      // Set up constants for width and height of frame
      static final int WIDTH = 600;
      static final int HEIGHT = 400;

      private native Void CreateNativeButt(String Title);
      private native Void CreateNativeText(String Init);
      private native Void CreateNativeLabel(String Lab);

      static {
      System.loadLibrary("oggettini");
      }

      // CONSTRUCTOR
      SimplePanelTest(String title) {

      // Set the title of the frame
      super(title);

                      // Lay out the components.
      // GridBagLayout gbl = new GridBagLayout();
      // setLayout(gbl);

      GridBagLayout gbl = new GridBagLayout();
      GridBagConstraints gbc = new GridBagConstraints();
                      gbc.fill = GridBagConstraints.VERTICAL;

                      setLayout(new GridBagLayout());
      CreateNativeLabel("Prima Label");
      CreateNativeText("Primotext");

      CreateNativeButt("Primobottone");
      CreateNativeText("Secondotext");

      CreateNativeButt("Secondobottone");
      CreateNativeButt("Terzobottone");
      }
      // CreateFirstFrame to execute the application
      public static void CreateFirstFrame(String args[]) {

      // instantiate a SimplePanelTest object
      // so you can display it
      Frame frame = new SimplePanelTest(args[0]);
      frame.setSize(WIDTH, HEIGHT);
      // frame.setResizable(false);
      // Create a WindowAdapter so the application
      // is exited when the window is closed.
      frame.addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent e) {
      System.exit(0);
      }
      });

      // Set the size of the frame and show it
      frame.setVisible(true);
      }
              public void CreateButt(Frame currentOne, String Title) {

      GridBagLayout gbl = new GridBagLayout();
      GridBagConstraints gbc = new GridBagConstraints();

                      Panel p1 = new Panel();
                      p1.setLayout(new GridLayout(2,1));

                      p1.add(new Button(Title));
                      gbc.gridwidth = GridBagConstraints.REMAINDER;
                      gbl.setConstraints ( p1, gbc );

                      p1.add(new Button(Title));
                      gbc.gridwidth = GridBagConstraints.RELATIVE;
                      gbl.setConstraints ( p1, gbc );

                      currentOne.add(p1);
      setLayout(gbl);
              }
              public void CreateText(Frame currentOne, String Init) {
      GridBagLayout gbl = new GridBagLayout();
      GridBagConstraints gbc = new GridBagConstraints();

                      Panel p1 = new Panel();
                      p1.setLayout(new GridLayout(2,1));

                      p1.add(new TextField(Init, 20));
                      gbc.gridwidth = GridBagConstraints.REMAINDER;
                      gbl.setConstraints ( p1, gbc );

                      p1.add(new TextField(Init, 20));
                      gbc.gridwidth = GridBagConstraints.RELATIVE;
                      gbl.setConstraints ( p1, gbc );

                      currentOne.add(p1);
      setLayout(gbl);

              }

              public void CreateLabel(Frame currentOne, String Lab) {

      GridBagLayout gbl = new GridBagLayout();
      GridBagConstraints gbc = new GridBagConstraints();

                      Panel p1 = new Panel();
                      p1.setLayout(new GridLayout(2,1));

                      p1.add(new Label("Prima :", Label.RIGHT));
                      gbc.gridwidth = GridBagConstraints.REMAINDER;
                      gbl.setConstraints ( p1, gbc );

                      p1.add(new Label("Seconda :", Label.RIGHT));
                      gbc.gridwidth = GridBagConstraints.RELATIVE;
                      gbl.setConstraints ( p1, gbc );

                      currentOne.add(p1);
      setLayout(gbl);

              }
      }
      :::::::::::::
      ritorna.c
      :::::::::::::
      #include <oobj.h>
      #include <jni.h>
      #include <stdio.h>
      #include "SimplePanelTest.h"
      JNIEXPORT jobject JNICALL Java_SimplePanelTest_CreateNativeButt
        (JNIEnv *env, jobject obj, jstring ButtonLabel)
      {
      jclass cls = (*env)->GetObjectClass(env, obj);
      jmethodID mid = (*env)->GetMethodID(env, cls, "CreateButt", "(Ljava/awt/Frame;Ljava/lang/String;)V");
      if (mid == 0) {
      printf("Mid=0 in CreateNativeButt\n");
      return;
      }
      (*env)->CallVoidMethod(env, obj, mid, obj, ButtonLabel);
      }
      JNIEXPORT jobject JNICALL Java_SimplePanelTest_CreateNativeText
        (JNIEnv *env, jobject obj, jstring InitText)
      {
      jclass cls = (*env)->GetObjectClass(env, obj);
      jmethodID mid = (*env)->GetMethodID(env, cls, "CreateText", "(Ljava/awt/Frame;Ljava/lang/String;)V");
      if (mid == 0) {
      printf("Mid=0 in CreateNativeText\n");
      return;
      }
      (*env)->CallVoidMethod(env, obj, mid, obj, InitText);
      }
      JNIEXPORT jobject JNICALL Java_SimplePanelTest_CreateNativeLabel
        (JNIEnv *env, jobject obj, jstring Lab)
      {
      jclass cls = (*env)->GetObjectClass(env, obj);
      jmethodID mid = (*env)->GetMethodID(env, cls, "CreateLabel", "(Ljava/awt/Frame;Ljava/lang/String;)V");
      if (mid == 0) {
      printf("Mid=0 in CreateNativeLabel\n");
      return;
      }
      (*env)->CallVoidMethod(env, obj, mid, obj, Lab);
      }

      I compile my file with this instruction:
      export JAVAPATH=/dkise3/JAVA/JDK12BETA3/jdk1.2beta3
      javac -classpath .:$JAVAPATH/lib/classes.zip SimplePanelTest.java
      javah -jni -classpath .:$JAVAPATH/lib/classes.zip SimplePanelTest
      cc -g -I $JAVAPATH/include -I $JAVAPATH/include/solaris -ljvm invoke.c
      cc -g -G -I $JAVAPATH/include-old -I $JAVAPATH/include-old/solaris -I $JAVAPATH/include -I $JAVAPATH/include/solaris ritorna.c -o liboggettini.so

      but when I exec the a.out file it try to load classes
      from directory /dkise3/JAVA/JDK12BETA3/jdk1.2beta3/classes
      while my classes are in my directory /dkise1/oggioni/EXAMPLES/AWTONLY,
      if I put my classes in the directory /dkise3/JAVA/JDK12BETA3/jdk1.2beta3/classes
      the program function but this is not what I want !!!

      My Operating System is Solaris 2.5.1
      (Review ID: 28052)
      ======================================================================

            sliangsunw Sheng Liang (Inactive)
            rmandelsunw Ronan Mandel (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: