Topic: 一个初学者的问题(is not abstract and does not override abstract)

  Print this page

1.一个初学者的问题(is not abstract and does not override abstract) Copy to clipboard
Posted by: tmw622
Posted on: 2005-09-26 21:41

请尽量使用准确的文字描述作为标题


最近在做java时老发现这样的问题,到底是怎么回事,我的 JDK是j2sdk-1_4_2_09-windows-i586-p
MultiListener.java:3: MultiListener is not abstract and does not override abstra
ct method windowDeactivated(java.awt.event.WindowEvent) in java.awt.event.Window
Listener
public class MultiListener implements MouseListener,MouseMotionListener,WindowListener

2.Re:一个初学者的问题(is not abstract and does not override abstract) [Re: tmw622] Copy to clipboard
Posted by: why
Posted on: 2005-09-27 00:11

The error message tells exactly what's wrong.Smile

Show us your code.

3.Re:一个初学者的问题(is not abstract and does not override abstract) [Re: tmw622] Copy to clipboard
Posted by: tmw622
Posted on: 2005-10-05 12:20

this is the original code:

import java.awt.*;
import java.awt.event.*;
public class multiListener
{
  private Frame f;
  private TextField tf;
  public static void main(String[] args)
  {
    multiListener m1=new multiListener();
    m1.go();
  }

  public void go()
  {
    Frame f=new Frame("多个监听者");
    f.add(new Label("单击和拖动鼠标"),"North");
    tf=new TextField(30);
    f.add(tf,"South");

    f.addMouseListener(new MouseAdapter()
    {
      public void mouseEntered(MouseEvent e)
      {
        String s="The mouse entered";
        tf.setText(s);
      }

      public void mouseExited(MouseEvent e)
      {
        String s="The mouse exited";
        tf.setText(s);
      }
    });
    
    f.addMouseListener(new MouseMotionAdapter()
    {
      public void mouseDragged(MouseEvent e)
      {
        String s="Mouse dragging:X="+e.getX()+"Y="+e.getY();
        tf.setText(s);
      }
    });

    f.addWindowListener(new WindowAdapter()
    {
      public void windowClosing(WindowEvent e)
      {
        System.exit(0);
      }
    });
    f.resize(200,200);
    f.show();
  }
}

4.Re:一个初学者的问题(is not abstract and does not override abstract) [Re: tmw622] Copy to clipboard
Posted by: z81608188
Posted on: 2005-10-19 22:37

我告诉你啊。

f.addMouseListener(new MouseMotionAdapter(){});这个地方写错了

应该是

f.addMouseMotionListener(new MouseMotionAdapter(){});

5.Re:一个初学者的问题(is not abstract and does not override abstract) [Re: tmw622] Copy to clipboard
Posted by: chenjianguojt
Posted on: 2005-10-19 23:33

这个错误的意思是说MultiListener 不是抽象类,不能重写抽象方法。这种情况在写监听器类的时候特别常见,一般我们都将Listener改为Adapter,然后重写你需要的函数就可以了


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923