Ok, I'm trying to transfer a string to an array so i can use each character separatly. I think I've managed that, now I want to output the contents of an array. However, Ive only managed to output the first character of the string.
This is the code I use to transfer string to array:
and this is the code that outputs it to the applet:
I'm guessing te problem is somewhere in here, but I can't think for the life of me where.(bit of a noobie!)
If it helps I can post the rest of the code, its not big at all.
Keith Lynn
Ranch Hand
Joined: Feb 07, 2005
Posts: 2341
posted
0
My guess is that its showing the last character of the String because you display every character in the String at the same x,y position.
Keith Lynn
Ranch Hand
Joined: Feb 07, 2005
Posts: 2341
posted
0
Oops. sorry let me retract that comment. I misread your code.
Jeff Albertson
Ranch Hand
Joined: Sep 16, 2005
Posts: 1780
posted
0
Maybe the real question here isn't about the array but what you are doing with it -- why are you using Graphics method drawChars instead of drawString or java.awt.font.TextLayout? Advancing by character width will not take into account things like kerning which make text layout more pleasing to the eye.
There is no emoticon for what I am feeling!
Ernest Friedman-Hill
author and iconoclast
Marshal
Note also that in those first three lines of code, only the last really does anything -- the char[] you allocate with "new" is discarded and replaced by a new one that you get from calling toCharArray(). There's no need to do the first allocation at all.
im using draw.char because i want to be able to eventually change each character separatly before printing them out collectively, basicallly im trying to write an vigenere encryption applet
Jeff Albertson
Ranch Hand
Joined: Sep 16, 2005
Posts: 1780
posted
0
Originally posted by peter huff: im using draw.char because i want to be able to eventually change each character separatly before printing them out collectively, basicallly im trying to write an vigenere encryption applet
That encryption may lead you to using a String's charAt() method as well as StringBuffer to be a mutable string, but I don't see why you have to use a char array or drawChar.
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.