我正在制作一个绘图程序,它需要同时实现 MouseMotionListener
和 MouseListener
.它还需要javax.swing.JFrame
和 javax.swing.JButton
.
如果我导入 JFrame
或 JButton
就其本身而言,没有编译错误(除了按钮/框架不会被理解)。但是,如果我同时导入两者,我会在 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
最佳答案
MyPaint is not abstract and does not override abstract method
mouseExited(java.awt.event.MouseEvent) in java.awt.event.MouseListener
这意味着代码声明了接口(interface)的实现——但实际上并没有实现接口(interface)中定义的所有方法。要消除该错误,请定义方法!
关于java - 使用 MouseListeners 导入 JButton 和 JFrame 时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26580335/