鼠标事件小程序未在appletviewer中运行

时间:2014-09-01 18:05:55

标签: java applet appletviewer

我已经写过这个applet与鼠标事件相关联。在cmd中它被编译没有任何错误但是当我使用appletviewer命令运行它时,没有任何反应。我尝试了不同的JDK,但问题仍然存在。

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

/*<applet code="rat" width=150 height=150>
</applet>
*/

public class rat extends Applet implements MouseListener,MouseMotionListener
{
    String msg="";
    int mouseX=0,mouseY=0;

    public void init()
    {
       addMouseListener(this);  
       addMouseMotionListener(this);
    }

    public void mouseClicked(MouseEvent e)
    {
       mouseX=0;
       mouseY=10;
       msg="Mouse Clicked";
       repaint();
    }

    public void mouseEntered(MouseEvent e) 
    {
       mouseX=0;
       mouseY=10;
       msg="Mouse entered";
       repaint();
    }

    public void mouseExited(MouseEvent e) 
    {
       mouseX=0;
       mouseY=10;
       msg="Mouse exited";
       repaint();
    }

    public void mousePressed(MouseEvent e)
    {
       mouseX=e.getX();``
       mouseY=e.getY();`
       msg="Down";
       repaint();
    }

    public void mouseReleased(MouseEvent e) 
    {
       mouseX=e.getX();
       mouseY=e.getY();
       msg="up";
       repaint();
    }

    public void mouseDragged(MouseEvent e)
    {
       mouseX=e.getX();
       mouseY=e.getY();
       msg="*"; 
       showStatus("mouse dragged at"+mouseX+","+mouseY);
       repaint();
    }

    public void mouseMoved(MouseEvent e)
    {
       showStatus("mouse moved at"+mouseX+","+mouseY);
    }

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

0 个答案:

没有答案