JComponent () { final JButton b = new JButton("Click me again " + num); num++; b.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e1) { getWindow().setVisible(false); Messages.showYesNoDialog(b, MESSAGE, TITLE, Messages.getQuestionIcon()); } }); return b; }