Topic
  • 4 replies
  • Latest Post - ‏2013-05-14T18:07:20Z by CedricVB
CedricVB
CedricVB
5 Posts

Pinned topic ILOG Java interface & swing

‏2013-05-10T15:18:45Z |

Hello,

To make my models a bit easier to work with, I'd like to spice them up with confirmation dialogs/alerts. Since this functionality wasn't available in the javascript API, I wanted to interface my CPLEX model with Java. 

I've got the following code:

 

package vrp;
import javax.swing.*;
import ilog.opl.*;
 
public class Extensions {
private JFrame frame = new JFrame();
 
public Extensions() {
frame.setSize(400,400);
frame.setVisible(true);
}

The file loads correctly, I'm able to execute functions from my OPL file, but the window isn't shown (though it is when I try to execute the classfile directly).
Any idea if it is possible to do this?

Kind regards,

Cedric

  • rdumeur
    rdumeur
    123 Posts

    Re: ILOG Java interface & swing

    ‏2013-05-10T15:49:29Z  

    Hi Cedric,

     

    Unfortunately, your code seems truncated. Could you please repost it as an attachment?

    Thank you in advance,

     

    Cheers,

  • CedricVB
    CedricVB
    5 Posts

    Re: ILOG Java interface & swing

    ‏2013-05-13T21:51:16Z  
    • rdumeur
    • ‏2013-05-10T15:49:29Z

    Hi Cedric,

     

    Unfortunately, your code seems truncated. Could you please repost it as an attachment?

    Thank you in advance,

     

    Cheers,

    Hello :)

    Actually, that's all of the Java code (except for the closing bracket). 

    In my CP mod file I've got the following:

    using CP;
    execute {
        IloOplImportJava("java/Extensions.jar");
        var obj = IloOplCallJava("vrp.Extensions", "<init>", "");
    }

    Execution "blocks" right after the init, which I would interpret as the GUI running in the same thread as the execution thread, but still no window is shown. (Note: everything non-GUI related works just fine.)

    Updated on 2013-05-13T22:01:46Z at 2013-05-13T22:01:46Z by CedricVB
  • FredericDelhoume
    FredericDelhoume
    3 Posts

    Re: ILOG Java interface & swing

    ‏2013-05-14T08:32:35Z  
    • CedricVB
    • ‏2013-05-13T21:51:16Z

    Hello :)

    Actually, that's all of the Java code (except for the closing bracket). 

    In my CP mod file I've got the following:

    using CP;
    execute {
        IloOplImportJava("java/Extensions.jar");
        var obj = IloOplCallJava("vrp.Extensions", "<init>", "");
    }

    Execution "blocks" right after the init, which I would interpret as the GUI running in the same thread as the execution thread, but still no window is shown. (Note: everything non-GUI related works just fine.)

    Hi,

    Your code works fine on my machine, in  OPL IDE the window opens and stays there, running with oplrun the window appears then closes because execution ends.

     

     

     

    Attachments

  • CedricVB
    CedricVB
    5 Posts

    Re: ILOG Java interface & swing

    ‏2013-05-14T18:07:20Z  

    Apparently the problem is Java VM-related... Not sure exactly why that is and it is working for Frederic though.
    It now works when supplying a different java VM as startup parameter for the IDE.

    -vm "C:\Program Files\Java\jdk1.7.0_07\jre\bin"

    Now able to make confirmation dialogs! Awesomeness :)