3

我想在java中执行一个函数,但同时我想JOptionPane在操作开始和结束时向用户显示一个,问题是如果我不按下第一个的“Accept”buyton JOptionPane,我的函数不会't 开始,我希望它是自动的,我该怎么做?这是我的代码,我正在为我的功能使用 JRI 接口。


JOptionPane.showMessageDialog(null, "Leyendo archivos, espere un momento...","Importar archivos cel", JOptionPane.INFORMATION_MESSAGE);

REXP data = re.eval("rawdata <- read.celfiles(celFiles)");

JOptionPane.showMessageDialog(null, "Se han importado las muestras exitosamente.", "Importar archivos cel",JOptionPane.INFORMATION_MESSAGE);
4

1 回答 1

0

使用ExecutorService,我相信如果理解它应该更容易实现。例子,

REXP data;
    try {
        ExecutorService newCachedThreadPool = Executors.newCachedThreadPool();
        Future<REXP> submit = newCachedThreadPool.submit(new Callable<REXP>() {
            @Override
            public Object call() throws Exception {
                return re.eval("rawdata <- read.celfiles(celFiles)");
            }
        });
        data = submit.get();
    } catch (InterruptedException | ExecutionException ex) {
        System.err.println(ex.getMessage);
    }
    JOptionPane.showMessageDialog(null, "Leyendo archivos, espere un momento...", "Importar archivos cel", JOptionPane.INFORMATION_MESSAGE);
    JOptionPane.showMessageDialog(null, "Se han importado las muestras exitosamente.", "Importar archivos cel", JOptionPane.INFORMATION_MESSAGE);

为了方便起见,您可以使用它的其他重载方法。见文档

于 2015-06-22T01:01:08.147 回答