[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/2.6.34.7-0.5-desktop; 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 __java__.cc 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
javaaddpath(".");
surf(rand(10));
sleep(0.1);
jd = java_new("javax.swing.JDialog");
sl = java_new("OctSlider", "Slider1", "callback", 0, 359, 0);
jd.add(sl);
jd.setModal(1);
jd.setSize(250, 50);
a = jd.setVisible(1);
disp(a)
pkg unload java
--- end test_java.m ---
--- begin callback.m ---
function callback(n)
[a, b] = view();
view(n, b)
drawnow
endfunction
--- end callback.m ---
--- begin OctSlider.java ---
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
value){
super(min, max, value);
this.callBack = callBack;
setName(name);
addChangeListener(this);
}
@Override
public void stateChanged(ChangeEvent e) {
if (e.getSource() == this && getValueIsAdjusting()) {
int val = (int)getValue();
Octave.call(callBack, new Object[]{val}, new Object[] {});
}
}
}
--- end OctSlider.java ---
all in the same folder for simplicity.
The java file is compiled with
javac -cp /home/martinh/octave/java-1.2.7/octave.jar OctSlider.java
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.
- Re: R: Best way to create interactive GUI apps with octave?, schnumbl, 2010/11/01
- Re: R: Best way to create interactive GUI apps with octave?, Michael Goffioul, 2010/11/01
- Re: R: Best way to create interactive GUI apps with octave?, schnumbl, 2010/11/01
- Re: R: Best way to create interactive GUI apps with octave?, Martin Helm, 2010/11/01
- Re: R: Best way to create interactive GUI apps with octave?, schnumbl, 2010/11/01
- Re: R: Best way to create interactive GUI apps with octave?, schnumbl, 2010/11/04
- Re: R: Best way to create interactive GUI apps with octave?, schnumbl, 2010/11/04
- Re: R: Best way to create interactive GUI apps with octave?, Martin Helm, 2010/11/07
- Re: R: Best way to create interactive GUI apps with octave?, schnumbl, 2010/11/19
- Re: R: Best way to create interactive GUI apps with octave?, Martin Helm, 2010/11/04
- Re: R: Best way to create interactive GUI apps with octave?,
Martin Helm <=