import java.applet.Applet;
import java.awt.*;

import java.rmi.*;

public class CLUGApplet4 extends CLUGApplet1 {
  
  CLUGJob remoteJob;
    
  public void init() {
    super.init();
    try {
      if (isApplet)
        remoteJob = (CLUGJob) Naming.lookup("rmi://"+getCodeBase().getHost()+"/CLUGServer");
      else
        remoteJob = (CLUGJob) Naming.lookup("rmi://localhost/CLUGServer");
    } catch (RemoteException e) {
      System.err.println(e);
    } catch (java.net.MalformedURLException e) {
      System.err.println(e);
    } catch (NotBoundException e) {
      System.err.println(e);
    };

  }
  
  public boolean action(Event e, Object o) {
    if (o.equals("=")) {
      int n1=0, n2=0;
      try {
        n1 = Integer.parseInt(faktor1.getText());
        n2 = Integer.parseInt(faktor2.getText());        
      } catch (NumberFormatException ex) {
        System.err.println(ex);
      }
      
      try {
        produkt.setText(remoteJob.calculate(n1, n2));
      } catch (RemoteException ex) {
        System.err.println(ex);
      }
      return true;  
    }
    return super.action(e, o);
  }
  
  public static void main(String [] param) {
    Frame f = new ExtFrame("CLUG-Applet in a Frame (RMIServer)");
    Applet a;
    isApplet = false;
    
    f.add(a = new CLUGApplet4());
    a.init();
    f.pack();
    f.show();
  }
}

