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:
//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:
//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!
:)