button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.out.println("hello world!"); } });