This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
I have this code for Caesar cipher implementation, which works fine, but when I adapt it for my code it is not working.
Here is my class:
I suppose it is a problem with String conversion, it is showing only the last character,
but why it is working in Console, then ? How do I make it to work in TextArea, as well ?
Could someone please help me with this ? Thank You!
Because in the first one you're printing out each character. In the last one you just get the current character.
I think if you're writing Swing apps but don't know how to build a string the learning is happening backwards... Maybe search the web for "java string concatenation".
Nicol Green
Ranch Hand
Joined: Jan 30, 2010
Posts: 66
posted
0
Thanks for quick response!
I know how to do concatenation. I was just asking for opinion how to do it maybe on another way in this case.
Thanks, anyway.
Well, you're trying to build a string character-by-character. Since Java Strings are immutable, there'd be the overhead of a new string *somewhere* in the process.
Nicol Green
Ranch Hand
Joined: Jan 30, 2010
Posts: 66
posted
0
Ok, I see.
But is there any way to adapt this code written for console to work as I wanted for Swing ? Or it is not possible to work on this way ?
Some way to gather currents to string, or with type cast ?
You said you knew how to concatenate strings--so concatenate away!
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32704
4
posted
0
Why are you using == to check Strings for equality?
Would the StringBuilder class help?
Nicol Green
Ranch Hand
Joined: Jan 30, 2010
Posts: 66
posted
0
Hi Ritchie!
Thank You for reply!
I am using == because I am checking which item is selected in Combo box.
In Combo box I have a few types of encryption algorithms and one of them is Caesar.
I just read description about of String Builder class, and will give it try!
Nope. You're still using the == operator to attempt to compare the contents of two strings. Don't do that. Use the equals() method of either of the two.
Nicol Green
Ranch Hand
Joined: Jan 30, 2010
Posts: 66
posted
0
Now I see what you mean, it is beginning Java mistake..
Thanks!
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.