Results 1 to 17 of 17
  1. #1
    _rapt0r_ is offline Member
    Join Date
    Nov 2011
    Posts
    24
    Rep Power
    0

    Default problem with java rmi

    I have a text box when I press a button it sends me a letter in character to a remote method in another class
    Java Code:
    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {                                         
            
                // TODO add your handling code here:
                    String leter = aposta.getText();
                    char x = leter.charAt(0);
            try {
                ridle(x);
            } catch (NotBoundException ex) {
                ex.printStackTrace();
            }
    Java Code:
    public void ridle(char leter) throws NotBoundException {
      
         Forca fr = null;
              System.setProperty("java.security.policy", "C:/Users/koo/Documents/NetBeansProjects/JavaApplication3/src/javaapplication3/security.txt/");
    		
    
    		String servicename = "hangman" ;
    
    		//Inicializar security manager
            if (System.getSecurityManager() == null) {
                System.setSecurityManager(new SecurityManager());
            }
            try {
                            Registry registry = LocateRegistry.getRegistry(Ip);
               
                    fr = (Forca) registry.lookup(servicename);
                
                
                            
                            xx = fr.jogar(leter);
                         
            } catch (RemoteException ex) {
                Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ex);
            }
            
     }
    the remote code

    Java Code:
     public String jogar(char x) throws RemoteException {
    
            System.out.println ("numero de"+ palavra.length());
            
            char formaPalavra[] = new char[palavra.length()];
            String apresentaPalavra="\0";
    
            for(int y = 0; y < palavra.length(); y++){
                System.out.println ("numero de"+ palavra.length());
                formaPalavra[y] = '_';
                apresentaPalavra += formaPalavra[y] + " ";
                }
    
            
            for(byte i = 0; i < palavra.length();i++){
                System.out.println ("numero de"+ palavra.length());
                    if(String.valueOf(palavra.charAt(i)).equalsIgnoreCase(Character.toString(x))){
                         formaPalavra[i] = palavra.charAt(0); //converte de String para char
             apresentaPalavra += formaPalavra[i] + " ";
            }else{
            apresentaPalavra += formaPalavra[i] + " ";
                 }
               //apresentaPalavra2 = apresentaPalavra;
      
            
            
        }
            return apresentaPalavra;
        }
    the problem is that returns me twice --- and of the letter that I put
    Last edited by _rapt0r_; 12-31-2011 at 04:01 PM.

  2. #2
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default Re: problem with java rmi

    This site is so dam buggy I posted an answer twice and both times it lost my answer. I cant be bothered to write it all over again but you need to add in a time restriction validation so that you cant 'double-post' within that time period.

  3. #3
    _rapt0r_ is offline Member
    Join Date
    Nov 2011
    Posts
    24
    Rep Power
    0

    Default Re: problem with java rmi

    i donīt understant the restriction validation :s

  4. #4
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default Re: problem with java rmi

    private long lastUpdate=0;
    private final long quietTime = 5*1000; //5secs

    public void jButton3ActionPerformed(java.awt.event.ActionEvent e) {
    if (!isReady()) return;
    lastUpdate = Calendar.getInstance().getTimeInMillis();
    //code
    ...
    }

    private boolean isReady() {
    return (Calendar.getInstance().getTimeInMillis()-lastUpdate >= quietTime);
    }

  5. #5
    _rapt0r_ is offline Member
    Join Date
    Nov 2011
    Posts
    24
    Rep Power
    0

    Default Re: problem with java rmi

    doesn't work :s

  6. #6
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default Re: problem with java rmi

    Hmm... so jogar(char x) is being run twice on one click?

  7. #7
    _rapt0r_ is offline Member
    Join Date
    Nov 2011
    Posts
    24
    Rep Power
    0

    Default Re: problem with java rmi

    I think the problem is there, but would only go once the method and return the result once. and always run this method only when I find matching in jbutton ..

  8. #8
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default Re: problem with java rmi

    Quote Originally Posted by _rapt0r_ View Post
    I think the problem is there, but would only go once the method and return the result once. and always run this method only when I find matching in jbutton ..
    i'm sorry i couldnt make much sense of that.

    but 'always run this method when...' what?

    Is there some more code which causes this method to run automatically?

  9. #9
    _rapt0r_ is offline Member
    Join Date
    Nov 2011
    Posts
    24
    Rep Power
    0

    Default Re: problem with java rmi

    the method donīt run automatically, he runs when I run this button..

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {

    // TODO add your handling code here:
    String leter = aposta.getText();
    char x = leter.charAt(0);
    try {
    ridle(x);
    } catch (NotBoundException ex) {
    ex.printStackTrace();
    }

    I no longer have any code running jogar(char x) method, only the code in my first post

  10. #10
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default Re: problem with java rmi

    Are you sure it is returning twice? Or is it your for loop adding the char to output twice?

  11. #11
    _rapt0r_ is offline Member
    Join Date
    Nov 2011
    Posts
    24
    Rep Power
    0

    Default Re: problem with java rmi

    i donīt no, I've seen for the loop several times and can not see what the error: S

    See this line?? System.out.println ("numero de"+ palavra.length()); return the number of letters

    if the word is "play" and a put a "p" see the output


    numero de4
    numero de4
    numero de4
    numero de4
    numero de4
    numero de4
    numero de4
    numero de4
    numero de4

  12. #12
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default Re: problem with java rmi

    Just to be sure print a String outside the loop to see how many times the method is called.

  13. #13
    _rapt0r_ is offline Member
    Join Date
    Nov 2011
    Posts
    24
    Rep Power
    0

    Default Re: problem with java rmi

    }
    System.out.println ("the number of request"+ palavra.length());
    return apresentaPalavra;
    }

    output
    the number of request3

    you're right, but do not see the problem in the code: S

  14. #14
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default Re: problem with java rmi

    Ok so lets look at your loop...

    You have a search feature like this...
    if (char y).equals(char x)

    But if you find a match, you did not break the loop,
    That allows there to be more than 1 result returned.

    if you only want 1 result, you can take the first result only,
    By breaking the loop like this:
    Java Code:
    for (...) {
      if (found) {
        //add to output
        ...
        break;
      else {
        //do something else
      }
    }

  15. #15
    _rapt0r_ is offline Member
    Join Date
    Nov 2011
    Posts
    24
    Rep Power
    0

    Default Re: problem with java rmi

    already improved, but now I put a word with 3 and 4 returns


    for(byte i = 0; i < palavra.length();i++){
    System.out.println ("numero de"+ pala.length());
    if(String.valueOf(pala.charAt(i)).equalsIgnoreCase (Character.toString(x))){
    formaPalavra[i] = pala.charAt(0); //converte de String para char
    apresentaPalavra += formaPalavra[i] + " ";
    break;
    }else{
    apresentaPalavra += formaPalavra[i] + " ";
    }
    break;

  16. #16
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default Re: problem with java rmi

    Huh? So if you dont want to print anything else why are you adding stuff to output in your first loop?

    Did you write any of this code yourself?

  17. #17
    _rapt0r_ is offline Member
    Join Date
    Nov 2011
    Posts
    24
    Rep Power
    0

    Default Re: problem with java rmi

    yes i write this code.. i found the problem
    for(int y = 0; y < pala.length(); y++){
    System.out.println ("numero de"+ pala.length());
    formaPalavra[y] = '_';
    apresentaPalavra += formaPalavra[y] + " ";
    break;
    }

    for(byte i = 0; i < palavra.length();i++){
    System.out.println ("numero de"+ pala.length());
    if(String.valueOf(pala.charAt(i)).equalsIgnoreCase (Character.toString(x))){
    formaPalavra[i] = pala.charAt(0); //converte de String para char
    apresentaPalavra += formaPalavra[i] + " ";
    break;
    }else{
    apresentaPalavra += formaPalavra[i] + " ";
    }
    break;

    so I needed a break more..

    tks for the help

Similar Threads

  1. Replies: 4
    Last Post: 03-16-2012, 11:29 AM
  2. Small problem with problem with Java, C++ parse program.
    By dragstang86 in forum New To Java
    Replies: 4
    Last Post: 10-30-2011, 03:43 AM
  3. Problem Display Jmenubar Java Se6 u23 versus Java SE6 u22
    By Ravanelly in forum Advanced Java
    Replies: 0
    Last Post: 01-07-2011, 09:36 AM
  4. Need help with a Java problem.
    By firestarter in forum New To Java
    Replies: 2
    Last Post: 10-04-2009, 12:24 AM
  5. Java Problem. Need Help!
    By bob101 in forum New To Java
    Replies: 6
    Last Post: 03-19-2009, 04:34 AM

Posting Permissions

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