Sophie Bell

Greenhorn
+ Follow
since Oct 23, 2011
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
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 Sophie Bell

Hi all
Well, I just couldn't let go of this problem, and I really wanted to solve it without using any new classes and methods - because I think that was sort of the point of the exercise.
Anyway, here's my new solution. I ran it only a couple of times, but it appears to be working fine .
I realize this is probably not the most efficient (and definitely not the most elegant) way to solve it, but here it is anyway
I couldn't have done it without your help, so thanks again
12 years ago
Unfortunately, I am not familiar with threads and I think the point of the exercise is to make do with the scant tools I have at my disposal. I guess I will give up after all
But thank you all for your help, guys
12 years ago

Campbell Ritchie wrote:I have added code tags. Use spaces, not tabs for indenting.

You would have to show us the details of the pause method for us to know what is going on. The usual way to pause is to use the Thread.sleep() method. Beware: that declares a checked Exception.



I am actually using the pause method from the acm.program package (here's the link: http://jtf.acm.org/javadoc/student/acm/program/Program.html#pause%28double%29 )
12 years ago
Thank you very much, Ralph, I think I understand much better now how to try and resolve this. Although I am not familiar with the timer class, I will try to solve this tomorrow (hope dies last ;))...
12 years ago
Thanks for the reply, Ralph
Unfortunatelly, I am not sure what you mean by a timer (or, in fact, by a "dispatch thread" - nor do I know how to disable user input) ... If it's any excuse, I am a total beginner
But this exercise is from a book I am studying from (The Art and Science of Java, I got to chapter 11 - although this probably doesn't mean anything to you), so I know I should be familiar with all the tools I need to get this right...
Anyway, thanks again
12 years ago
Hi all,
I'm writing a program that plays a simple version of the game of Nim, with 11 coins. When the player presses on any of the last three coins on the screen, that coin all the coins to its right turn red; when the mouse is released, the marked coins should be removed immediately and then the computer makes its move, coloring one, two, or three of the remaining coins yellow, pausing for one second, and finally removing them from the screen. Now, what happens in my implementation is this: instead of pausing after marking the coins the computer is supposed to remove, it appears the execution is paused right after the mouse is released - the red coins remain on the screen for one more second, and then all the coins are removed at once – both the player’s and the computer’s, so that you can’t even see the computer’s coins turning yellow (I hope this is clear enough )
What am I missing here?
Thanks

12 years ago

Thanks, Rob
I love this forum! You are great
12 years ago
Thanks, Tim! It worked
12 years ago
I can't believe I made such a silly mistake...
Thanks, Tim
Although, the program still doesn't work
In fact, it seems this particular mistake had nothing to do with the result
Here's the latest version:

private GImage makeColorNegative(GImage image) {
int[][]array = image.getPixelArray();
for(int row = 0; row < array.length; row++) {
for(int col = 0; col < array[0].length; col++) {
int pixelColor = array[row][col];
array[row][col] = getNegativeColor(pixelColor);
}
}
return new GImage(array);
}

private int getNegativeColor(int color) {
int alpha = ((color >> 24) & 0xFF);
int negRed = ~((color >> 16) & 0xFF);
int negGreen = ~((color >> 8) & 0xFF);
int negBlue = ~(color & 0xFF);
return (alpha << 24) | (negRed << 16) | (negGreen << 8) | negBlue;
}
12 years ago
Hi all,
I'm trying to define a simple method that takes an image and returns its negative. It appears I have some trouble with the method that returns the negative of the pixel color (only black becomes white, but every other color is returned as yellow).
Here's the code:

private GImage makeColorNegative(GImage image) {
int[][]array = image.getPixelArray();
for(int row = 0; row < array.length; row++) {
for(int col = 0; col < array[0].length; col++) {
int pixelColor = array[row][col];
array[row][col] = getNegativeColor(pixelColor);
}
}
return new GImage(array);
}

private int getNegativeColor(int color) {
int alpha = ((color >> 24) & 0xFF);
int negRed = ~((color >> 24) & 0xFF);
int negGreen = ~((color >> 16) & 0xFF);
int negBlue = ~((color >> 8) & 0xFF);
return (alpha << 24) | (negRed << 16) | (negGreen << 8) | negBlue;
}

Thanks
12 years ago