5 Replies Latest reply: Apr 11, 2011 9:59 PM by EJP RSS

    need help in rmi

    854538
      can anyone tell me what's the error in this rmi calculator



      <h1>CLIENT</h1>
      import java.applet.*;
      import java.awt.event.*;
      import java.awt.*;
      import java.rmi.*;
      //<applet code=clint.class width=200 height=200></applet>
      public class clint extends Applet implements ActionListener
      {
       Button b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,ad,sb,ml,dv,eq,clr;
       int x=0,y=0,z=0,s=0,ans;
       String s1;
       TextField t1;
       calintf ci;
      
       public void init()
       {
      
        s1="";
        t1=new TextField(20);
        add(t1);
      
        clr=new Button("Clr");
        clr.addActionListener(this);
        add(clr);
      
        b1=new Button("1");
        b1.addActionListener(this);
        add(b1);
        
        b2=new Button("2");
        add(b2);
        b2.addActionListener(this);
      
        b3=new Button("3");
        add(b3);
        b3.addActionListener(this);
      
        b4=new Button("4");
        add(b4);
        b4.addActionListener(this);
      
        b5=new Button("5");
        add(b5);
        b5.addActionListener(this);
      
        b6=new Button("6");
        add(b6);
        b6.addActionListener(this);
      
        b7=new Button("7");
        add(b7);
        b7.addActionListener(this);
      
        b8=new Button("8");
        add(b8);
        b8.addActionListener(this);
      
        b9=new Button("9");
        add(b9);
        b9.addActionListener(this);
      
        b0=new Button("0");
        add(b0);
        b0.addActionListener(this);
      
        sb=new Button("-");
        add(sb);
        sb.addActionListener(this);
      
        ad=new Button("+");
        add(ad);
        ad.addActionListener(this);
      
        ml=new Button("*");
        add(ml);
        ml.addActionListener(this);
      
        dv=new Button("/");
        add(dv);
        dv.addActionListener(this);
      
        eq=new Button("=");
        add(eq);
        eq.addActionListener(this);
      
       }
      
       public void actionPerformed(ActionEvent e)
       {
      //try{
       
       //}catch(Exception ex){}
      
        if(e.getSource()==b0)
        {
          s1=s1+0;
          t1.setText(s1);
        }
      
      if(e.getSource()==b1)
        {
          s1=s1+1;
          t1.setText(s1);
        }
      
      if(e.getSource()==b2)
        {
          s1=s1+2;
          t1.setText(s1);
        }
      
      if(e.getSource()==b3)
        {
          s1=s1+3;
          t1.setText(s1);
        }
      
      if(e.getSource()==b4)
        {
          s1=s1+4;
          t1.setText(s1);
        }
      
      if(e.getSource()==b5)
        {
          s1=s1+5;
          t1.setText(s1);
        }
      
      if(e.getSource()==b6)
        {
          s1=s1+6;
          t1.setText(s1);
        }
      
      if(e.getSource()==b7)
        {
          s1=s1+7;
          t1.setText(s1);
        }
      
      if(e.getSource()==b8)
        {
          s1=s1+8;
          t1.setText(s1);
        }
      
      if(e.getSource()==b9)
        {
          s1=s1+9;
          t1.setText(s1);
        }
      
      if(e.getSource()==ad)
        {
          x=1;
          y=Integer.parseInt(t1.getText());
          s1="";
          t1.setText(s1);
        }
      
      if(e.getSource()==sb)
        {
          x=2;
          y=Integer.parseInt(t1.getText());
          s1="";
          t1.setText(s1);
        }
      
      if(e.getSource()==ml)
        {
          x=3;
          y=Integer.parseInt(t1.getText());
          s1="";
          t1.setText(s1);
        }
      
      if(e.getSource()==dv)
        {
          x=4;
          y=Integer.parseInt(t1.getText());
          s1="";
          t1.setText(s1);
        }
      
      
      
      if(e.getSource()==clr)
        {
          x=0;
          y=0;
          s1="";
          t1.setText(s1);
        }
      
      
      if(e.getSource()==eq)
        {
          //x=5;
          z=Integer.parseInt(t1.getText());
          s1="";
          t1.setText("");
      try{
         ci=(calintf)Naming.lookup("rmi://127.0.0.1/calc");
          switch(x)
          {
      
            case 1:ans=ci.radt(z,y);
                      // t1.setText(String.valueOf(ans));
                       break;
            case 2:ans=ci.rsub(y,z);
                       //t1.setText(String.valueOf(ans));
                       break;
            case 3:ans=ci.rmul(y,z);
                       //t1.setText(String.valueOf(ans));
                       break;
            case 4:ans=ci.rdiv(y,z);
                       t1.setText(String.valueOf(ans));
                       break;
           }
          }catch(Exception ex){}
          t1.setText(String.valueOf(ans));
      
          
         }
      
        }
        
      }
       
       
      <H1>SERVER</H1>
      import java.rmi.*;
      public class calserver
           {
           public static void main(String args[])
                {     try{
                calfun cf=new calfun();
                Naming.rebind("calc",cf);
                     }catch(Exception e)
                     {}
                }
           }
                
      <h1>INTERFACE</h1>
      import java.rmi.*;
      
      public interface calintf extends Remote
           {     
           public int radt(int a,int b) throws RemoteException;
           public int rsub(int a,int b) throws RemoteException;
           public int rmul(int a,int b) throws RemoteException;
           public int rdiv(int a,int b) throws RemoteException;     
                
           }
      <h1>FUNCTION</h1>
      import java.rmi.*;
      import java.rmi.server.*;
      public class calfun extends UnicastRemoteObject implements calintf
           {
           calfun()throws RemoteException
                {}
           public int radt(int a,int b)
                {
                int f=a+b;
                return f;
                }
           public int rmul(int a,int b)
                {
                int f=a*b;
                return f;
                }
           public int rsub(int a,int b)
                {
                int f=a-b;
                return f;
                }
           public int rdiv(int a,int b)
                {
                int f=a/b;
                return f;
                }
           }