Heh, i've been trying to get my head around it and did pretty much. But i'm not sure which is the best method. I realised when i was starting programming a GUI that programmers aren't going to create a class for every single action event. So, i devised a way to have multiple actions in one class so when you register the action there are multiple actions dependant on the parameter via one class. An example:
And then carry on with multiple if else statements.Code:public class Listener implements ActionListener { public void actionPerformed(ActionEvent event) { String action = event.getActionCommand(); if(action.compareTo("Create New Invoice") == 0) { // add and repaint content pane here } }
Do you think this is a good method? I'd only create one instance of Listener (which is an ADT if you get confused by the class name) and then add it to every button. So i'd create the instance, doing Listener listen = new Listener(); and then button.addActionListener(listen("parameter")
Would that work? Are there better methods?