Kevin Simonson

Ranch Hand
+ Follow
since Oct 22, 2011
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
2
In last 30 days
0
Total given
0
Likes
Total received
7
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Kevin Simonson

Carey Brown wrote:


Thanks, Carey! This worked just fine.
11 months ago
I've got two ".pdf" files that are precisely the same size. I suspect they may be identical, but I'm not exactly sure. If you have two files of the same format, and you're not exactly sure what the format is, so the files could have any possible binary values in an arbitrarily large number of bytes, is there a way to open each of the files and compare all the bytes one by one, to find out if the files are identical or not?
11 months ago

Rob Camick wrote:

When you do the rotate the string gets drawn down 250 and to the left 250, so effectively it is painted off the panel.


Thanks! I got my code working the way I like it. I really appreciate the help.
1 year ago

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?
1 year ago

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?
1 year ago

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.
1 year ago
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?
1 year ago
If I do a Google search on "java escape sequences", I get a number of pages like "https://www.golinuxcloud.com/escape-sequence-in-java" that seem to indicate that there are only eight escape sequences, namely "\t", "\b", "\n", "\r", "\f", "\'", "\"", and "\\". But when I wrote the following code:

it became obvious that I can also have "\uxxxx", where (xxxx) are four hexadecimal digits, and I can also have "\0", "\01", "\012", and "\7"; so the list on that website appears to be incomplete. Can anyone tell me where I can find the complete rules on which escape sequences I can use?
1 year ago
I have successfully written a Java program using a {javax.sound.midi.Sequencer} object to make musical sounds. What I want to do now is make a group of sounds (in this case three), and let the user select which of the (three) sounds that user wants to hear, and then have the program play that particular sound. The code I tried is:

When I run this I get:

Why is it telling me this? I called {open()} on each of the three {Sequencer} objects. I don't understand why it's telling me that the sequencer is not open. Can anyone tell me what I'm doing wrong?
1 year ago
This somewhat artificial example shows the problem I'm having. I'd like to throw my custom-made
exception with a string and then have that string returned when I call {getMessage()} in my
exception handler. Here's my code:

When I go to compile it I get:

Does anybody know what I'm doing wrong?
1 year ago

Carey Brown wrote:Have you tried closing the sequencer?


I get the warning before the user provides any input, and I use the sequencer if the user enters an empty string. So by the time I would be able to close the sequencer, I've already gotten the warning.
2 years ago

Ron McLeod wrote:Sounds like this issue: StackOverflow: Java could not open/create prefs error.  The work-around seems to be either run the application once as a user with Administrator rights, or manually create the registry key.


I followed the link you provided. It said: "I was faced this issue on Windows 10 64-bit and was able to resolve the problem by manually creating the following registry key. / HKEY_LOCAL_MACHINE\Software\JavaSoft\Prefs / Hope this helps for the Windows users." I'm not entirely sure what that means. What do I have to do to manually create that key?
2 years ago
I've written a Java program that, each time the user enters an empty string, goes an octave up the scale in half steps. If the user enters any non-empty string, the program terminates.

It works just fine, except that before I enter the first string I get the complaint:

What do I have to do to get rid of this warning? If it's telling me I need to make some changes to my code I'm willing to change it. If there's no way to fix the problem, is there something I can do to suppress the printing of the warning?
2 years ago
What I'd like to do is write a program that plays a scale over one octave every time the user hits the return key by itself. Entering any character before hitting the return key causes the program to end. I tried writing:

but it only plays the scale after I hit the return key the first time; every time after that when I hit the return key I don't hear anything. Anybody know what I'm doing wrong?
2 years ago