Runs fast inside Eclipse, slow as runnable JAR [message #1008132] |
Sun, 10 February 2013 18:10 |
Chris Crawford Messages: 7 Registered: January 2012 |
Junior Member |
|
|
I'm a long-time, very simple-minded programmer who uses perhaps 10% of the capabilities of Eclipse; I've been using Eclipse for maybe five years now and have assiduously avoided learning anything that I don't need. I've been exporting projects to runnable JAR files for years with no problems. But I have run into a nasty little issue. I don't know if it's an Eclipse problem or a Java problem. I'm running on a Mac Pro, OS 10.7.5.
I have some big images (128w by 128h) that I'm treating as simple graphics objects rather than JButtons, for complicated reasons. I need to replicate SOME of the behavior of JButtons, including the redrawing of the image when the pseudo-button is pressed. This is handled with a very simple bit of code inside the mousePressed() method of the Mouse Listener:
int i=0;
boolean gotcha=false;
while ((i<cButtons)&(!gotcha)) {
if (buttons[i].fEnabled) {
Rectangle test=new Rectangle(buttons[i].x,buttons[i].y,faceWidth,faceHeight);
if (test.contains(e.getX(), e.getY())) {
gotcha=true;
buttons[i].fPressed=true;
repaint(buttons[i].x,buttons[i].y,faceWidth,faceHeight);
}
}
++i;
}
The value of cButtons is 16, so the loop executes a maximum of 16 times; in this test case, only seven buttons get past the first if-test. faceWidth and faceHeight are equal to 128.
When I run the program inside Eclipse, everything runs just fine, but when I export it to a Java runnable file, with "Package required libraries into generated JAR", and run the result, I get a problem: the buttons blink. That is, the repainting process takes so long that erasing the background takes an entire frame jiffy and drawing the button takes more than one frame jiffies. It gets worse: the length of the blink is visibly concomitant with the position of the button in the array. That is, the first three buttons on the screen are drawn without blinks, the fourth has a very short blink, the fifth a visibly longer blink, and the sixth even longer. In other words, this code is requiring at least 5 milliseconds per loop iteration, and possibly as much as 20 milliseconds per loop iteration. That's ridiculous! This is running on a Mac Pro with two 2.66 GHz dual-core processors and over 3 GB of free RAM according to the Activity Monitor.
Why is it running so slowly as a runnable JAR when it runs so fast inside Eclipse? We'd expect that Eclipse would slow it down, if anything. I fear that my problem lies in some magical incantation I have to perform with Eclipse to tell it to prepare the final code in a manner that runs quickly.
Any suggestions as to what I'm doing wrong?
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.07733 seconds