home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1997 August / PCO0897.ISO / filesbbs / os2 / fp1os2.arj / OS2 / DATA / 49 / C / 0 / F_26836 / SjScriptWatchdog.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-05-15  |  2.9 KB  |  100 lines

  1. import java.awt.BorderLayout;
  2. import java.awt.Button;
  3. import java.awt.Component;
  4. import java.awt.Container;
  5. import java.awt.Event;
  6. import java.awt.FlowLayout;
  7. import java.awt.Frame;
  8. import java.awt.Label;
  9. import java.awt.Panel;
  10. import java.awt.Window;
  11.  
  12. class SjScriptWatchdog extends Frame implements Runnable {
  13.    private static final long DEFAULT_SLEEP_TIME = 60000L;
  14.    private static String aMsgText = null;
  15.    private JScriptRuntimeInstance aRTI;
  16.    private Thread aMyThread;
  17.    private long nSleepTime;
  18.    private boolean bAllreadyStoped;
  19.    private boolean bFrameCreated;
  20.    private boolean bContinue;
  21.    private Button aOk;
  22.    private Button aCancel;
  23.    private Label aMessage;
  24.  
  25.    public SjScriptWatchdog(JScriptRuntimeInstance var1) {
  26.       super("JavaScript Wachhund");
  27.       this.aRTI = var1;
  28.       this.bAllreadyStoped = false;
  29.       this.bFrameCreated = false;
  30.       this.aMyThread = new Thread(this, "Script-Watchdog for " + this.aRTI);
  31.       this.aMyThread.start();
  32.       this.nSleepTime = 60000L;
  33.       if (aMsgText == null) {
  34.          aMsgText = JavaScript.GetWatchdogMessage();
  35.       }
  36.  
  37.    }
  38.  
  39.    public void ScriptDone() {
  40.       this.bAllreadyStoped = true;
  41.       this.aMyThread.stop();
  42.       ((Component)this).hide();
  43.       ((Frame)this).dispose();
  44.    }
  45.  
  46.    public boolean action(Event var1, Object var2) {
  47.       if (var1.target == this.aOk) {
  48.          ((Component)this).hide();
  49.          return true;
  50.       } else if (var1.target == this.aCancel) {
  51.          this.bContinue = false;
  52.          this.aRTI.StopExecution();
  53.          this.bAllreadyStoped = true;
  54.          ((Component)this).hide();
  55.          ((Frame)this).dispose();
  56.          return true;
  57.       } else {
  58.          return false;
  59.       }
  60.    }
  61.  
  62.    public void run() {
  63.       this.bContinue = true;
  64.  
  65.       while(this.bContinue && !this.bAllreadyStoped) {
  66.          try {
  67.             Thread.sleep(this.nSleepTime);
  68.             if (!this.bAllreadyStoped) {
  69.                this.CreateMe();
  70.             }
  71.          } catch (InterruptedException var1) {
  72.             this.bContinue = false;
  73.          }
  74.       }
  75.  
  76.    }
  77.  
  78.    private final void CreateMe() {
  79.       if (!this.bFrameCreated) {
  80.          this.bFrameCreated = true;
  81.          ((Container)this).setLayout(new BorderLayout());
  82.          Panel var1 = new Panel();
  83.          Panel var2 = new Panel();
  84.          ((Container)var2).setLayout(new FlowLayout());
  85.          this.aOk = new Button("Ok");
  86.          this.aCancel = new Button("Cancel");
  87.          ((Container)var2).add(this.aOk);
  88.          ((Container)var2).add(this.aCancel);
  89.          this.aMessage = new Label(aMsgText);
  90.          ((Container)var1).add(this.aMessage);
  91.          ((Container)this).add("North", var1);
  92.          ((Container)this).add("South", var2);
  93.          ((Window)this).pack();
  94.          ((Component)this).resize(300, 180);
  95.       }
  96.  
  97.       ((Window)this).show();
  98.    }
  99. }
  100.