问题描述
- 我是菜鸟,搞不定了,麻烦了
-
代码如下:import java.awt.*; import java.awt.event.*; public class Jian extends Frame implements WindowListener {//上面的错误是什么?但是程序还可以运行 Jian() { this.setTitle("窗口监听"); this.addWindowListener(this); this.setBounds(100,100,300,300); this.setVisible(true); } public void windowActivated(WindowEvent e) { System.out.println("激活"); } public void windowClose(WindowEvent e) { System.out.println("释放"); }http://ask.csdn.net/questions/214642# public void windowClosing(WindowEvent e) { System.out.println("菜单关闭"); this.dispose(); } public void windowDeactivated(WindowEvent e) { System.out.println("失去焦点"); } public void windowDeiconified(WindowEvent e) { System.out.println("到最大化"); } public void windowIcoified(WindowEvent e) { System.out.println("到最小化"); } public void windowOpend(WindowEvent e) { System.out.println("打开"); } public static void main(String args[]) { new Jian(); } }
解决方案
鼠标放上去看一下提示,有可能是重名
解决方案二:
为什么不把所有的错误信息都黏贴出来,光看代码是很难判断出错的地方是那里的,
解决方案四:
这就是全部的信息了:
激活
Exception in thread "AWT-EventQueue-0" java.lang.Error: Unresolved compilation problem:
The type Jian must implement the inherited abstract method WindowListener.windowOpened(WindowEvent)
at Jian.windowOpened(Jian.java:3)
at java.awt.Window.processWindowEvent(Window.java:1859)
at java.awt.Window.processEvent(Window.java:1820)
at java.awt.Component.dispatchEventImpl(Component.java:4583)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Window.dispatchEventImpl(Window.java:2475)
at java.awt.Component.dispatchEvent(Component.java:4413)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
失去焦点
激活
菜单关闭
Exception in thread "AWT-EventQueue-0" java.lang.Error: Unresolved compilation problem:
The type Jian must implement the inherited abstract method WindowListener.windowClosed(WindowEvent)
at Jian.windowClosed(Jian.java:3)
at java.awt.Window.processWindowEvent(Window.java:1865)
at java.awt.Window.processEvent(Window.java:1820)
at java.awt.Component.dispatchEventImpl(Component.java:4583)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Window.dispatchEventImpl(Window.java:2475)
at java.awt.Component.dispatchEvent(Component.java:4413)失去焦点
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
解决方案五:
The type Jian must implement the inherited abstract method WindowListener.windowClosed(WindowEvent)
好明显的错误提示,这是要你实现它的抽象方法,你的代码肯定是没有实现抽象方法windowClosed(WindowEvent),
你的代码是
public void windowClose(WindowEvent e)
{
System.out.println("释放");
}
名字少了一个d,是两个不同的方法
解决方案六:
激活
Exception in thread "AWT-EventQueue-0" java.lang.Error: Unresolved compilation problem:
The type Jian must implement the inherited abstract method WindowListener.windowOpened(WindowEvent)
at Jian.windowOpened(Jian.java:3)
at java.awt.Window.processWindowEvent(Window.java:1859)
at java.awt.Window.processEvent(Window.java:1820)
at java.awt.Component.dispatchEventImpl(Component.java:4583)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Window.dispatchEventImpl(Window.java:2475)
at java.awt.Component.dispatchEvent(Component.java:4413)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
菜单关闭
失去焦点
释放
解决方案七:
The type Jian must implement the inherited abstract method WindowListener.windowOpened(WindowEvent)
自己也要学会看错误提示,要仔细看,
public void windowOpend(WindowEvent e)
{
System.out.println("打开");
}
要实现的方法是windowOpened(WindowEvent),和你的不同,你的少了一个 e 。
个人认为你应该系统的学习知识,你这种情况可以看出你基础不扎实,如果你想继续往这方面发展,应该练好基础。另外要锻炼心性,你还不够细心
解决方案八:
WindowListener接口中抽象方法要全部实现的,像Eclipse中会根据提示自动导入的,建议在IDE中编写。