• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Too many variables

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!

 
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
did you try using OOP approach? separate the getter/setter from the JButton to a different class then instantiate it as an object.
 
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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!
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
> 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.
 
Ranch Hand
Posts: 650
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...

 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Michael Dunn wrote:
I'm cooking spaghetti


:shock: You cook in GWBasic?
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
nothing like a good 'goto' (or couple of hundred of them)
 
Darryl Burke
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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


http://pinoycook.net/goto-beef-tripe-congee/
 
You can't have everything. Where would you put it?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic