I'd like to create new classes dynamically, using Java. I have 3 buttons with labels: 1, 2 and 3. Code is like:
switch (button.getActionCommand()) { case 1: return new Listener1(); break; case 2: return new Listener2(); break; case 3; return new Listener3(); break; } And it works but I'd like to make it shorter. Every new class will be different from the previous with last number, only. So is it possible to create classes dynamically like:
return new Listener()+button.getActionListener(); I'm sure its possible, but how? Should I use one of Proxy classes or is there an easier way to achieve this?
ListenerFactory.