• Post Reply Bookmark Topic Watch Topic
  • New Topic

AddActionListener Problem  RSS feed

 
Jim Buck
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have the following code. When I try to to add an ActionListener. The Class won't compile. Eclipse tells me that "The Method addActionListener(ActionListener) in the type Button is not applicable for the arguments (AlarmClock)". I'm at my wits end! Anyone have any ideas?
Thanks,
Jim
package Clock;
//import Clock.*;
import java.util.*;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
public class AlarmClock extends Frame
{
// AlarmClock class Fields are all Private
private int wakeHour, currHour;
private int wakeMinute, currMinute;
private TextField lcd;
private String type;
private TextField myLcd;
Button stopButton = new Button("Stop Me");
Button pressMe = new Button("Press Me");
//private String type;
private Clock time;
public AlarmClock(String mode)
{
// set up GUI components
super("Alarm Clock");
setSize(240, 240);
setLayout(new BorderLayout(30, 30));
lcd = new TextField();
lcd.setFont(new Font("Courier", Font.BOLD, 25));
add(lcd);

add(stopButton, BorderLayout.SOUTH);
Here is Where I try to Add the Listener
// Listen For Button
stopButton.addActionListener(this);

addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
((Window) e.getSource()).dispose();
System.exit(0);
}
});
show();
type = mode;
}
/**
*
*
*/
public void actionPerformed(ActionEvent thisEvent)
{
Object source = thisEvent.getSource();
if (source == stopButton)
{
lcd.setText("Stopped");
time.killClock();
}
}
}
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jim,
Welcome to JavaRanch!
Implementing the actionPerformed() method isn't enough to make AlarmClock into an ActionListener; you have to actually declare that it implements the interface:
public class AlarmClock extends Frame implements ActionListener {
 
Jim Buck
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ernest. I can't beliver I missed that!
Jim
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!