[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: R: Best way to create interactive GUI apps with octave?

From: Martin Helm
Subject: Re: R: Best way to create interactive GUI apps with octave?
Date: Sun, 7 Nov 2010 15:51:50 +0100
User-agent: KMail/1.13.5 (Linux/; KDE/4.5.3; x86_64; ; )

I meanwhile tested a bit a trivila example for callbacks with the java 1.2.7 
package (and octave 3.3.53 - had to change getcwd in to make it 
compatible) and it still works as expected on gnu/linux (opensuse 11.3).

I have 3 files, 2 m files (the main script and the callback function) and one 
java file

--- begin test_java.m ---

pkg load java

jd = java_new("javax.swing.JDialog");
sl = java_new("OctSlider", "Slider1", "callback", 0, 359, 0);
jd.setSize(250, 50);
a = jd.setVisible(1);
pkg unload java

--- end test_java.m ---

--- begin callback.m ---

function callback(n)
  [a, b] = view();
  view(n, b)

--- end callback.m ---

--- begin ---

import javax.swing.JSlider;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import org.octave.Octave;

public class OctSlider extends JSlider implements ChangeListener {

        private String callBack = "";

        public OctSlider(String name, String callBack, int min, int max, int 
                super(min, max, value);
                this.callBack = callBack;

        public void stateChanged(ChangeEvent e) {
                if (e.getSource() == this && getValueIsAdjusting()) {
            int val = (int)getValue();
  , new Object[]{val}, new Object[] {});


--- end ---

all in the same folder for simplicity.
The java file is compiled with
javac -cp /home/martinh/octave/java-1.2.7/octave.jar

of course on another system the classpath has to be set to the place where 
octave.jar is located.

Then run it with "octave test_java.m" or make it an executable script.

It opens a gnuplot window with random surface and creates a java slider which 
can be used to rotate the plot in the gnuplot window.

This code is of course not in any way a masterpiece of octave or java design, 
just a trivial example to ensure that the callbacks from java work.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]