This week's book giveaway is in the Programmer Certification forum.
We're giving away four copies of OCP Oracle Certified Professional Java SE 21 Developer Study Guide: Exam 1Z0-830 and have Jeanne Boyarsky & Scott Selikoff on-line!
See this thread for details.

Eric Chang

Ranch Hand
+ Follow
since Jan 27, 2004
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Eric Chang

So let's say I have a Java application that allows for the drawing of scribbles. However, the way I store the scribbles in memory is by turning the scribble into line segments and storing the two points of each line segment (thereby not actually storing every single pixel coordinate into memory).
Now, I have to be able to erase that scribble...does anyone have any fancy ideas on how this can be done within Java that is efficient. I've thought about turning the scribble back into it's pixel-by-pixel form and working from there, but it seems like the refreshing and redrawing of it is pretty inefficient and quite flickery.
I'm open to suggestions from those that might have a much better idea on this than I do.
Thanks!
12 years ago
Just from a quick look, you appear to want to add lastValue to the container when you set lastValue to currentValue. container never contains the very first value (ie: 10) because you never add it.
15 years ago
So I've got this problem where I have shape (say a pie-shaped arc) and another shape (say an ellipse), and I want to find out if they overlap. However, not only so I need to find out if they overlap, I need to see if the area that the overlap occurs is more than a third shape (say another pie-shaped arc) and the ellipse.
Anyone have any ideas on how I'd go about implementing this?
15 years ago
Thanks for the tips! I'll check it out.
16 years ago
I have this bit of .NET code that I believe does what I'm looking to do, but I don't know where to start in terms of converting the functionality into a Java method:

16 years ago
Oh right, I forgot to add that part...yes, I would want to convert it to a png also.
16 years ago
Is there a way in Java to convert the following jpg image:
here

into a transparent png by making a color (say...black?) transparent? I have little to no familiarity with anything dealing with manipulating imagery in Java. Any tips on where to start looking?
16 years ago
Hahah, yeah I was planning on making those assumptions if I went crazy trying to deal with the fact that the earth is not a perfect sphere.

So maybe a little bit more background is needed to get the best solution...I'm writing a tool that will generate Flight Plan scenarios where my "planes" will be flying aimlessly in circles. So that is why I need my points in lat/lon format (degrees or DDMMHHSS...doesn't matter since I can convert those easily).
So the tool will ask the user for the number of points that make up the circle (or rather, the number of "reports" the radar gets for the plane as it goes around in the circle) as well as the center point and the radius.
I guess those assumptions are fine since it doesn't have to be a perfect circle on a curved surface.
16 years ago
So I have no idea if this is the proper forum for this questions...but I'll give it a shot.
Lets say I am given a center point (as a Latitude/Longitude) and a radius in some unit (let's say km). And I'm also given a number of points to make up the circle (say 100). How the hell would I calculate the location of the points on the circle? And to make it more difficult (but this part isn't absolutely necessary I suppose), we are talking about a circle on the Earth, which means you wouldn't actually have a perfect circle without factoring in the curvature of the the earth, etc.
16 years ago
I finally figured it out (I guess a weekend of not staring at it in frustration helps).
It turns out that it was a Threading issue...I had created the socket in one thread and sent it into another one.
So this problem is driving me crazy. I have one little program where I open a Socket, send a byte for 'P' and then do a readLine...this works perfectly fine 100% of the time.

I now have a different program where I've put the bit of working code to get the data from a server (from my other program) which is part of a much larger system. I SEEM to do the send ok (no exceptions), but as soon as the readLine() gets called, I get the following:

java.net.SocketException: Software caused connection abort: recv failed
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(Unknown Source)
at sun.nio.cs.StreamDecoder.readBytes(Unknown Source)
at sun.nio.cs.StreamDecoder.implRead(Unknown Source)
at sun.nio.cs.StreamDecoder.read(Unknown Source)
at java.io.InputStreamReader.read(Unknown Source)
at java.io.BufferedReader.fill(Unknown Source)
at java.io.BufferedReader.readLine(Unknown Source)
at java.io.BufferedReader.readLine(Unknown Source)

Here's the two methods that get called (Note: getOutputStream() and getInputStream() get the i/o stream of the open socket:



So in one case, it works fine...in the other case, it never works...with practically the exact same code. I have a feeling I'm missing something blatantly obvious, but I don't know what to look for or where to start.
Any ideas?
Yes, I understand why the piping doesn't work, however the tutorial didn't explain why just doing "lpr filename.txt" didn't work either...unless I'm guessing that the fact that lpr takes in arguments is the same problem as piping to a file.
I will scour that tutorial again to see if I missed something more.

Fake Edit: Yeah, that's exactly what it is...nevermind.

[ September 30, 2008: Message edited by: Eric Chang ]
[ September 30, 2008: Message edited by: Eric Chang ]
16 years ago
OK, so I had asked a question a few months ago about running a script on a Sun box and the answer was to use something along the lines of:

Process exec = Runtime.getRuntime().exec("script");

Now, I'm attempting to execute the following command:

postprint filename.tmp | lpr

through Java...and no matter how I do it using the above, I cannot get it to execute, yet when I do it just on the command line, it works fine.
I read some of what's here and saw there there might be an issue with me piping the output into lpr, so I tried using just lpr, and that didn't work either.
Anyone have any ideas why this might be failing?
16 years ago
Nevermind, I figured it out. The solutions you both gave sparked me to think about just using readByte and then reading each byte into an ArrayList until I reach the ETX ASCII character (byte = 3), and then printing out what I have.
Thanks again!
16 years ago
OK, both seem like good solutions, however, I don't think I can use either because the server I am using is actually just a unit test stub, whereas the actual application that will be receiving the messages will not be able to deal with either a readInt() call before or the "\n" character.
HOWEVER, I do frame each String with the SOH and ETX ASCII characters, so perhap on the server-side (the test stub) I could do something with those? Or maybe NOT use the BufferedReader and instead go back to a DataInputStream and read each byte individually until I find the byte for /\0?
I appreciate the help.
[ June 27, 2008: Message edited by: Eric Chang ]
16 years ago