程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> JAVA編程 >> 關於JAVA >> JAVA鼠標事件各種監聽 代碼

JAVA鼠標事件各種監聽 代碼

編輯:關於JAVA
 

package test.lrd;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class test01 extends JFrame implements MouseListener,MouseMotionListener
{
private JLabel statusBar;
public test01()
{
super("java3");
statusBar=new JLabel();
this.add(statusBar,BorderLayout.SOUTH);
addMouseListener(this);
addMouseMotionListener(this);
setSize(275,100);
show();
}
public void mouseClicked(MouseEvent e)
{
statusBar.setText("Clicked at["+e.getX()+","+e.getY()+"]");
}
public void mousePressed(MouseEvent e)
{
statusBar.setText("Pressed at["+e.getX()+","+e.getY()+"]");
}
public void mouseReleased(MouseEvent e)
{
statusBar.setText("Released at["+e.getX()+","+e.getY()+"]");
}
public void mouseEntered(MouseEvent e)
{
statusBar.setText("Mouse in window");
}
public void mouseExited(MouseEvent e)
{
statusBar.setText("Mouse outside window");
}
public void mouseDragged(MouseEvent e)
{
statusBar.setText("Dragged at["+e.getX()+","+e.getY()+"]");
}
public void mouseMoved(MouseEvent e)
{
statusBar.setText("Moved at["+e.getX()+","+e.getY()+"]");
}
public static void main(String args[])
{
test01 app=new test01();
app.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
}
}

 
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved