Results 1 to 17 of 17
Thread: problem with java rmi
- 12-30-2011, 11:28 PM #1
Member
- Join Date
- Nov 2011
- Posts
- 24
- Rep Power
- 0
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(); }the remote codeJava 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 problem is that returns me twice --- and of the letter that I putJava 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; }Last edited by _rapt0r_; 12-31-2011 at 04:01 PM.
-
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.
- 12-31-2011, 12:44 PM #3
Member
- Join Date
- Nov 2011
- Posts
- 24
- Rep Power
- 0
Re: problem with java rmi
i don´t understant the restriction validation :s
-
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);
}
- 12-31-2011, 03:41 PM #5
Member
- Join Date
- Nov 2011
- Posts
- 24
- Rep Power
- 0
Re: problem with java rmi
doesn't work :s
-
Re: problem with java rmi
Hmm... so jogar(char x) is being run twice on one click?
- 12-31-2011, 03:54 PM #7
Member
- Join Date
- Nov 2011
- Posts
- 24
- Rep Power
- 0
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 ..
-
- 12-31-2011, 04:05 PM #9
Member
- Join Date
- Nov 2011
- Posts
- 24
- Rep Power
- 0
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
-
Re: problem with java rmi
Are you sure it is returning twice? Or is it your for loop adding the char to output twice?
- 12-31-2011, 04:18 PM #11
Member
- Join Date
- Nov 2011
- Posts
- 24
- Rep Power
- 0
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
-
Re: problem with java rmi
Just to be sure print a String outside the loop to see how many times the method is called.
- 12-31-2011, 04:53 PM #13
Member
- Join Date
- Nov 2011
- Posts
- 24
- Rep Power
- 0
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
-
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 } }
- 12-31-2011, 05:16 PM #15
Member
- Join Date
- Nov 2011
- Posts
- 24
- Rep Power
- 0
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;
-
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?
- 12-31-2011, 05:41 PM #17
Member
- Join Date
- Nov 2011
- Posts
- 24
- Rep Power
- 0
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
-
Problem with Java Web Applications and Java in Control Panel
By Abysinian in forum Advanced JavaReplies: 4Last Post: 03-16-2012, 11:29 AM -
Small problem with problem with Java, C++ parse program.
By dragstang86 in forum New To JavaReplies: 4Last Post: 10-30-2011, 03:43 AM -
Problem Display Jmenubar Java Se6 u23 versus Java SE6 u22
By Ravanelly in forum Advanced JavaReplies: 0Last Post: 01-07-2011, 09:36 AM -
Need help with a Java problem.
By firestarter in forum New To JavaReplies: 2Last Post: 10-04-2009, 12:24 AM -
Java Problem. Need Help!
By bob101 in forum New To JavaReplies: 6Last Post: 03-19-2009, 04:34 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks