摆动工作不起作用

时间:2015-06-14 17:04:55

标签: java swingworker

在我的申请中,我有两个不同的摇摆工作者(他们做两个不同的工作)。第一个完美,而后者则没有。

我能做些什么来解决它?

class worker extends SwingWorker<Boolean, String> {     
    @Override
     protected Boolean doInBackground() throws Exception {
        getstub().registration(name.getText(), surname.getText());
      return true;
     }

     protected void done() {
      boolean status;
      try {
       status = get();
       regstatus.setText("registration status: " + status);
      } catch (InterruptedException e) {
      } catch (ExecutionException e) {
      }
     }
}


class worker1 extends SwingWorker<Boolean, String> {        
    @Override
     protected Boolean doInBackground() throws Exception {
        int i = Integer.parseInt(id.getText());
        double r = Double.parseDouble(range.getText());
        double la = Double.parseDouble(lat.getText());
        Coordinate lat = new DegreeCoordinate(la);
        double lo = Double.parseDouble(lon.getText());
        Coordinate lon = new DegreeCoordinate(lo);
        System.out.println("id: "+i+" lat: "+la+ " lon: "+lo+" type: "+type.getText()+ " range: "+r);
        getstub().request(i, lat ,lon ,type.getText(), r);          
        return true;
     }

     protected void done() {

      boolean status;
      try {
       status = get();
       reqstatus.setText("request status: " + status);
      } catch (InterruptedException e) {
      } catch (ExecutionException e) {
      }
     }
}

和两个启动工作人员的jbuttons

 private JButton register = new JButton("Register");
 register.addActionListener(new ActionListener() {
           public void actionPerformed(ActionEvent arg0) {
              new worker().execute();
           }
          });

private JButton search = new JButton("Search now");
search.addActionListener(new ActionListener() {
               public void actionPerformed(ActionEvent arg0) {
                   reqstatus.setText("I'm searching...");
                   new worker1().execute();                    
               }
              });

1 个答案:

答案 0 :(得分:0)

大范围内的问题

看起来你正在使用ninja-exception-logging(看不见的):

  } catch (InterruptedException e) {
  } catch (ExecutionException e) {
  }

在那里做一些真正的日志记录,你很可能会看到问题。至少使用System.out.println();更好的选择是log4j

  } catch (InterruptedException e) {
      //a thread exception, quite unlikely to happen
      System.out.println(e);
  } catch (ExecutionException e) {
      System.out.println(e);
  }

特别错误

启用日志记录后,找到了包含在NumberFormatException中的ExecutionException