If I extend (JPanel) and in my (paintComponent()) method I call (drawString()) on a (Graphics) object, I can pass in a (String) object as my first parameter and cause that (String) object to be printed horizontally in my (JPanel) window. Is there a way to print that (String) object vertically instead of horizontally? I need to switch each of the characters in the (String) object so that they occur one on top of the other instead of horizontally next to each other, and I also need to rotate each of the characters ninety degrees. Does anybody know how to do that?
By chance, I have an age-old piece of code around that does exactly that. Well, it also writes an image file with the result, but to do that it needs to tweak the Graphics2D to begin with.
The way I would do it requires a second Graphics object. I have had difficulty with Graphics objects when I apply an affine transform to them; it doesn't seem to reverse properly. It is usually shear() that causes problems; translate() and scale() can usually be reversed.Graphics#create() method. Graphics2D#rotate() method.
Carey Brown wrote:Kevin, can you provide a screen snapshot as to how you expect it to look. From your description I'm guessing (?) you want:
A
B
C
and not just ABC rotated 90 degrees.
I don't know how to provide a screen snapshot; I was hoping on using the Java interpreter to display it, and I can't figure out how to do that; I don't know any other way to display it. But in response to your guess, I actually do not want
A
B
C
instead I do want ABC rotated 90 degrees.
Campbell Ritchie wrote:The way I would do it requires a second Graphics object. I have had difficulty with Graphics objects when I apply an affine transform to them; it doesn't seem to reverse properly. It is usually shear() that causes problems; translate() and scale() can usually be reversed.Graphics#create() method. Graphics2D#rotate() method.
Campbell, using what you said I wrote:
Then when I ran it with
I got a large (JFrame) window with "DsgRot Cube_15_10.0" in the upper left corner, but nothing actually appeared in the window; it's all completely white. Any idea what I'm doing wrong?
Campbell Ritchie wrote:The way I would do it requires a second Graphics object. I have had difficulty with Graphics objects when I apply an affine transform to them; it doesn't seem to reverse properly. It is usually shear() that causes problems; translate() and scale() can usually be reversed.Graphics#create() method. Graphics2D#rotate() method.
Actually, let me make it easier. I tried:
And then I executed "java Ritchie", and got a window with a white strip on top with an icon and "Ritchie" on the left, and then underneath it I got an apparently 500 pixel by 500 pixel square that was completely gray; there's no trace of a green "Campbell is brilliant" anywhere near the center of the square where it should have appeared. Once again, what am I doing wrong?
I forgot that rotation is around the (0, 0) point, so you would want to translate it by (width / 2, height / 2) (or similar) to move the origin to the centre of the display.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.