GUI Code Generators

4 minute read

This past summer, I had a project for my Operating System class that required us to write a CPU Scheduling simulator.  The teacher wanted us to also write up a nice GUI for it to display the result for each type of CPU Scheduling Algorithm (i.e. first come first served, round robing, etc.).  How this should be displayed was left for our own imagination so I immediately began to think about how I would go about constructing it and what it would look like.  I also spoke to one other classmate of mine that said I would be ‘wasting‘ my time writing up the GUI on my own when your one can be built for you using your favorite IDE!  Although he was right that it would easier to have the IDE generate the code for the GUI, in my opinion this sort of defeated one of the purposes of the project being able to design something from scratch that would relay the results of your simulation.

Now I  understand that GUI builders are appropriate in certain situations.  For example, when I was learning how to build Windows Forms using Visual Studio I used the built-in form designer to build the GUI’s for my forms as the code that it generates would have taken too much of my time to build on my own.  My biggest gripe about having the GUI generated for you was the feeling of loosing control over the code I was writing, and quite frankly this brought a feeling of uneasiness.  My feelings were what if there was a bug in the generated code (which if you have ever seen any generated GUI code is quite intimidating)?  I felt as if I would be helpless to fix it.  Luckily, there were never any bugs in the generated code that I was aware of but I still just had that feeling that this would come back to bite me in the future.

Going back to my original example, my friend was right in that it would take a while to build the GUI for the project.  But I was determined to build it by hand no matter the cost (in time and effort).  To make sure I didn’t waste my time, I recall how even before I wrote a single line of code for the GUI I spent about an hour or so just visualizing how I wanted the GUI to look like.  For example, I wanted internal tabbed windows that would allow the user to view different results for each data set generated.  This would satisfy one of the many requirements of the project!  Once I had a basic idea (and sketches) of what I wanted to build I then had to familiarize myself with the JFreeChart library and how it would be used in the project!  I need to become familiar with this library not only because I had to display bar charts of my results, but also because I wanted to make sure I know how it would fit in the overall design of m original sketches!

The result of my initial planning and many hours of coding in the hot summer days was a pretty nice GUI.  It was hard work, but in the end I got exactly what I wanted out of the project (both results and grade wise!).  I felt that I had the control needed to make any and every change I needed to do so that I could get a good grade for the project.  The original design of the different kinds of objects (i.e. Processes, DataSet, Algorithms, etc.) and how they were displayed in the GUI (built using Swing) was pretty smooth.  Every time I came up upon a problem, I was able to easily fix it which is something that I think would have been much more difficult if I had let the IDE generate the GUI code!  By the way another reason why I decided to build the GUI by hand was so that I could refresh my memory in building GUI’s in Java.  It was quite fun experience and I am glad I went this route for this project!

Note: I am not saying that GUI builders are a bad thing, but there are times when one must ask him/her self whether or not it’s wise to build it on your own or have the GUI be built by your favorite IDE. Each circumstance is different I assume, and different criteria should be used to decided to either use a GUI builder or not.

Leave a comment