Invocation API: JFrame opens and closes immediatly when invoced.

Hello,
I'm sitting with an existing software, to which I would like to create a Java GUI to present calculation results in a nice way (simple editing, saving in different formats, etc.). The core is Fortran 77 and 90.
Right now I'm trying to figure out how JNI works, and I have been able to make some C code show a Jframe. However, the JFrame disappears immediately if I don't make the runningThread.sleep() for some time, and I can't seem to find any GUI sample code. If I run it in NetBeans it stays open until I click the X.
In the end I would like the GUI to be started from Fortran 90 when a user gives the plot command in the application console.
In addition to the above problem, I would like a push in the right direction. What should I think about with this approach? Any common traps?
This is how the test looks:
Java code generated by NetBeans, where I just want to display a JFrame.
public class JFrame extends javax.swing.JFrame {
    public JFrame() {
        initComponents();
    @SuppressWarnings("unchecked")
    private void initComponents() {
        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("JFrameInvoced");
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        pack();
    @SuppressWarnings("static-access")
    public static void main(String args[]) throws InterruptedException {
        JFrame frameTest = new JFrame();
        frameTest.setVisible(true);
        Thread runningNow = Thread.currentThread();
        runningNow.sleep(1000);
}C code from internet.
#include <stdio.h>
#include <jni.h>
JNIEnv* create_vm() {
     JavaVM* jvm;
     JNIEnv* env;
     JavaVMInitArgs args;
     JavaVMOption options[1];
     int ret;
     /* There is a new JNI_VERSION_1_4, but it doesn't add anything for the purposes of our example. */
     args.version = JNI_VERSION_1_4;
     args.nOptions = 1;
     options[0].optionString = "-Djava.class.path=D:\\Source\\Invocation_test";
     args.options = options;
     args.ignoreUnrecognized = JNI_FALSE;
     ret = JNI_CreateJavaVM(&jvm, (void **)&env, &args);
     return env;
void invoke_class(JNIEnv* env) {
     jclass helloWorldClass;
     jmethodID mainMethod;
     jobjectArray applicationArgs;
     jstring applicationArg0;
     //helloWorldClass = (*env)->FindClass(env, "InvocationHelloWorld");
     helloWorldClass = (*env)->FindClass(env, "JFrame");
     mainMethod = (*env)->GetStaticMethodID(env, helloWorldClass, "main", "([Ljava/lang/String;)V");
     applicationArgs = (*env)->NewObjectArray(env, 1, (*env)->FindClass(env, "java/lang/String"), NULL);
     applicationArg0 = (*env)->NewStringUTF(env, "From-C-program");
     (*env)->SetObjectArrayElement(env, applicationArgs, 0, applicationArg0);
     (*env)->CallStaticVoidMethod(env, helloWorldClass, mainMethod, applicationArgs);
int main(int argc, char **argv) {
     JNIEnv* env = create_vm();
     invoke_class( env );
}

sammen wrote:
Can multithreading be a possible solution to this?Multithreading is certainly involved when you create a GUI using SWING, as SWING automatically creates a thread where all drawing and event handling is performed. Calculations and other longer tasks are performed outside that thread. This is done to avoid blocking the GUI during calculations.
But first focus on the interface between the C program, where the calculations are performed, and the Java program, where the GUI should be located. Possible questions you should ask yourself are:
- What data must be sent from the C part to the GUI?
- What actions do I want to trigger from the C part, e.g. "create a plot"?
- What actions do I want to trigger from the GUI to the C part, e.g. "redo calculations"?
Then you could design the interface between those two. The multithreading performed by SWING has to be considered especially for the third question, as event handlers like "actionPerformed" are called from the SWING thread and should return quickly, just triggering the action, but not performing it. But those things are better discussed in the SWING forum.
Martin

Similar Messages

  • TS2771 After updating my software my apps open and close immediately when selected

    After updating my ipod software my apps open and close immediately when selected.

    See:
    iOS: Troubleshooting applications purchased from the App Store
    Restore from backup. See:
    iOS: How to back up
    Restore to factory settings/new iPod

  • IE 11 opens and closes immediatly

    Brand new windows 7 pro pc. IE 11 opens and closes immediately. I tried all fixes already posted. If i remove ie 11 from the programs in control panel it disappears. But if i try to re-install from MSFT download ie 10 or ie 11 i receive a message that a
    new version is already installed even though no ie shows being installed, If i go back and recheck IE 11 in programs in control panel it re-installs the same IE 11 and has the same error, opens and closes immeditaly. I have also rolled back to system restore,
    same error.  FYI Chrome is installed and works fine but client needs IE for certain integration with cloud.
    thanks 

    Hi,
    I just make a supplement, if you do need to revert IE 11 to a lower edition, you need to uninstall IE 11 in Windows Update history.
    Control Panel->View installed updates.
    Find IE 11 and uninstall it, after that, restart your computer.
    Roger Lu
    TechNet Community Support

  • Ibooks open and close immediatly on ipad, Ibooks open and close immediatly on ipad, Ibooks open and close immediatly on ipad

    All in the tittle
    Ni error message : it opens then immediatly close
    iPad

    Have you tried closing the iBooks app completely and seeing if it works when you re-open it ? From the home screen (i.e. not with iBooks 'open' on-screen) double-click the home button to bring up the taskbar, then press and hold any of the apps on the taskbar for a couple of seconds or so until they start shaking, then press the '-' in the top left of the iBooks app to close it, and touch any part of the screen above the taskbar so as to stop the shaking and close the taskbar.
    If that doesn't work then you could try a reset : press and hold both the sleep and home buttons for about 10 to 15 seconds (ignore the red slider), after which the Apple logo should appear - you won't lose any content, it's the iPad equivalent of a reboot.
    A third option is to delete the app and re-download it - in which case you may want to copy all your books/PDFs to your computer's iTunes first (File > Transfer Purchases).

  • Adobe reader won't open and closes internet when trying to open a pdf

    I'm not sure when it started, but for the last 2 weeks every time I try to open a pdf file on the internet it stops and says "internet Explorer has stopped working" and will then close the window.  I thought it was just a cable (internet connection) problem since we had been having issues in that area, but now that's fixed and I still cannot open a pdf on the internet.  I uninstallled and restarted and re-installled Adobe Reader and I can't even open Adobe Reader much less a pdf from the internet.  Please help!  I've also tried installing Safari and it has the same results.  I'm sure it has to do with my Reader, but I just don't know how to fix it.

    I finally uninstalled Adobe Reader and found a free pdf reader program.  At least now I can save the file I want to look at and can
    open it with the other program.  Thanks for all your suggestions and help.  I learned a lot of new things.  Sorry Adobe... your loss

  • HT5100 Itunes u just opens and closes immediately when I try to use it. It worked previously, and now it doesn't.  I tried uninstalling it and then installing it again and it still closes as soon as I open it. Other apps do not do this. What should I do?

    iTunes u closes as soon as I open it. What should I do?

    I would start with this FAQ Entry first, if you have not done so yet: http://forums.adobe.com/thread/792580?tstart=0
    It starts with a checklist for getting PrE set up properly, then moves into tuning up one's system and OS (you have done a lot of that already), and then goes into troubleshooting tips. Note: those tips rather work up quickly in "degree of difficulty," and DO become quite technical, but things like the "Finding Clues" link will give some tools, that might prove useful, like the use of Windows' Event Viewer to track down issues.
    One of the first things to look at would be your video driver. I would go to the video card's/chip's mfgr's. Web site, and check for a later driver. Do not trust Windows, or any utility to tell you if you have the latest driver. If there is not a newer video driver, or it will not install properly on your system, be sure to check with the HP Web site, as HP, Dell, Lenovo, and some other mfgrs. will re-package video drivers to suit their specific setup.
    One troubleshooting technique, that might prove useful (however, those deleted programs bother me a bit here), would be to create a System Restore Point for now (see Windows Help for doing this with your particular OS version). Then, boot to Safe Mode, and choose an older System Restore Point, from when things did work. This might take some trial-and-error, to get back far enough. Test. At the worst, you will only have lost a few minutes, as you have your new System Restore Point for now, to fall back on.
    Good luck,
    Hunt

  • When iphone lock i'm want to use slide open and close camera

    1. When iphone lock i'm want to use slide open and close camera
    2. When i'm turn on wifi via control center i'm need to keep it show popup in order to select join wifi the other

    Autthapol saiyat wrote:
    1. When iphone lock i'm want to use slide open and close camera
    When the phone is locked, you can pull up on the camera icon in the lower right of the screen to access the camera. If you have Control Center enabled in the lock screen, you can also access the camera that way. 

  • Apps open and close

    hello
    i have a iphone 4. My apps open and close immediatly. I can't use them.
    What can I do ?
    thanks for your help
    Chris

    Hey Chris,
    It just happened to me. If all the brought apps are closing immediately (and excluding the built in ones) then try either:
    1. Restart your phone.
    2. Hold the home button for the task bar and hold the app for a few seconds until they jiggle and a red cicle with a line in it shows up. Touch each one (this is just deleting them and "refreshing them", you aren't really deleting the app).
    3. Go to the App store and buy a free app, any, and install it. Try opening one of your apps now. This worked for me. If it works, you can go ahead and delete the free app.
    4. If all fails...restore your phone.
    Good luck!

  • ALL of my 3rd party apps open and close immediately

    after connecting to itunes after a few months now ALL of my 3rd party apps open and close immidiately when i try to open them

    First try a hard reset.  To do this, press and hold both the Sleep/Wake and Home buttons together long enough for the Apple logo to appear.  If that doesn't help, try downloading a new App free app from the app store to see if that helps.
    B-rock

  • Since installing LTR 5.4, which I've now upgraded to 5.6, I've encountered repeated slowness and malfunctions in operations, especially when using the Compare View function and the Tab key to open and close the right and left side panels.  Such problems n

    Since installing LTR 5.4, which I've now upgraded to 5.6, I've encountered repeated slowness and malfunctions in operations, especially when using the Compare View function and the Tab key to open and close the right and left side panels.  Such problems never arose during two years of using LTR-4 and nothing else has changed on my computer.  I have a pretty simple system with only a few plug-ins, which are usually not in operation.  I have 12GB of RAM in my Windows 7 PC.  I could illustrate these problems with screen shots if you would tell me how to submit screen shots.  Otherwise I will try to describe the problems in words.
    The problem is clearly cumulative, growing worse as usage time passes.  Compare View feature gradually slows down and eventually seems to choke as my work session proceeds. If I Exit LTR and re-enter and start all over, things will work normally for maybe 30 minutes, but then the Compare View feature begins to become very slow to respond.   In a recent example with my screen full of thumbnails in Library mode I highlighted two images to compare. LTR started to open the Compare View screen by first having the top row of thumbnails disappear to be replaced by the "SELECT" and "CANDIDATE" words in their spaces  (but no images), but Compare View never succeeded in gaining control of the screen. After some seconds the top row of thumbnails reasserted its position and the Compare View windows disappeared. But LTR kept trying to bring them back. Again the top row of thumbnails would go away, Select and candidate would reappear, try again, and give up. This went on for at least 2-3 minutes before I tried to choose File and Exit, but even that did not initially want to respond. It doesn't like to accept other commands when it's trying to open Compare View. Finally it allowed me to exit.
    To experiment I created a new catalog of 1100 images.  After 30-40 minutes, the Compare View function began to operate very slowly. With left and right side panels visible and two thumbnails highlighted, hitting Compare View can take half a minute before the two mid-size  images open in their respective SELECT and CANDIDATE windows. When the side panels are open and two images are in the Select/Candidate spaces, hitting the Tab button to close the side panels produces a very delayed response--25-30 seconds to close them, a few more seconds to enlarge the two images to full size. To reverse the process (i.e., to recall the two side panels), hitting Tab would make the two sides of the screen go black for up to a minute, with no words visible. Eventually the info fields in the panels would open up.
    I also created a new user account and imported a folder of 160 images. After half an hour Compare View began mis-placing data.  (I have a screen shot to show this.)  CANDIDATE appears on the left side of SELECT, whereas it should be on the right. The accompanying camera exposure data appears almost entirely to the left of the mid-screen dividing line. Although the Candidate and Select headings were transposed, the image exposure data was not, but the data for the image on the right was almost entirely to the left of the line dividing the screen in two.
    Gurus in The Lightroom Forum have examined Task Manager data showing Processes running and Performance indicators and they see nothing wrong.  I could also send screen shots of this data.
    At this point, the only way I can process my images is to work 30-40 minutes and then shut down everything, exit, and re-start LTR.  This is not normal.  I hope you can find the cause, and then the solution.  If you would like to see my screen shots, tell me how to submit them.
    Ollie
    [email protected]

    Since installing LTR 5.4, which I've now upgraded to 5.6, I've encountered repeated slowness and malfunctions in operations, especially when using the Compare View function and the Tab key to open and close the right and left side panels.  Such problems never arose during two years of using LTR-4 and nothing else has changed on my computer.  I have a pretty simple system with only a few plug-ins, which are usually not in operation.  I have 12GB of RAM in my Windows 7 PC.  I could illustrate these problems with screen shots if you would tell me how to submit screen shots.  Otherwise I will try to describe the problems in words.
    The problem is clearly cumulative, growing worse as usage time passes.  Compare View feature gradually slows down and eventually seems to choke as my work session proceeds. If I Exit LTR and re-enter and start all over, things will work normally for maybe 30 minutes, but then the Compare View feature begins to become very slow to respond.   In a recent example with my screen full of thumbnails in Library mode I highlighted two images to compare. LTR started to open the Compare View screen by first having the top row of thumbnails disappear to be replaced by the "SELECT" and "CANDIDATE" words in their spaces  (but no images), but Compare View never succeeded in gaining control of the screen. After some seconds the top row of thumbnails reasserted its position and the Compare View windows disappeared. But LTR kept trying to bring them back. Again the top row of thumbnails would go away, Select and candidate would reappear, try again, and give up. This went on for at least 2-3 minutes before I tried to choose File and Exit, but even that did not initially want to respond. It doesn't like to accept other commands when it's trying to open Compare View. Finally it allowed me to exit.
    To experiment I created a new catalog of 1100 images.  After 30-40 minutes, the Compare View function began to operate very slowly. With left and right side panels visible and two thumbnails highlighted, hitting Compare View can take half a minute before the two mid-size  images open in their respective SELECT and CANDIDATE windows. When the side panels are open and two images are in the Select/Candidate spaces, hitting the Tab button to close the side panels produces a very delayed response--25-30 seconds to close them, a few more seconds to enlarge the two images to full size. To reverse the process (i.e., to recall the two side panels), hitting Tab would make the two sides of the screen go black for up to a minute, with no words visible. Eventually the info fields in the panels would open up.
    I also created a new user account and imported a folder of 160 images. After half an hour Compare View began mis-placing data.  (I have a screen shot to show this.)  CANDIDATE appears on the left side of SELECT, whereas it should be on the right. The accompanying camera exposure data appears almost entirely to the left of the mid-screen dividing line. Although the Candidate and Select headings were transposed, the image exposure data was not, but the data for the image on the right was almost entirely to the left of the line dividing the screen in two.
    Gurus in The Lightroom Forum have examined Task Manager data showing Processes running and Performance indicators and they see nothing wrong.  I could also send screen shots of this data.
    At this point, the only way I can process my images is to work 30-40 minutes and then shut down everything, exit, and re-start LTR.  This is not normal.  I hope you can find the cause, and then the solution.  If you would like to see my screen shots, tell me how to submit them.
    Ollie
    [email protected]

  • IMessage beta loose all saved conversations when I open and close a window.

    iMessage beta looses all saved conversations when I open and close a window.
    Just reporting this bug... Could not find anyother place to do it.
    Jonathan

    I thought it was doing that also. But I found that if I start a new chat with someone I was messaging before, then the old messages re-appear in the messages window.

  • Today i download adobe cs6 , and install in as trial, when i open my cs6 , it open and close automatically

    Today i download adobe cs6 , and install in as trial, when i open my cs6 , it open and close automatically
    i want to try the adobe cs6 , 1st in trial time
    i am beginner for Photoshop,

    os win 7
    process: Intel(R) Core (TM) i3cpu 540 @ 3.07Ghz 3.06
    Ram: 4GB
    Type: 32 bit

  • My firefox always opens a crash report when I close it. Even if I have no tabs open and close firefox.

    The Crash information is:
    AdapterDeviceID: 95c4
    AdapterVendorID: 1002
    Add-ons: TFToolbarX@torrent-finder:1.2.6,{1de0de3c-0b5c-4f67-90c6-689623894991}:0.3,{9fb7d178-155a-4318-9173-1a8eaaea7fe4}:2.1.11,{B17C1C5A-04B1-11DB-9804-B622A1EF5492}:1.2.1,{c0c9a2c7-2e5c-4447-bc53-97718bc91e1b}:5.4,{d10d0bf8-f5b5-c8b4-a8b2-2b9879e08c5d}:1.3.9,{D4DD63FA-01E4-46a7-B6B1-EDAB7D6AD389}:0.9.8,{ef4e370e-d9f0-4e00-b93e-a4f274cfdd5a}:1.4.4,{b9db16a4-6edc-47ec-a1f4-b86292ed211d}:4.9.5,[email protected]:4.0.2,{1E73965B-8B48-48be-9C8D-68B920ABC1C4}:10.0.0.1410,avg@igeared:7.008.031.001,[email protected]:1.3.5
    AvailableVirtualMemory: 3804364800
    BuildID: 20110902133214
    CrashTime: 1316851060
    EMCheckCompatibility: true
    Email: [email protected]
    FramePoisonBase: 00000000f0de0000
    FramePoisonSize: 65536
    InstallTime: 1315413340
    Notes: AdapterVendorID: 1002, AdapterDeviceID: 95c4, AdapterDriverVersion: 8.872.0.0
    D2D? D2D+
    DWrite? DWrite+
    D3D10 Layers? D3D10 Layers+
    ProductName: Firefox
    ReleaseChannel: release
    SecondsSinceLastCrash: 452
    StartupTime: 1316850895
    SystemMemoryUsePercentage: 78
    Theme: LavaFox_V1-Blue
    Throttleable: 1
    TotalVirtualMemory: 4294836224
    URL: https://support.mozilla.com/en-US/questions/new?product=desktop&category=d2&search=My+firefox+always+opens+a+crash+report+when+I+close+it.+Even+if+I+have+no+tabs+open+and+close+firefox.&showform=1
    Vendor: Mozilla
    Version: 6.0.2
    Winsock_LSP: MSAFD Tcpip [TCP/IP] : 2 : 1 :
    MSAFD Tcpip [UDP/IP] : 2 : 2 : %SystemRoot%\system32\mswsock.dll
    MSAFD Tcpip [RAW/IP] : 2 : 3 :
    MSAFD Tcpip [TCP/IPv6] : 2 : 1 : %SystemRoot%\system32\mswsock.dll
    MSAFD Tcpip [UDP/IPv6] : 2 : 2 :
    MSAFD Tcpip [RAW/IPv6] : 2 : 3 : %SystemRoot%\system32\mswsock.dll
    RSVP TCPv6 Service Provider : 2 : 1 :
    RSVP TCP Service Provider : 2 : 1 : %SystemRoot%\system32\mswsock.dll
    RSVP UDPv6 Service Provider : 2 : 2 :
    RSVP UDP Service Provider : 2 : 2 : %SystemRoot%\system32\mswsock.dll
    This report also contains technical information about the state of the application when it crashed.

    Have a read of the rather complicated article
    * [[firefox crashes]]
    * and for anyone with firefox crashing before you can key in about:crashes see: <br/> http://kb.mozillazine.org/Breakpad#Location_of_crash_reports
    I note you have found bp-54df2ba6-de52-405d-9ccc-4dd272110924 have you any other recent crash signatures or crash IDs, the one you provide seems rather uncommon [https://crash-stats.mozilla.com/report/list?product=Firefox&query_search=signature&query_type=exact&query=karasx2.dll%400x2535&reason_type=contains&date=09%2F24%2F2011%2001%3A44%3A07&range_value=1&range_unit=weeks&hang_type=any&process_type=any&do_query=1&signature=karasx2.dll%400x2535 [karasx2.dll%400x2535]]
    Do you still get the problem in [[safe mode]] and with default themes, and all plugins disabled. Note common causes of crashes are malware, and versions of the software IDvault. (do you use IDvault ? - often provided by Comcast)

  • When to open and close database connection

    im trying to connect to a oracle database using servlets
    when should i open and close the connection
    it works fine when i do both in the doPost() method
    but when i tried to open connection in init() methd .. it doesnt seem to work
    what should i do...
    the connection is initialised in the init() method but is null in the doPost() method

    " im trying to connect to a oracle database using servlets
    when should i open and close the connection
    it works fine when i do both in the doPost() method
    but when i tried to open connection in init() methd .. it doesnt seem to work
    what should i do...
    the connection is initialised in the init() method but is null in the doPost() method"
    1:
    without seeing the code i would say the the connection is null
    because you are storing it as a servlet class variable which is
    not thread safe.
    2:
    The best way to do it using connection pooling
    detailed docs on the tomcat website
    3:
    if you are not using connection pooling, then
    open and close the connection in the do* method
    or
    use init() to place the connection in the servletconfig
    and close in destroy() and use synching to access

  • When I open 2 or more browsers of Firefox, click to open and close email it pops up the First Firefox browser since I have verrsion 6 as of yesterday. And some times the tool bar dosen't appear or have to refresh it.

    Question
    When I open 2 or more browsers of Firefox, click to open and close email it pops up the First Firefox browser since I have verrsion 6 as of yesterday. And some times the tool bar dosen't appear or have to refresh it.

    Question
    When I open 2 or more browsers of Firefox, click to open and close email it pops up the First Firefox browser since I have verrsion 6 as of yesterday. And some times the tool bar dosen't appear or have to refresh it.

Maybe you are looking for

  • Haven't been able to log in to AOL email via FireFox since Friday....have to use Google

    Not sure what is going on with AOL email and FireFox, but I have not been able to access my AOL email account via FireFox since Friday. I know others are having the same issue. I have no problem if I use Google.

  • Date and time problems

    On my older imacG5 running tiger I am able to display the clock as a floating transparent icon on the desktop which shows the date and time, on my newer intel imac and macbook pro running leopard I cannot do this, in fact there's two things that I ca

  • Oracle 9i (SE) Solaris 9 (Alert.log file)

    Hi Guys, How do I clean up my alert.log file. Do I have to delete it completely or only delete the content of the file. Thank you.

  • Plz Anyone i need help

    hi, i have a question if someone can awnser that i am designing a data warehouse with dimensions and fact table. The current operational data base has four year old data. Two of the dimensions are slowly changing dimension. My question is how do you

  • Problem while transport table entries (TFRM)

    Hi , An routine has been developed earlier, It has been release but not moved to Quality. In the same request there are another 3 or 4 tasks which i don't want to transport. So created a new request all the coding part is saved. But when i am trying