0

I am new to java programming. I am trying to create a GUI which includes JLabels, JPanels, JButton, text fields and labels. I am not using layout manager. Is there a particular structure in laying out the code that I should follow.? Thanks

.

3
Contributors
2
Replies
4
Views
5 Years
Discussion Span
Last Post by JamesCherrill
0

The code to create a GUI is always a long long list of repetitive add/set method calls - people often use a GUI design tool to generate them. It really doesn't have a structure. The only thing you can do is to put it all in a simple method, eg private void createGUI() so it don't clutter up or confuse the rest of your logic.
I recommend using anonymous inner classes to handle events (mouse clicks etc) - the very first one is a bit of a learning curve, but after that it's just copy/paste. The beginner's technique of making your main class the event handler is a dead-end that doesn't scale at all well for the future.

Unless you have some very special requirement, not using a layout manager is a big mistake.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.