鼠标处理程序

时间:2014-01-28 06:49:43

标签: java mouseevent mousewheel

我正在制作一个鼠标处理程序,但由于编译时错误,它无法正常工作。知道问题是什么吗?

import java.awt.*;
import java.awt.event.*;

public class Mouse extends Frame implements MouseListener, MouseMotionListener, MouseWheelListener {

    int x = 0, y = 0;
    String msg = "";

    public static void main(String agrs[]) {
        Mouse m = new Mouse("ashish");
    }

    Mouse(String mj) {
        super(mj);
        addWindowListener(new mywa(this));

        addWindowListener(this);
        setSize(500, 500);
        setVisible(true);
    }

    class mywa extends WindowAdapter {

        Mouse m = null;

        mywa(Mouse m) {
            this.m = m;
        }

        public void windowClosing(WindowEvent we) {
            m.setVisible = false;
        }
    }

    public void mouseClicked(MouseEvent e) {
        msg = "mouseclicked";
        x = e.getX();
        y = e.getY();
        repaint();
    }

    public void mouseEntered(MouseEvent e1) {
        msg = "mouseentered";
        x = e1.getX();
        y = e1.getY();
        repaint();
    }

    public void mouseExited(MouseEvent e2) {
        msg = "mouseexit";
        x = e2.getX();
        y = e2.getY();
        repaint();
    }

    public void mousePressed(MouseEvent e3) {
        msg = "mouse pressed";
        x = e3.getX();
        y = e3.getY();
        repaint();
    }

    public void mouseReleased(MouseEvent ee) {
        msg = "mouse released";
        x = ee.getX();
        y = ee.getY();
        repaint();
    }

    public void mouseDragged(MouseEvent e11) {
        msg = "dragged";
        x = e11.getX();
        y = e11.getY();
        repaint();
    }

    public void mouseMoved(MouseEvent e12) {
        msg = "moved";
        x = e12.getX();
        y = e12.getY();
        repaint();
    }

    public void mouseWheelMoved(MouseWheelEvent e13) {
        msg = "wheel";
        x = e13.getX();
        y = e13.getY();
        repaint();
    }

    public void paint(Graphics g) {
        g.drawString(msg + " at " + x + "," + y, 50, 100);
    }
}

----------编译----------

.\MouseEvent.java:8: error: class Mouse is public, should be declared in a file named Mouse.java
public class Mouse extends Applet
       ^
Mouse.java:29: error: cannot access MouseEvent
public void mouseClicked(MouseEvent e){
                         ^
  bad source file: .\MouseEvent.java
    file does not contain class MouseEvent
    Please remove or make sure it appears in the correct subdirectory of the sourcepath.

Output completed (0 sec consumed) - Normal Termination

2 个答案:

答案 0 :(得分:0)

如果您收到此例外

.\MouseEvent.java:8: error: class Mouse is public, should be declared in a file named Mouse.java
public class Mouse extends Applet

然后你必须保存名为Mouse.java的java文件或从public中删除class Mouse声明。

我在这里看到的另一个问题

public void windowClosing(WindowEvent we) {
            m.setVisible = false;// error
        }

应为m.setVisible(false);

还有一个问题出在您的构造函数

Mouse(String mj) {
        super(mj);
        addWindowListener(new mywa(this));

        addWindowListener(this);//error , Parameter should be a WindowListener object
        setSize(500, 500);
        setVisible(true);
    }

答案 1 :(得分:-1)

框架错误。

我的计算机上有一个可屏蔽的,但当我将我的DOS 7.10分区更改为Win95时,因为我已经将Win95正常工作,它会通过V86接口重新出现并记住六个以上。

基本上原因是时间错误。我只是因为您通过保护模式使用接口来调用其VCPI接口。

这是最低优先级,在保护模式下,您必须重新获取缺少此功能的新保护模式mutltitask接口。

您拥有鼠标多任务但无法支持程序操作的任何实模式调试,因为计算机不能简单地依赖来自VCPI接口的数据位。它的数据是仿真,不能使用也不可信,因为它不是实模式通信中的特权级接口。

您无法从失败的错误中建立新的保护模式多任务,因为它是相同的错误 - 并且正在尝试重新建立它。