所以我有这个代码,每次编译它都会得到错误:MouseEvent不是抽象的,也不会覆盖abtract方法mouseExited。
任何人都可以告诉我为什么或如何解决它。
`
import javax.swing.*;
import javax.swing.border.LineBorder;
import javax.swing.event.MouseInputListener;
import java.awt.*;
import java.awt.event.*;
public class MouseEvent extends JFrame implements MouseInputListener {
JLabel label = new JLabel("Label");
//constructor
public MouseEvent() {
JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
panel.add(label, BorderLayout.NORTH);
getContentPane().add(panel);
setSize(800,400);
setVisible(true);
}//end constructor
//main method
public static void main(String args[]){
new MouseEvent();
}//end main method
public void mouseClicked(MouseEvent e){
label.setText("Mouse Clicked");
}
public void mouseEntered(MouseEvent e){
label.setText("Mouse Entered");
}
public void mouseExited(MouseEvent e){
label.setText("Mouse Entered");
}
public void mousePressed(MouseEvent e){
label.setText("moyse held");
}
public void mouseReleased(MouseEvent e){
label.setText("mouse released");
}
public void mouseDragged(MouseEvent e){
label.setText("Mouse Dragged");
}
public void mouseMoved(MouseEvent e){
label.setText("mouse moved");
}
} //结束课程
任何帮助将不胜感激。
答案 0 :(得分:1)
尝试更改类的名称以避免与java的MouseEvent类冲突。