示例#1
0
  // ---------starts the image loader worker-----------
  // (displays the picture when its done)
  private void startImageLoader(String img_file) {
    final LoadImage imgRetriever = new LoadImage(img_file);

    // adds listener!
    imgRetriever.addPropertyChangeListener(
        new PropertyChangeListener() {

          public void propertyChange(PropertyChangeEvent evt) {

            if (imgRetriever.getState() == StateValue.DONE) {

              javax.swing.SwingUtilities.invokeLater(
                  new Runnable() {

                    public void run() {

                      try {
                        imgToShow = imgRetriever.get();

                        System.out.println("shutting down everything");
                        shutDownEverything();

                        // SHOWS IMAGE
                        getGraphics()
                            .drawImage(
                                imgToShow, LOSE_WIN_TIE_IMAGE_X, LOSE_WIN_TIE_IMAGE_Y, null, null);

                      } catch (InterruptedException e) {
                        System.err.println("Couldnt display image 1 ");
                      } catch (ExecutionException e) {
                        System.err.println("Couldnt display image 2");
                      }
                    }
                  });
            }
          }
        });

    // executes
    imgRetriever.execute();
  } // end of startIMageLoader
 @Override
 public void onDestroy() {
   // TODO Auto-generated method stub
   super.onDestroy();
   if (loadImage != null) loadImage.cancel(true);
 }