基本概念:你的MarathonApp类是从接口WindowListener来的,而接口WindowListener中有多个抽象方法,WindowListener想变成类则每个方法都必须override一下,查JDK1.3 document得到 interface WindowListener共有7个方法,所以在你的程序中再加入以下6个方法就可以了。 public void windowOpened(WindowEvent e){ } public void windowClosed(WindowEvent e){ } public void windowIconified(WindowEvent e){ } public void windowDeiconified(WindowEvent e){ } public void windowActivated(WindowEvent e){ } public void windowDeactivated(WindowEvent e){ } 可以查看Thinking in Java(version 1) chapter13的 Using listener adapters for simplicity小节 ... But since WindowListener is an interface, you must implement all of the other methods even if they don’t do anything. This can be annoying. To solve the problem, each of the listener interfaces that have more than one method are provided with adapters,...
onApp.MarathonApp 中定义windowOpened(java.awt.event.WindowEvent)
public class MarathonApp implements WindowListener
^
1 个错误声明卖windowOpened接口的实现吧
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;public class MarathonApp
{
JLabel label = new JLabel("It just keeps going,and going...");
JFrame frame = new JFrame("MarathonApp Example"); public MarathonApp()
{
frame.getContentPane().add (label);
frame.setSize(300,100);
frame.setVisible (true);
frame.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit (0);
}
});
frame.show();
}
public static void main(String[] args)
{
MarathonApp m = new MarathonApp();
}}
interface WindowListener共有7个方法,所以在你的程序中再加入以下6个方法就可以了。
public void windowOpened(WindowEvent e){
}
public void windowClosed(WindowEvent e){
}
public void windowIconified(WindowEvent e){
}
public void windowDeiconified(WindowEvent e){
}
public void windowActivated(WindowEvent e){
}
public void windowDeactivated(WindowEvent e){
}
可以查看Thinking in Java(version 1) chapter13的 Using listener adapters for simplicity小节
... But since WindowListener is an interface, you must implement all of the other methods even if they don’t do anything. This can be annoying.
To solve the problem, each of the listener interfaces that have more than one method are provided with adapters,...