Pergunta

I am making a program of mouse handling, but due to compile time error it is not working. Any idea what the problem is?

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);
    }
}

---------- compile ----------

.\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
Foi útil?

Solução

If you are getting this Exception

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

Then you have to save you java file with name Mouse.java or remove the public declaration from class Mouse.

Another Problem I see here

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

It should be m.setVisible(false);

One more problem is at your cunstructor

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

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

Outras dicas

Framing Error.

I have one on my computer to which was maskable but when I went to change my DOS 7.10 partition to Win95 as I had Win95 working fine on it, it reappeard through the V86interface and remembered over six onths ago.

Basically the reason is a time error. Ii's simply because you are using an interface through protected mode to call its VCPI interface.

This is the lowest priority and in protected mode you must reaquire a new protected mode mutltitask interface to which this is lacking.

You have your mouse multitasks but fail to support any real mode debugging of the operation of the program since the computer just can't simply rely on databits from a VCPI interface. Its data is an emulation and cannot be used nor trusted-as it is not a privileged level interface in real mode communications.

You cannot establish a new protected mode multitask from a failed error as it is the same error-and are trying to re-establish it.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top