Results 1 to 7 of 7
  1. #1
    xiongling is offline Member
    Join Date
    Apr 2008
    Posts
    3
    Rep Power
    0

    Default How to call the input value from different file?

    I am doing a sever/client chat program. I wish to let the user to enter their entire name through input dialog and I want to use the name that entered by the user in client.java to be use in server.java so that it will shows "username connected to server". I wish to know how to get the username that entered by the user in client to be use in server. Hope anyone can answer me. Thanks.

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    You asking that how to pass a value from one class to the other? I've not clear your question pal.

  3. #3
    xiongling is offline Member
    Join Date
    Apr 2008
    Posts
    3
    Rep Power
    0

    Default

    ya, exactly like wad u say. But the class is in different java file. Able to make it?

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    It's basis in Java. Even you have two Java files(as you say server.java and client.java) there is two classes. To access from one class to the other, in simple word, you need an object of a class in the others.

    So create an object of server class in the client class and using that object call a function of a server class to check the username.

    Is that clear.

  5. #5
    xiongling is offline Member
    Join Date
    Apr 2008
    Posts
    3
    Rep Power
    0

    Default

    sorry, but i don't get u. Coz i m still new to java. Can u write me an example of code of how to make it? Thanks.

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Ok, I'll explain it in simple way as follows.


    Java Code:
    public class Client{
        String username;
        
        // Get the user name through a GUI and set it to username
    
        // Object for class Server
        Server myServer = new Server();
        myServer.isValid(username);
    }
    
    
    public class Server{
       // Check that username is correct
       public void isValid(String name){
            // Check that user name is valid, and so do the process
       }
    }
    Is that clear now, or need more explanations.

    Actually if you don't know how those basis things done, please spend some time with Java fundamentals. If you don't know such things to do, how can you handle a server-client application.

    In a such a project you have to do much more than this, it's not going to be easy for you pal :(

  7. #7
    try
    try is offline Member
    Join Date
    Nov 2007
    Posts
    2
    Rep Power
    0

    Smile I think

    I think, u can use socket or URL class to connect to server and pass parameter values.

    Thanks,
    Guddu
    Java Open Source Utilities Help - ¬*¬*¬* Java Open¬*Source Utility Help

Similar Threads

  1. count character in text file as input file
    By aNNuur in forum New To Java
    Replies: 7
    Last Post: 03-25-2010, 04:01 PM
  2. Taking input from Properties File
    By bugger in forum New To Java
    Replies: 4
    Last Post: 05-07-2008, 09:30 AM
  3. calling another call file
    By Yaya B in forum New To Java
    Replies: 1
    Last Post: 12-21-2007, 06:11 AM
  4. how to call a JAR FILE from HTML
    By leonard in forum Java Applets
    Replies: 1
    Last Post: 08-05-2007, 06:06 AM
  5. How to remove Control Characters from an input file?
    By renjan in forum Advanced Java
    Replies: 0
    Last Post: 08-01-2007, 03:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •