Skip to content

Instantly share code, notes, and snippets.

@imagejan
Created December 2, 2014 17:38
Show Gist options
  • Save imagejan/f238e6a5a7d49b597329 to your computer and use it in GitHub Desktop.
Save imagejan/f238e6a5a7d49b597329 to your computer and use it in GitHub Desktop.
Slider and DialogListener demo
import ij.IJ;
import ij.gui.GenericDialog;
import ij.gui.DialogListener;
import ij.ImagePlus;
import ij.plugin.PlugIn;
import java.awt.AWTEvent;
import java.awt.Scrollbar;
public class Dialog_Test implements PlugIn, DialogListener {
private static GenericDialog gd;
String text;
public void run(String arg) {
showDialog();
IJ.log("Text: "+text);
}
void showDialog() {
gd = new GenericDialog("Test Dialog");
gd.addSlider("X", 0, 100, 0);
gd.addSlider("Y", 0, 200, 0);
gd.addDialogListener(this);
gd.showDialog();
}
public boolean dialogItemChanged(GenericDialog gd, AWTEvent e) {
final double Valor_X = gd.getNextNumber();
final double Valor_Y = gd.getNextNumber();
Scrollbar slider1 = (Scrollbar)gd.getSliders().get(0);
Scrollbar slider2 = (Scrollbar)gd.getSliders().get(1);
IJ.log("Slider 1 value: "+IJ.d2s(slider1.getValue()));
slider2.setValue(slider1.getValue());
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment