// action can be Runnable or a function name static JButton newButton(S text, final O action) { JButton btn = new JButton(text); if (action != null) btn.addActionListener(actionListener { callFunction(action); }); ret btn; }