Help coderanch get a
new server
by contributing to the fundraiser

Daniel Croft

Greenhorn
+ Follow
since Feb 16, 2012
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Daniel Croft

Wow, I can't believe I didn't see that. I guess that's what you get for coding in the middle of the night. Thanks guys
12 years ago
So I'm trying to generate a random long, preferably in the full range between Long.MIN_VALUE and Long.MAX_VALUE. My first (very naive) attempt was "Long.MIN_VALUE + (long) (Math.Random() * (Long.MAX_VALUE - Long.MIN_VALUE + 1));", obviously this didn't work because the calculation overflowed. I eventually got lazy and decided to just use the positive numbers, so I tried "(long) Math.Random()*(Long.MAX_VALUE);" but for some reason this always returns 0. I'd really like to know why this doesn't work and I'd appreciate any ideas on how to accomplish my goal. I thought about using a BigInteger, but this code needs to be speedy. Thanks for your help.
12 years ago
Doh! I didn't realize that was a link. I'll try to trim it down somewhat but it might take a while, it's pretty involved already.
12 years ago
I've tried using Thread.yield(), but that seems to have no effect. I get pretty good results using a sleep of around 14 milliseconds; that seems to keep the fps at 60 and keeps the mouse responsive. It's kind of weird that completely removing the sleep doesn't result in any fps gains though. Also, I'm sorry but I don't know what an SSCCE is :/
12 years ago
So I'm writing a turn based game that involves scrolling a map made of squares which light up as you mouse over them. Everything is drawn on a frame with a 2 buffer strategy. The rendering is done in a separate thread that loops continuously. When I sleep the render thread for a few milliseconds after each frame to push the fps down to around 30, the squares light up very responsively but the scrolling map jitters pretty bad. If I don't sleep the thread, it sits at around 60 fps and the map scrolls really smoothly, but there is noticeable delay between the mouse passing over a square and it lighting up. The code for identifying which square to light is very simple and quick and the processor doesn't seem taxed, so I don't think that the render thread is slowing things down too much. I'm a little stumped as to what is causing the delay, maybe the mouseEvents aren't spawning fast enough? Any ideas would be greatly appreciated as I'm pretty stumped.
12 years ago
It's a security precaution, the idea being that you can restrict the way that those variables are used. For example, you could have a private field with only a getter and no setter; this would stop people from setting the variable to null. If it's not a private field, then it can be set to null by part of the code with appropriate access.
12 years ago
The string[] on line 21 should be a capital "S", so String[] rateTerm = {"7 years","15years","30 years"};
12 years ago
Here's some code from a game that I'm currently writing, you might find it helpful. It uses a two buffer strategy and blits between them to avoid tearing. It also uses active rendering instead of waiting for repaint events which should help you control the frame rate. It keeps track of the frame rate, so that should help you make sure it's fast enough; just set the RenderThread.sleep() to 8 or 4 like rob said.

12 years ago
Well right off the bat, at line 66 you're setting lblJlabela to null then trying to set an icon for it. This is obviously going to give you a null pointer exception. You want to make your jlabels into member variables of the class since you're accessing them from multiple functions; instead of declaring them in main, you should declare them at the top of your class where you declared frame.
12 years ago
After some trial and error, I finally found that the problem was fixed by the update from 1.5.0_22 -> 1.6.0. I don't know if this might help anyone figure out how I might run my code on 1.5 but I'm still looking for a solution and any help would be appreciated.
12 years ago
I'm afraid I don't know all that much about it, having never used it personally. But I've got to get my two cents in here anyway ;).

StackOverflow

^ This is a pretty good explanation. As I understand it, it has to do with sending a serializable object through streams or over the network. I think it has something to do with persistence too but I'm not sure. Chances are, if you're not doing either of those things, you can just ignore it and add an annotation to suppress the warning.
12 years ago
Yeah, he has umm... 10.5.8 I think. I looked it up and I found 1.6 for it, but it was only for the 64bit version :/
12 years ago
Good catch on the more than 6 digits part. You're right, the .* after it allows this thing to accept more than 6 digits, although his specs don't technically disallow this. As for the negative lookahead, I sort of chopped that out of a Google search, but it was the best I could find on short notice; I suspect there's probably a better way.
12 years ago
No problem, glad I could help. Google always links me to this site; it's so useful I figured it was about time I started giving back.
12 years ago
Haha, yeah. I don't think I'm that committed. I originally installed 1.5.0, and there were 22 updates until 1.6. I guess I could just try to narrow down where it breaks by downloading a few more JREs, maybe then I'd stand a chance.
12 years ago