使用 MouseClicked 使用光标坐标获取此错误。"The method getX() & getY() is undefined for the type MouseEvent"

Getting this error with the coordinates of the cursor using MouseClicked."The method getX() & getY() is undefined for the type MouseEvent"

简单的加减法应用:

我检查了它的解决方案,找到了有关 getX() 的解决方案,但与 MouseClicked 无关!

我认为这是某种类型转换问题,但我无法解决它,我验证了所有导入,甚至将代码与可用的在线代码进行了匹配!

进口:

    import java.awt.FlowLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.MouseAdapter;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JMenuItem;
    import javax.swing.JPopupMenu;
    import javax.swing.JTextField;
    import com.sun.glass.events.MouseEvent;

主要Class:

    public class Calcx {
        public static void main(String[] args) {
            Initialize o=new Initialize();

        }
    }

呼叫 class:

    class Initialize extends JFrame implements ActionListener {
            JFrame frame;
            JTextField t1;
            JButton b1,b2;
            JTextField t2;
            JLabel l,l1;
            JPopupMenu p;
            JMenuItem i,j;

构造函数:

                public Initialize() {
                    setTitle("CalcX");
                    setLayout(new FlowLayout());
                    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                    l=new JLabel("CalcX");
                    t1=new JTextField(5);
                    t2=new JTextField(5);
                    b1=new JButton("ADD");
                    b2=new JButton("SUBTRACT");
                    b2.addActionListener(this);
                    l1=new JLabel();
                    b1.addActionListener(this);
                    p=new JPopupMenu("Edit");
                    i= new JMenuItem("cut");
                    j= new JMenuItem("copy");
                    add(p);
                    p.add(i);
                    p.add(j);
                    add(l);
                    add(t1);
                    add(t2);
                    add(b1);
                    add(b2);
                    pack();
                    setVisible(true);


Error while using mouseClicked:

                    addMouseListener(new MouseAdapter()
                    {
                    public void mouseClicked(MouseEvent a)
                    {
                         int x=a.getX();    *Error*
                        int y=a.getY();     *Error*
                    p.show(frame,x,y);
                    }
                    }); 
                }

    }
import com.sun.glass.events.MouseEvent;

这不是与 JDK 一起使用的标准 MouseEvent class。

您需要使用:

import java.awt.event.MouseEvent;