/**
*@version 1.00 2000-04-13
*@author Cay Horstmann
*/
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.Timer;
//to resolve conflict with java.util.Timer
public class TimerTest
{
public static void main(String[] args)
{
ActionListener listener = new TimePrinter();
//construct a timer that calls the listener
//once every 10 seconds
Timer t = new Timer(10000,listener);
t.start();
JOptionPane.showMessageDialog(null, "Quit program?");
System.exit(0);
}
}
class TimePrinter implements ActionListener
{
public void actionPerformend(ActionEvent event)
{
Date now = new Date();
System.out.println("At the tone, the time is " + now);
Toolkit.getDefaultToolkit().beep();
}
}
我是照着打的,但是提示:
D:\java code>javac TimerTest.java
TimerTest.java:29: TimePrinter 不是抽象的,并且未覆盖 java.awt.event.ActionListe
ner 中的抽象方法 actionPerformed(java.awt.event.ActionEvent)
class TimePrinter implements ActionListener
^
1 错误
*@version 1.00 2000-04-13
*@author Cay Horstmann
*/
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.Timer;
//to resolve conflict with java.util.Timer
public class TimerTest
{
public static void main(String[] args)
{
ActionListener listener = new TimePrinter();
//construct a timer that calls the listener
//once every 10 seconds
Timer t = new Timer(10000,listener);
t.start();
JOptionPane.showMessageDialog(null, "Quit program?");
System.exit(0);
}
}
class TimePrinter implements ActionListener
{
public void actionPerformend(ActionEvent event)
{
Date now = new Date();
System.out.println("At the tone, the time is " + now);
Toolkit.getDefaultToolkit().beep();
}
}
我是照着打的,但是提示:
D:\java code>javac TimerTest.java
TimerTest.java:29: TimePrinter 不是抽象的,并且未覆盖 java.awt.event.ActionListe
ner 中的抽象方法 actionPerformed(java.awt.event.ActionEvent)
class TimePrinter implements ActionListener
^
1 错误
ner 中的抽象方法 actionPerformed(java.awt.event.ActionEvent)
class TimePrinter implements ActionListener {
public void actionPerformed(ActionEvent event) {
Date now = new Date();
System.out.println("At the tone, the time is " + now);
Toolkit.getDefaultToolkit().beep();
}
}
你写错了 actionPerformed 仔细看看
而你敲成了actionPerformend,所以会报TimePrinter没有实现ActionListener里面的抽象接口