import java.awt.*;


//  Iteration dialog class

class IterationDialog extends Dialog {

  public Net net;
  boolean keep_going = true;


  IterationDialog (Net nt) {

    super (new Frame(), "Training...", true);
    net = nt;
    int i;
    int cur_iter = 0;
    TextField trialField;

    Panel p_title = new Panel();
    p_title.setLayout (new GridLayout(3,1));
    p_title.add (new Label (" "));
    p_title.add (new Label ("    The network is training."));
    add ("North", p_title);

//    Panel p_list = new Panel();
//    p_list.setLayout (new GridLayout(3, 1, 0, 0));

    Panel p_trial = new Panel();
    p_trial.setLayout(new FlowLayout(FlowLayout.RIGHT));
    trialField = new TextField(String.valueOf(cur_iter));
    trialField.setEditable(false);
    p_trial.add(new Label("Running iteration "));
    p_trial.add(trialField);
    p_trial.add(new Label("of " + Integer.toString(net.iterations)));

//    p_list.add(p_trial);
//    p_list.add(p_learn);
//    p_list.add(p_clear);

    add("Center", p_trial);

    add("East", new Label(" "));
    add("West", new Label(" "));

    Panel p_buttons = new Panel();
    p_buttons.setLayout (new FlowLayout());
    p_buttons.add (new Button ("Stop"));
    add("South", p_buttons);

    Font f = new Font ("Dialog", Font.PLAIN, 12);
    setFont (f);
    resize (300, 170);

    testFunction();
  }


  void testFunction () {
    int i;
    while (keep_going) {
      for (i = 1; i < 100000; i ++) {
        System.out.println(keep_going);
      }
    }
  }
  

  // Handle the buttons

  public boolean action (Event e, Object o) {
    int i, old_iter, new_iter;
    float old_rate, new_rate;
  
    if (e.target instanceof Button) {
      if (o.equals("Stop")) {
        keep_going = false;
        hide();
        dispose();
      }
    }
    return false;
  }
}
