I have two questions. I'll start by posting my code:
First of all, in my main loop, I'm going to have to access all of my JTextFields. I wanted to put the buildGUI function seperate from the main loop which is good programming practice, but I would have to make all of the TextFields global, which is bad programming practice. Should I leave it like it is or is there a solution to this problem?
Secondly, the program runs fine the way it is now, but if I add a few more columns its starts to lag horribly... What is causing this lag and how do I fix it?
Generally, it is impossible (or at least VERY HARD) to find where the slowdown is by looking at the code. It's almost NEVER where you think it would be. The best way to find it is to get some kind of profiler that will show you where your code is spending all it's time. Then you can focus on that part.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Joined: Apr 22, 2009
Well the fact that the outer loop doesn't break can't be the problem. Even if I have four columns, the code in the loop where the program is spending its time is the same. If I have 8 columns, the code in the loop is still the same. So it doesn't make sense that it's getting slower when its looping through the same code in both situations... any ideas?
I'd say it would definitely slow down your application. Your program will constantly be executing the loop. Although it may not execute any code, it will still check, and check, and check, and check, and check... In other words, your CPU will be very very busy.
But what I'm saying is, even though it checks and checks and checks, the number of checks is going to be the same no matter how many columns there are, because its only checking for one column during the loop. I'll change it so its more efficient in general, but I'm going to guess that the problem with the columns will still apply. I'll post back when I make the changes.