| | |
Java GUI design
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Oct 2007
Posts: 2
Reputation:
Solved Threads: 0
Hiya!
I've got a problem writing GUI's. Basically the design portion in code.
What I've done is I've broken the GUI components into seperate classes, for example:
and all the parent widgets are composed of the smaller widget items, like this:
As you can see, adding FileMenuNewItem to FileMenu requires just a single line of code, all the actual code that composes the look and operations of the "new file" menu item is contained in the class FileMenuNewMenuItem...
I feel it's too much bloat...
Can someone suggest a better method of writing easy to maintain/extend GUI's?
Thanks!
I've got a problem writing GUI's. Basically the design portion in code.
What I've done is I've broken the GUI components into seperate classes, for example:
Java Syntax (Toggle Plain Text)
//custom menu bar public class MyMenuBar extends JMenuBar { ... } //custom generic menu. all //look-and-feel is set //here i.e. fonts etc public class MyMenu extends JMenu { ... } //the file menu public class FileMenu extends MyMenu { ... } //custom generic menu item. all //look-and-feel is set here. //i.e. fonts, tearable etc public class MyMenuItem extends JMenuItem { ... } //the "new file" menu item public class FileMenuNewMenuItem extends MyMenuItem { ... }
and all the parent widgets are composed of the smaller widget items, like this:
Java Syntax (Toggle Plain Text)
//MyMenuBar is composed of menus public class MyMenuBar extends JMenuBar { //members private FileMenu fileMenu; //default constructor public MyMenuBar() { //create file menu fileMenu = new FileMenu(); //add file menu to menu bar this.add(fileMenu); } } //File menu is composed of menu items public class FileMenu extends MyMenu { //members private FileMenuNewMenuItem newItem; //default constructor public FileMenu() { //set text and mnemonic super("File",'F'); //create new file menu item newItem = new FileMenuNewItem(); //add to menu this.add(newItem); } }
As you can see, adding FileMenuNewItem to FileMenu requires just a single line of code, all the actual code that composes the look and operations of the "new file" menu item is contained in the class FileMenuNewMenuItem...
I feel it's too much bloat...
Can someone suggest a better method of writing easy to maintain/extend GUI's?
Thanks!
Well, you are probably right on the bloat. It all depends on how your menu items need to be used. If you have a single menu for the app, then just create a single menu bar class that manages those items. If you need to share those menu items among a few other classes, you may want to use a MenuItemFactory to centralize the creation of the items and get them as needed to compose other menus.
Creating small classes that implement Action is a good way to encapsulate what a menu item does and those actions can also be used with popup menus and buttons.
It's really a matter of balancing your usage needs with the bloat that can occur by making every tiny thing a separate class. There isn't so much one "right" answer as there is a good flexible solution for your particular context... and that is where the "art" part of software development comes in.
Creating small classes that implement Action is a good way to encapsulate what a menu item does and those actions can also be used with popup menus and buttons.
It's really a matter of balancing your usage needs with the bloat that can occur by making every tiny thing a separate class. There isn't so much one "right" answer as there is a good flexible solution for your particular context... and that is where the "art" part of software development comes in.
•
•
Join Date: Oct 2007
Posts: 2
Reputation:
Solved Threads: 0
Hey thanks man! That's true!
It's a pretty complex GUI system, and I wanted to make it as easy as possbile to extend/modify...
I guess I went a little overboard on the classes, so now I'm gonna just make the components a little larger, i.e. all menu items on a single menu, so the menu is the smallest component. I suppose that's a reasonable way to go...
I've been looking at the MVC pattern, seems pretty good way to do things...
Yeah, GUI design is hard work! Not simple at all!!!
It's a pretty complex GUI system, and I wanted to make it as easy as possbile to extend/modify...
I guess I went a little overboard on the classes, so now I'm gonna just make the components a little larger, i.e. all menu items on a single menu, so the menu is the smallest component. I suppose that's a reasonable way to go...
I've been looking at the MVC pattern, seems pretty good way to do things...
Yeah, GUI design is hard work! Not simple at all!!!
![]() |
Similar Threads
- Java / GUI Developer Needed (UK) (Software Development Job Offers)
- Best way to Design GUI (Java)
- java gui libraries (Java)
- Java GUI JOptionPane.showMessageDialog (Java)
- Java GUI--Dynamically Adding Buttons to a Menu (Java)
- basic java GUI problem (Java)
- two Java GUI problems - please help (Java)
- a Java GUI based program using Swing classes, Vat (Java)
Other Threads in the Java Forum
- Previous Thread: Please Help me only one day left for me...!
- Next Thread: how to make a textfield in html form readonly in servlet
| Thread Tools | Search this Thread |
actuate android api applet application applications array arrays automation balls bank binary bluetooth business chat class classes clear client code codesnippet collections component database db defaultmethod development dice dragging draw ebook eclipse error event exception formatingtextintooltipjava fractal game givemetehcodez graphics gui hql html ide image infinite input integer invokingapacheantprogrammatically j2me java javaprojects jni jpanel julia linux list loop looping map method methods mobile mysql netbeans newbie openjavafx oracle parameter php print problem program programming project recursion repositories scanner screen scrollbar server set size sms sort sorting sql sqlserver state storm string sun superclass swing swt text-file threads time tree windows






