Class 不是抽象的,也不会超过错误

Class is not abstract and does not over ride error

我正在尝试编写一个程序,通过在圆圈改变颜色时单击它来测试反应时间,但无法使单击部分正常工作。我一直收到这样的错误,即我的 class 不是抽象的,并且没有覆盖 MouseListener 中的方法。这是代码。

            import java.util.*;
            import java.io.*;
            import java.awt.*;
            import java.awt.event.*;
            import java.util.Random;
            import java.awt.event.MouseEvent;
            import java.awt.event.MouseListener;
            import java.awt.event.MouseMotionListener;

            public class Stopwatch
            {
                public static int windowX = 900; 
                public static int windowY = 700;

                public static void main(String args[])
                {
                    GfxApp gfx = new GfxApp();
                    gfx.setSize(900,700);
                    gfx.addWindowListener(new WindowAdapter() {public void
                    windowClosing(WindowEvent e) {System.exit(0);}});
                    gfx.show();
                }
            }

            class GfxApp extends Frame
            {
                public void paint(Graphics g) 
                {           
                    Timer.drawgreen(g);
                    Timer.pause();
                    Timer.drawred(g);

                }
            }

            class Timer
            {
                public static int circlex = 300;
                public static int circley = 200;
                public static int radius = 250;

                public static void drawgreen(Graphics g)
                {
                    g.setColor(new Color(0,255,0));
                    g.fillOval(circlex, circley, radius, radius);
                }

                public static void drawred(Graphics g)
                {
                    g.setColor(new Color(255,0,0));
                    g.fillOval(circlex, circley, radius, radius);
                }

                public static void pause()
                {
                    Random rand = new Random();

                    int k = rand.nextInt(301);

                    for(double i = 0; i < 500 + k; i += .000001)
                    {
            //                      delay
                    }
                }
            }

            class Mouse implements MouseListener
            {
                MouseListener circle = new MouseListener();

                public void MouseClicked (MouseEvent me)
                {
                }
                public void MouseEntered (MouseEvent me)
                {
                }
                public void MouseExited (MouseEvent me)
                {
                }
                public void MousePressed (MouseEvent me)
                {
                }
                public void MouseReleased (MouseEvent me)
                {
                }
            }

你的实现方法与接口的大小写不匹配,因此编译器认为你的class不满足约定,建议将这个class标记为抽象。

比如接口定义了这个方法:

void mouseClicked(MouseEvent e) { }

你把它写成:(大写的 M 而不是小写的 m)

void MouseClicked (MouseEvent me) { }

这里的这一行让我很困惑:

MouseListener circle = new MouseListener();

据我所知,MouseListener 是一个接口,您当然可以让左侧将类型声明为接口,但右侧必须是具体的 class。