⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testmouseevent.java

📁 事件的处理
💻 JAVA
字号:
import java.awt.*;
import java.awt.event.*;
public class TestMouseEvent extends Frame implements MouseListener,MouseMotionListener{

  private TextArea testTA;
  private Label testLabel;

  public static void main(String args[]){

    TestMouseEvent test=new TestMouseEvent();
    test.setSize(300,200);
    test.setVisible(true);

  }

  public TestMouseEvent(){

    testTA=new TextArea();
    testTA.addMouseListener(this);
    testTA.addMouseMotionListener(this);
    testLabel=new Label();
    add(testTA,BorderLayout.CENTER);
    add(testLabel,BorderLayout.SOUTH);
  
  }

  public void mouseClicked(MouseEvent e){

    if ((e.getModifiers() & MouseEvent.META_MASK)==0)
      testTA.append("left");
    else
      testTA.append("right");
    testTA.append(" click "+e.getClickCount()+" times\n");

  }

  public void mouseEntered(MouseEvent e){

    testTA.append("enter\n");
    
  }

  public void mouseExited(MouseEvent e){

    testTA.append("exit\n");
    
  }

  public void mousePressed(MouseEvent e){

    testTA.append("press\n");
    
  }


  public void mouseReleased(MouseEvent e){

    testTA.append("release\n");
    
  }

  public void mouseDragged(MouseEvent e){

    testTA.append("drag\n");
    
  }

  public void mouseMoved(MouseEvent e){

    testLabel.setText(e.getX()+","+e.getY());
    
  }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -