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:

Some more code to help

Posted by Hiran on January 25, 2002 at 11:08 AM

The import statements I have are:


import java.awt.*;
import javax.swing.*;

That should be fine. The only thing I can think of is that the compiler doesn't know where to look for the packages java.awt and javax.swing. When I installed the SDK, I set the PATH, but that's it. Should I have set something else as well? Any help is greatly appreciated. Thanks
Hiran

> 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