title: Dispatch an event to main java
body: <p>I have a <em>CountDownTimer</em> class that when it finishes counting down it should dispatch an event to main java (or any class that uses it) letting it know it has finished.</p>
  
  <p>Here is my class:</p>
  
  <pre><code>import com.google.gwt.user.client.Timer;
  import com.google.gwt.user.client.Window;
  import com.google.gwt.user.client.ui.Label;
  
  public class CountTimer {
  
      private Label targetText;
      private String direction;
      private int minutes;
      private int seconds;
      private int totalSeconds;
      private int timeTotal;
      private int timeLoaded;
      private Boolean test;
  
      Timer timer;
  
  
      public CountTimer(int min,int sec,String dir,Label targetTextField)
      {
          minutes = min * 60;
          seconds = sec;
          timeTotal = minutes + seconds;
          if (dir == "down") {
              totalSeconds = minutes + seconds;
          }
          else {
              totalSeconds = 0;
          }
          if (targetTextField != null) {
              targetText = targetTextField;
          }
          direction = dir;
      }
  
      public void start()
      {
          timer = new Timer(){
              public void run(){  
                  timeLoaded +=  1;
  
                  if (direction == "up") {
                      totalSeconds++;
                  }
                  else {
                      totalSeconds--;
                  }
  
                  seconds = totalSeconds % 60;
                  minutes = (int) Math.floor(totalSeconds / 60);
                  String minutesDisplay = (minutes &lt; 10) ? "0" + Integer.toString(minutes) : Integer.toString(minutes);
                  String secondsDisplay= (seconds &lt; 10) ? "0" + Integer.toString(seconds): Integer.toString(seconds);
                  if (targetText != null) {
                      targetText.setText( minutesDisplay + ":" + secondsDisplay);
                  }
                  if (test=true)  {
                      consoleLog(minutesDisplay + ":" + secondsDisplay);  
                  }
  
                  if(timeTotal == timeLoaded) {
                      //DISPATCH CUSTOM EVENT TO MAIN.JAVA HERE
                      Window.alert("OK");
                      timer.cancel();
                  }
              }
          };
  
          timer.scheduleRepeating(1000);        
      }
  
      public int getTimeTotal()
      {
          return timeTotal;
      }
  
      public int getTimeLoaded()
      {
          return timeLoaded;
      }
  
      public int getProg()
      {
          return (int) Math.floor(timeLoaded/timeTotal*100);
      }
  
      public native final void consoleLog(String msg)/*-{
      console.log(msg);
  }-*/;
  
  }
  </code></pre>
  
  <p>Please help, how can i do this?</p>