-2

I am currently not new to java but the first time I got this error here is a sample of my code ! Explains why even if I implements the mouseListener methods I cant seem to make my code work im working with IntelliJ

package com.company;

import org.w3c.dom.events.MouseEvent;

import javax.swing.*;
import java.awt.event.MouseListener;

public class AppMenu extends JMenuBar implements MouseListener {

    //  Constants
    private static String menufile = "File";
    private static String editmenu = "Edit";
    private static String aboutmenu = "About";

    //  Constructor
    public AppMenu() {
        super();

        this.add(newMenu(menufile));
        this.add(newMenu(editmenu));
        this.add(newMenu(aboutmenu));
    }

    //  This function create new menu for the App Menu
    private JMenu newMenu(String _name){
        JMenu newMenu = new JMenu(_name);
        //newMenu.addMouseListener(this);
        return newMenu;
    }

    public void mouseExited(MouseEvent e) {}

    public void mousePressed(MouseEvent e) {}

    public void mouseReleased(MouseEvent e) {}

    public void mouseEntered(MouseEvent e) {}

    public void mouseClicked(MouseEvent e) {}
}
sbolel
  • 3,486
  • 28
  • 45
Jay
  • 1
  • 1

1 Answers1

1
import org.w3c.dom.events.MouseEvent;

is the wrong import, you want

import java.awt.event.MouseEvent;

A quick look over the examples at How to Write a Mouse Listener and the JavaDocs for MouseListener would have highlighted the particular issue

MadProgrammer
  • 343,457
  • 22
  • 230
  • 366