Пример #1
0
  private void compute() {

    // final File file = new File(filePathTextField.getText());

    messagesTextArea.setText("Welcome message!\n");

    computationWorker =
        new ComputationWorker(filePathTextField.getText(), messagesTextArea, drawPanel);

    computationWorker.addPropertyChangeListener(
        new PropertyChangeListener() {
          @Override
          public void propertyChange(final PropertyChangeEvent event) {
            switch (event.getPropertyName()) {
              case "progress":
                break;
              case "state":
                switch ((StateValue) event.getNewValue()) {
                  case DONE:
                    computationWorker = null;
                    break;
                  case STARTED:
                  case PENDING:
                    break;
                }
                break;
            }
          }
        });

    // Very important. Start up working thread.
    computationWorker.execute();
  }
Пример #2
0
 private void cancel() {
   computationWorker.cancel(true);
 }