0

完了するまでに時間がかかる可能性のある JNI 関数があり、関数が終了している間、JProgress バーを不確定モードで実行したいと考えています。Oracle が提供するチュートリアルを読みましたが、そのチュートリアルの性質上、その方法を理解するのに役立たないようです。この関数をバックグラウンド スレッドで実行する必要があることはわかっていますが、その方法がよくわかりません。

関連するコードは次のとおりです。押されたときに関数 mainCpp() を呼び出すボタン (runButton) があります。

public class Foo extends javax.swing.JFrame 
                         implements ActionListener,
                                    PropertyChangeListener{

    @Override
    public void actionPerformed(ActionEvent ae){
        //Don't know what goes here, I don't think it is necessary though because I do not intend to use a determinate progress bar
    }

    @Override
    public void propertyChange(PropertyChangeEvent pce){
        //I don't intend on using an determinate progress bar, so I also do not think this is necassary
    }

class Task extends SwingWorker<Void, Void>{

    @Override
    public Void doInBackground{
         Foo t = new Foo();
         t.mainCpp();

         System.out.println("Done...");
    }
    return null;
}

/*JNI Function Declaration*/
public native int mainCpp(); //The original function takes arguments, but I have ommitted them for simplicity. If they are part of the problem, I can put them back in.

...//some codes about GUI

private void runButtonActionPerformed(java.awt.event.ActionEvent evt) {

    ProgressBar.setIndeterminate(true);
    Task task = new Task();
    task.execute();    
    ProgressBar.setIndeterminate(false);

}


/*Declarations*/
private javax.swing.JButton runButton;
}

どんな助けでも大歓迎です。

編集: kiheru が提案したことを実行しようとして編集されましたが、まだ機能しません。

4

1 に答える 1