-1

我正在制作一个绘图程序,它需要同时实现MouseMotionListenerMouseListener. 它还需要javax.swing.JFramejavax.swing.JButton

如果我导入JFrameJButton自己导入,则不会出现编译错误(除了按钮/框架不会被理解)。MouseListener但是,如果我同时导入两者,我会在和的双重实施中遇到错误MouseMotionListener

收到的错误是:

MyPaint is not abstract and does not override abstract method 
    mouseExited(java.awt.event.MouseEvent) in java.awt.event.MouseListener

导入javax.swing.*;并不能解决问题,我很茫然。

import java.awt.*;
import java.awt.event.*;
import javax.swing.JButton;
import javax.swing.JFrame;



public class MyPaint extends Canvas implements MouseListener, MouseMotionListener
{
    public boolean bg;

    public static JButton brushSize1 = new JButton("Size 1");
    public static JButton brushSize2 = new JButton("Size 2");
    public static JButton brushSize3 = new JButton("Size 3");

    //all the code necessary
4

2 回答 2

2
MyPaint is not abstract and does not override abstract method 
    mouseExited(java.awt.event.MouseEvent) in java.awt.event.MouseListener

This means the code declares implementation of an interface - yet does not actually implement all the methods defined in the interface. To get rid of that error, define the method!

于 2014-10-27T03:22:49.097 回答
0

MouseListenerMouseMotionListener都是接口。因此,如果要实现它们,则必须在接口中定义所有方法。像这样:

public void mouseExited(MouseEvent e){
    // Do what you want to do with this.
}

像这样,您必须在接口中定义所有方法。

于 2014-10-27T13:48:28.537 回答