File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Too many variables Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Too many variables" Watch "Too many variables" New topic
Author

Too many variables

Gera Levi
Greenhorn

Joined: Jun 07, 2010
Posts: 3
Hi I'm new to this forum, and I've read all over googling about my problem and didn't got lucky...perhaps you can help me out.

well the problem is I believe for most of you guys quite simple, but I'm getting tired:

I have a JFrame with too many TextFields, and an advanced programmer told me that a JButton must not have more than 5 code lines to get best performance.

and in my Button I have loads of setters :P, lets say like 180 variables, so there are like 180 codelines with the setters, because I do the whole process in a java class.

for example: myclass.setMyVariable(Mytextfield.getText()); <--------------like this one, I have over 180 haha, the program works, but I feel it gets somehow laggy...

----Now what I've tried----

thought about sending them in an ArrayList or a String []..... but it's the same story, I would have to put the Mytextfield.getText() again 180 times...and using a "FOR" for that..
well my TextFields are named different... so I couldnt make a FOR that also changes my TextFields names and a position..... so I discarded it.

I've tryied using the jPanel.getComponents() and sending them to a Components[] method in my class. and then managed to separate them and using them, and it worked!
now...the sad story It can get really tricky, and it doesn't work for the inverse, which it would be putting info into the textfields, lets say for an edit option that brings all the info from the
database and put's into the JFrame fields...... only for a virgin JFrame and It doesn't work for me because my frame needs a scrollpane and etc....

So Discarded it...

and Now I'm hopeless, If you guys say there is no other way or that It could be very messy and tricky.....well I guess I should go for investigating a way to put a fancy splashscreen
with a progress bar if my APP get's too laggy with that frame... LOL

I'll wait for an answer, thank you very much!

Roldan Baldo
Ranch Hand

Joined: Aug 11, 2009
Posts: 99
did you try using OOP approach? separate the getter/setter from the JButton to a different class then instantiate it as an object.
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
Gera Levi wrote:I have a JFrame with too many TextFields, ....


I'm not sure what you mean by too many textfields. Are you concerned with the useability of your GUI (a valid concern)? the responsiveness of your GUI (I'm not sure that the number of JTextFields affects this)?

and an advanced programmer told me that a JButton must not have more than 5 code lines to get best performance.

Sorry, but this simply makes no sense at all.


and in my Button I have loads of setters :P, lets say like 180 variables, so there are like 180 codelines with the setters, because I do the whole process in a java class.

This may be a bit difficult to maintain. Later on you mention using an ArrayList, and I like this idea since it should simplify your code greatly.


and Now I'm hopeless, If you guys say there is no other way or that It could be very messy and tricky.....well I guess I should go for investigating a way to put a fancy splashscreen

I'm still not sure what exactly your precise problem is, what's causing it, or what solution you're looking for. If you don't get help from others soon, please have a look here: http://faq.javaranch.com/java/TellTheDetails.

Luck!
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> I have a JFrame with too many TextFields, and an advanced programmer told me that a JButton must not have more than 5 code lines to get best performance.

I'm cooking spaghetti, and a chef told me there should not be more than 2 flavors in ice cream.
Mark E Hansen
Ranch Hand

Joined: Apr 01, 2009
Posts: 650
Well, I'm just throwing a rock into a big pond here (in that I don't really understand what problem you're having), but I have to wonder if what the advanced programmer was talking about had more to do with the amount of time you spend in the button's action event.

For example, if the user clicks the button and the action event take 30 seconds to complete, the application (GUI) will appear unresponsive during that time.

For long-running work, it's better to do that work in a separate "worker" thread and let the event dispatch thread (EDT) get back to managing the application.

There are issues which must be dealt with (like allowing the user to click the button again, or how the application is notified that the work finished, etc.), but it's better to learn/deal with these issues than allow the application to appear to hang while it's doing its work.

Of course, this may be of no help to your actual problem...

Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4658
    
    5

Michael Dunn wrote:
I'm cooking spaghetti

:shock: You cook in GWBasic?
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
nothing like a good 'goto' (or couple of hundred of them)
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4658
    
    5

Michael Dunn wrote:nothing like a good 'goto' (or couple of hundred of them)

http://pinoycook.net/goto-beef-tripe-congee/
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Too many variables