框架可以正常打开和关闭,但无法单击鼠标。

import java.awt.Frame;
import java.awt.Graphics;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

//Create a frame window that responds to mouse click
public class AWT3 extends Frame {
    String Mmsg="";
    int mouseX=0, mouseY=0;

    public AWT3() {
        addWindowListener(new MyWindowwAdapter(this));
        addMouseListener(new MyMouseeAdapter(this));
    }

public void paint(Graphics g){
        g.drawString(Mmsg, mouseX, mouseY);
    }

public static void main(String args[]){
    AWT3 awt3 = new AWT3();
    awt3.setSize(new dimension(500, 500));
    awt3.setTitle("Window framee");
    awt3.setVisible(true);
    }
}


class MyWindowwAdapter extends WindowAdapter{
    AWT3 awt3;
    public MyWindowwAdapter(AWT3 awt3) {
        this.awt3=awt3;
    }
    public void windowClosing(WindowEvent we){
        awt3.setVisible(false);
    }
}

class MyMouseeAdapter extends MouseAdapter{
AWT3 awt3;
public MyMouseeAdapter(AWT3 awt3) {
    this.awt3=awt3;
}
public void MouseClicked(MouseEvent me){
    awt3.Mmsg="the mouse is clicked";
    awt3.mouseX= me.getX();
    awt3.mouseY=me.getY();``
    awt3.repaint();
}
}

最佳答案

方法名称应为public void mouseClicked(MouseEvent me)
而不是public void MouseClicked(MouseEvent me)

10-08 20:00