• Post Reply Bookmark Topic Watch Topic
  • New Topic

Swing GUI advice needed

 
Tomasz Pawelczyk
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is my first post on this forum so hi everyone.
I would like to ask for your opinion about this code. It is GUI for small program I want to write.
Is there something I need to change or something what clearly could be writen better?
I could add only that second tab will be a bit bigger than first. Is there any point in splitting this GUI into few classes?
I'm waiting for your opinions. Thank you in advance.

 
K. Tsang
Bartender
Posts: 3604
16
Firefox Browser Java Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

You seem to organize your program pretty good, very clear splitting each section of the main window (frame) into its own methods.

Suggestions:
* you can extend the class making it a JFrame instead of declaring a (instance) variable.


* instance variables in GUI code is only necessary IMHO when multiple methods or inner class (eg anonymous listeners) need them. Try keeping the scope of these as small (local) as possible.

* you xxxPanel() methods can in fact return the actual panel instead of void. The syntax would then look like line line 44 & 45 of your code


* when it comes to GUI design, IMHO if there is a lots of components (panels, menu bars, dialogs, listeners etc) that can possibly "reuse", then having it as a separate class is a good idea. The key is reusability. Another key is to some extend maintainability - changing one class or that section of the GUI "should not" affect the other parts. The disadvantage I see to splitting into classes is you need to understand how each class/component interact. For example: say you have a JTable, does a listener need to update the table model, if so do you need to pass the JTable reference to the listener class or can the listener get the table from some where else.
 
Tomasz Pawelczyk
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your suggestions but I have another questions.
Is there any limit of lines in class which determines if I should split my class or it doesn't matter? Is there such a thing as too big class?
 
K. Tsang
Bartender
Posts: 3604
16
Firefox Browser Java Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Too big class? No, but there is such as a thing a too big methods! How many lines is big? Don't know.

The question to ask is does the method do what it meant to do and nothing else.
 
Tomasz Pawelczyk
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for answers.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!