communication Interface Program
communication Interface Program
import java.rmi.*;
public interface CommuInt extends Remote
{
public String printTime()throws RemoteException, Exception;
}
1-4
//Authentication Interface program
import java.rmi.*;
public interface AuthInt extends Remote
{ public String check(String Uname, String pwd) throws RemoteException, Exception; }
2-4
//Calculator Interface Program.
import java.rmi.*;
public interface CalcInt extends Remote
{ public long arith(int flag, long a, long b) throws RemoteException; }
3-4
public CalcCli()
{
super("Calculator");
val=0;
setLayout(null);
l1.setBounds(20,50,55,25); add(l1);
l2.setBounds(20,100,55,25); add(l2);
l3.setBounds(20,150,55,25); add(l3);
t1.setBounds(150,50,100,25); add(t1);
t2.setBounds(150,100,100,25); add(t2);
t3.setBounds(150,150,100,25); add(t3);
B1.setBounds(20,200,80,25); add(B1);
B2.setBounds(100,200,80,25); add(B2);
B3.setBounds(180,200,80,25); add(B3);
B4.setBounds(260,200,80,25); add(B4);
B1.addActionListener(this);
B2.addActionListener(this);
B3.addActionListener(this);
B4.addActionListener(this);
addWindowListener(
new WindowAdapter()
{ public void windowClosing(WindowEvent e)
{ System.exit(0);}
});
}
public void actionPerformed(ActionEvent AE)
{ if(AE.getSource()==B1)
{ val=1; }
else if(AE.getSource()==B2)
{ val=2; }
else if(AE.getSource()==B3)
{ val=3; }
else if(AE.getSource()==B4)
{ val=4; }
fun();
}
public void fun()
{ int i=Integer.parseInt(t1.getText());
int j=Integer.parseInt(t2.getText());
long result;
try{
String rmiName = "rmi://127.0.0.1/CalculatorService";
CalcInt MI=(CalcInt)Naming.lookup(rmiName);
result=MI.arith(val,i,j);
t3.setText(""+result);
}
catch(Exception ex)
{System.out.println("Exception:"+ex); }
}
public static void main(String args[])
{ CalcCli MC=new CalcCli();
MC.setVisible(true);
MC.setSize(600,500);
}
}
4-4