If you know how to display messages when a button is pressed, then you already know how to call a method, since opening a new window is a method call.
With more details, you can implement an ActionListener , and then use the addActionListener method on your JButton. Here 's a pretty simple tutorial on how to write an ActionListener .
You can also use an anonymous class:
yourButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { hillClimb(); } });
talnicolas
source share