Note that there are some explanatory texts on larger screens.

plurals
  1. POcalling a time consuming method from a JButtonActionPerformed
    primarykey
    data
    text
    <p>In the following lines of code when Button1 is pressed the Jframe becomes unresponsive till the execution of the encode() method is completed. But I need to update a progress bar in the Jframe displaying the progress. </p> <pre><code>private void Button1ActionPerformed(java.awt.event.ActionEvent evt) { try { if (flagState == 0) { WavFile.decode(readWavFile, msg.getText(), key.getText().hashCode()); } else if (flagState == 1) { WavFile.encode(readWavFile, msg.getText(), key.getText().hashCode()); } } catch (WavFileException | IOException e) { notes.setText(e.getMessage()); } } </code></pre> <p>I thought of doing this</p> <pre><code>private void Button1ActionPerformed(java.awt.event.ActionEvent evt) { try { if (flagState == 0) { Thread t = new Thread(new Runnable() { public void run() { WavFile.decode(readWavFile, msg.getText(), key.getText().hashCode()); } };) t.start(); } else if (flagState == 1) { Thread t = new Thread(new Runnable() { public void run() { WavFile.encode(readWavFile, msg.getText(), key.getText().hashCode()); } };) t.start(); } } catch (WavFileException | IOException e) { notes.setText(e.getMessage()); } } </code></pre> <p>and update the progress bar from the encode() method.</p> <p>But I understand that it will a strong coupling between the modules and i dont want that.</p> <p>I also dont think that calling a new thread every time is a good idea ( thought of ExecutorService but not sure how to use it).</p> <p>What should I do to make this into a decent piece code?? </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload