can anyone tell me what's the error in this rmi calculator program....... especially the clint.java.........

here when i run the rmi calculator.........i gets an applet calculator.....but for all the mathematical addition,sub,div,mul......i'm getting the null value.......i also doubt at whether the try catch is placed wrongly............

Edited 5 Years Ago by Jessurider: n/a

Attachments
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;
		}
	}
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;	
		
	}
import java.rmi.*;
public class calserver
	{
	public static void main(String args[])
		{	try{
		calfun cf=new calfun();
		Naming.rebind("calc",cf);
			}catch(Exception e)
			{}
		}
	}
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));

    
   }

  }
  
}

help me,,,
i'm getting a java.lang.NullPointerException

Edited 5 Years Ago by Jessurider: n/a

start with calculator view, replace all int to double, in all classes

I don't want to help you with that longer ..., nothing special but view to GUI is correct, not nice or ....

import java.awt.event.*;
import java.awt.*;
import java.math.RoundingMode;
import java.rmi.*;
import java.text.NumberFormat;
import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JFormattedTextField;
import javax.swing.JPanel;
//<applet code=Clint.class width=200 height=200></applet>
public class Clint extends JApplet implements ActionListener {

    private static final long serialVersionUID = 1L;
    private JButton b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, ad, sb, ml, dv, eq, clr;
    private int x = 0;
    private double y = 0, z = 0, s = 0, ans;
    private double s1;
    private JFormattedTextField t1;
    private calintf ci;
    private JPanel inputPanel = new JPanel();
    private JPanel buttonPanel = new JPanel();

    @Override
    public void init() {
        inputPanel = new JPanel();
        inputPanel.setPreferredSize(new Dimension(400, 30));
        inputPanel.setLayout(new BorderLayout(5, 5));
        buttonPanel = new JPanel();
        buttonPanel.setPreferredSize(new Dimension(400, 400));
        buttonPanel.setLayout(new GridLayout(4, 4, 5, 5));
        s1 = 0;
        NumberFormat dblFormat = NumberFormat.getNumberInstance();
        dblFormat.setMinimumFractionDigits(0);
        dblFormat.setMaximumFractionDigits(9);
        dblFormat.setRoundingMode(RoundingMode.HALF_UP);

        t1 = new JFormattedTextField(dblFormat);
        t1.setValue(0);
        t1.addFocusListener(new FocusListener() {

            @Override
            public void focusGained(FocusEvent e) {
                t1.requestFocus();
                t1.setText(t1.getText());
                t1.selectAll();
            }

            @Override
            public void focusLost(FocusEvent e) {
            }
        });
        inputPanel.add(t1, BorderLayout.CENTER);
        clr = new JButton("Clr");
        clr.addActionListener(this);
        buttonPanel.add(clr);
        b1 = new JButton("1");
        b1.addActionListener(this);
        buttonPanel.add(b1);
        b2 = new JButton("2");
        buttonPanel.add(b2);
        b2.addActionListener(this);
        b3 = new JButton("3");
        buttonPanel.add(b3);
        b3.addActionListener(this);
        b4 = new JButton("4");
        buttonPanel.add(b4);
        b4.addActionListener(this);
        b5 = new JButton("5");
        buttonPanel.add(b5);
        b5.addActionListener(this);
        b6 = new JButton("6");
        buttonPanel.add(b6);
        b6.addActionListener(this);
        b7 = new JButton("7");
        buttonPanel.add(b7);
        b7.addActionListener(this);
        b8 = new JButton("8");
        buttonPanel.add(b8);
        b8.addActionListener(this);
        b9 = new JButton("9");
        buttonPanel.add(b9);
        b9.addActionListener(this);
        b0 = new JButton("0");
        buttonPanel.add(b0);
        b0.addActionListener(this);
        sb = new JButton("-");
        buttonPanel.add(sb);
        sb.addActionListener(this);
        ad = new JButton("+");
        buttonPanel.add(ad);
        ad.addActionListener(this);
        ml = new JButton("*");
        buttonPanel.add(ml);
        ml.addActionListener(this);
        dv = new JButton("/");
        buttonPanel.add(dv);
        dv.addActionListener(this);
        eq = new JButton("=");
        buttonPanel.add(eq);
        eq.addActionListener(this);
        setLayout(new BorderLayout(5, 5));
        setPreferredSize(new Dimension(600, 600));
        setLayout(new BorderLayout(5, 5));
        add(inputPanel, BorderLayout.NORTH);
        add(buttonPanel, BorderLayout.CENTER);
        setVisible(true);
    }

and debug that with System.out.println(tested value)

hey i want the attached rmi program to be corrected.............the above code is not in rmi format

Edited 5 Years Ago by Jessurider: n/a

are you done with:

1/ start with calculator view
2/ replace all int to double, in all classes
3/ get number value from JForrmatedTextField

I think that you're shot to the dark, haven't you, because a.m. changes could *** (upTo) half hour

now I'm outta from this thread,

This article has been dead for over six months. Start a new discussion instead.