Hi..I basically new wit java.
i have a program called Transfer.java..n when i press button caleed "start Transfer" it executes FileServer.java

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.Random;
import java.util.*;
import java.text.*;
import java.rmi.*;

class transfer extends JFrame implements ActionListener, Runnable
{
    JButton btntrans,btnexit;
    ImageIcon bc;
    JLabel lbltitle ,label1;
    JTextField text1;
     Thread t;

     public transfer()
 {
 	setSize(800,570);
	setTitle(" FILE TRANSFER ");

	
	
	/*bc=new ImageIcon("1.jpg");*/
		
       lbltitle= new JLabel(bc);	
       label1 = new JLabel();
       label1.setFont(new Font("Serif", Font.BOLD, 28));
       label1.setForeground(Color.black);
       label1.setOpaque(true);	
       label1.setText("ip Address:");
	
        text1 = new JTextField(20);

	btntrans=new JButton(" Start Transfer");
        btnexit=new JButton("Exit");


	Container cp=getContentPane();
	cp.setLayout(null); 

	//cp.setBackground(Color.white);
	Insets ins=getInsets();

	label1.setBounds(40,100,150,50);
        text1.setBounds(200,100,280,50);
	btntrans.setBounds(40,300,150,50);
        btnexit.setBounds(40,400,150,50);
         
	lbltitle.setBounds(0,0,850,570);
	//lbltitle.setBounds(220,20,130,104); 

	btntrans.addActionListener(this);
	btnexit.addActionListener(this);
        text1.addActionListener(this);
		
	cp.add(btntrans);
	cp.add(btnexit);
        cp.add(lbltitle);
	cp.add(label1);
	cp.add(text1);

	//cp.setBackground(Color.blue);
     
	
  }


public void run()
{

  try
      {
               		 
          while(t.isAlive())
           {		
	Thread.sleep(1000);
	
	File f = new File("check/test.jpg");
	 if(f.exists())                  
	{
                    

	   String fname = f.getAbsolutePath();

                   FileInputStream instream = new FileInputStream(fname);

	int insize = instream.available();

	byte inBuf[] = new byte[insize];

                 int bytesread = instream.read(inBuf,0,insize);
	instream.close();
		                     	
		
 
                  }                    

            }
       }
         catch(Exception e)
         {
             System.out.println(e);
        }


}

public void actionPerformed(ActionEvent ae)
  {

	String value1=text1.getText();
				
	if(ae.getSource() == btntrans)
	{
 
        
 try {
         FileInterface fi = new FileImpl("FileServer");
         Naming.rebind("//192.168.1.2/FileServer", fi);
      } 
         catch(Exception e) {
         System.out.println("FileServer: "+e.getMessage());
         e.printStackTrace();
      }

        }

 	else
	{
		System.exit(0);
	}
}
     public static void main(String args[])
  {
 	transfer t=new transfer();
	t.show();
  }
}

Now i need to take IP adress from user & pass it to Naming.rebind("//192.168.1.2/FileServer", fi); instead of 192.168.1.2.
the ip adress is stored in Value1.
how do i pass tht value to Naming.rebind("//192.168.1.2/FileServer", fi); * i need user input ip adress instead of 192.168.1.2.
thanx fr any kind of assistance in advance

Most simple without any checks for entry validity will be Naming.rebind(text1.getText()) . More complex with validation will do more less same Naming.rebind(validate(text1.getText())) where you send what ever retrieved from user to validation method that will check that string is in appropriate format (4 sets of numbers berween 0-255)

Comments
Useful, concise help, besides, sandyben did not mark the thread as solved...

hey even

Naming.rebind("//"+value1+"/FileServer", fi);

also works...
since am storing the textbox value in Value1

String value1=text1.getText();

bt thnks fr d reply.. :)

Edited 6 Years Ago by peter_budo: Please use [code][/code] instead of [quote][/quote] to post any amount of code in your post

Instead of using this

String value1=text1.getText();

you should use setter and getter methods.

setIP(text1.getText());
//do not forget value1 declaration at the start of your code
//as private String value1;

private void setIP(String string){
    value1 = string;
}

public String getIP(){
    return value1;
}

Hi..I basically new wit java.
i have a program called Transfer.java..n when i press button caleed "start Transfer" it executes FileServer.java

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.Random;
import java.util.*;
import java.text.*;
import java.rmi.*;

class transfer extends JFrame implements ActionListener, Runnable
{
    JButton btntrans,btnexit;
    ImageIcon bc;
    JLabel lbltitle ,label1;
    JTextField text1;
     Thread t;

     public transfer()
 {
 	setSize(800,570);
	setTitle(" FILE TRANSFER ");

	
	
	/*bc=new ImageIcon("1.jpg");*/
		
       lbltitle= new JLabel(bc);	
       label1 = new JLabel();
       label1.setFont(new Font("Serif", Font.BOLD, 28));
       label1.setForeground(Color.black);
       label1.setOpaque(true);	
       label1.setText("ip Address:");
	
        text1 = new JTextField(20);

	btntrans=new JButton(" Start Transfer");
        btnexit=new JButton("Exit");


	Container cp=getContentPane();
	cp.setLayout(null); 

	//cp.setBackground(Color.white);
	Insets ins=getInsets();

	label1.setBounds(40,100,150,50);
        text1.setBounds(200,100,280,50);
	btntrans.setBounds(40,300,150,50);
        btnexit.setBounds(40,400,150,50);
         
	lbltitle.setBounds(0,0,850,570);
	//lbltitle.setBounds(220,20,130,104); 

	btntrans.addActionListener(this);
	btnexit.addActionListener(this);
        text1.addActionListener(this);
		
	cp.add(btntrans);
	cp.add(btnexit);
        cp.add(lbltitle);
	cp.add(label1);
	cp.add(text1);

	//cp.setBackground(Color.blue);
     
	
  }


public void run()
{

  try
      {
               		 
          while(t.isAlive())
           {		
	Thread.sleep(1000);
	
	File f = new File("check/test.jpg");
	 if(f.exists())                  
	{
                    

	   String fname = f.getAbsolutePath();

                   FileInputStream instream = new FileInputStream(fname);

	int insize = instream.available();

	byte inBuf[] = new byte[insize];

                 int bytesread = instream.read(inBuf,0,insize);
	instream.close();
		                     	
		
 
                  }                    

            }
       }
         catch(Exception e)
         {
             System.out.println(e);
        }


}

public void actionPerformed(ActionEvent ae)
  {

	String value1=text1.getText();
				
	if(ae.getSource() == btntrans)
	{
 
        
 try {
         FileInterface fi = new FileImpl("FileServer");
         Naming.rebind("//192.168.1.2/FileServer", fi);
      } 
         catch(Exception e) {
         System.out.println("FileServer: "+e.getMessage());
         e.printStackTrace();
      }

        }

 	else
	{
		System.exit(0);
	}
}
     public static void main(String args[])
  {
 	transfer t=new transfer();
	t.show();
  }
}

Now i need to take IP adress from user & pass it to Naming.rebind("//192.168.1.2/FileServer", fi); instead of 192.168.1.2.
the ip adress is stored in Value1.
how do i pass tht value to Naming.rebind("//192.168.1.2/FileServer", fi); * i need user input ip adress instead of 192.168.1.2.
thanx fr any kind of assistance in advance

Excellent Post. I hope the java Members will be greatly appreciated by this code.

Edited 6 Years Ago by gerdonhanry: n/a

This question has already been answered. Start a new discussion instead.