In Java,Is it a good practice to make GUI(Swings) using GUI builders or by hand-coding? [duplicate]
Possible Duplicate:
Java, GUI builder or hand coding?
I have been making GUI hand-coded for several apps.But some of my pals 开发者_开发问答are using GUI builders like netbeans IDE.I too tried it recently but the amount of code produced for a simple GUI(around 2 panels,3 text,2 buttons) itself is whooping 500 lines(mines barely 80 lines with some acceptable alignments).My point is, will it make the program slower ?Will it make code maintainability difficult?
I used to generate the GUI code when I was a student. It was quick, I did not have to understand the code. I did not have to debug and/or modify the code. It was perfect for small coursework projects.
Since then I have never used GUI tool to build GUI. We have been coding the GUI code for many years by hand in the company I work for and now I know it is the way to go. Your code is under your control. You can always make someone responsible for the code ("it was not me it was the GUI generator who did this bad code"). You can debug the code, you can better handle its re-usability and scalability. You can adapt the GUI and its functionality perfectly to the customer needs.
The costs may be higher in the beginning, but I believe they pay back later on. Anyway, the choice is up to you or it has already been made by your supervisor. That is life.
Prepare for many opinions!
I think it all depends on the requirements and goals. If your purpose is to learn Swing, then I think you should avoid GUI builders as they hide important details away from you, and the minute you need a GUI that does more than the mere basics, you're up the creek.
On the other extreme, if your goal is rapid prototyping and you're familiar with Swing, then by all means, use a GUI builder.
In between these two extremes the answer varies, and in fact there is no hard and fast yes or no. Code can be maintained as long as the builder's code is not modified outside of the builder itself and its files are not corrupted.
My point is, will it make the program slower?
Probably not, though it depends on what those 500 lines do. I expect that they are mostly concerned with page layout / look-and-feel stuff, and they only get executed when preparing the window to be displayed.
Those 500 lines probably also make the GUI more tailorable by end users and / or make the GUI better at dealing with window resizing, etc ... than your 80 line version.
Will it make code maintainability difficult?
It depends. If use the same IDE / GUI generator to maintain the code as you did to create it in the first place, you should be OK.
For development purposes (i mean commercial development not academic projects), the tools available now are very mature and produce code that is maintainable and readable by human beings. It is perfectly suitable for production code.
A couple of years earlier, i would have recommended you code by hand, but that was a long time ago and the tools have come a long way since then. I use netbeans for building my GUI and its a solid IDE.
Hand written code is sometimes more consice than the generated code (like you pointed out), but the loss of productivity is usually not worth it.
Althought for learning purposes, i would recommend you finish your project by hand to get the experience.
精彩评论