package test; import java.lang.reflect.InvocationTargetException; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; public class ProfilerTest extends JFrame { private JButton button; public ProfilerTest(final int instanceNo) { super(); button = new JButton("Instance#: " + instanceNo); button.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent event) { ; // noop, just to see the instance(s) of this anonymous class ... } }); getContentPane().add(button); } public static void main(final String[] args) { ProfilerTest frame1 = new ProfilerTest(1), frame2 = null; Class clazz = ProfilerTest.class; try { frame2 = (ProfilerTest) clazz.getConstructor(int.class).newInstance(2); } catch (NoSuchMethodException e) { e.printStackTrace(); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } frame1.setDefaultCloseOperation(javax.swing.JFrame.DISPOSE_ON_CLOSE); frame2.setDefaultCloseOperation(javax.swing.JFrame.DISPOSE_ON_CLOSE); frame1.pack(); frame2.pack(); frame1.setVisible(true); frame2.setVisible(true); } }