The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
January 2002

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

Adding action listeners to JButton

Posted by Hiran on January 25, 2002 at 10:45 AM

How do I add an action listener to JButton? I've done this before, but I must be doing something wrong, because I'm getting an error message. Here's my code:


public class HoursTrackerGUI extends JFrame
{
private JButton setStartTime = new JButton("Clock in");

public HoursTrackerGUI()
{
super();

this.setSize(400, 300);

Container contents = this.getContentPane();
contents.setLayout(new FlowLayout());
contents.add(setStartTime);

setStartTime.addActionListener(new SSTListener());
}

private class SSTListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
System.out.println("The button was pressed!");
}
}
}


Thanks in advance.
Hiran



Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us