当前位置: 技术问答>java相关
如何监听这个事件?给点源代码最好!
来源: 互联网 发布时间:2015-04-26
本文导语: 如窗体有几个按钮,当水标移到某个按钮上时触发。 先谢过! | import java.awt.*; import java.awt.event.*; public class mouse { public static void main(String args[]) { new test(); } } class test extends Fra...
如窗体有几个按钮,当水标移到某个按钮上时触发。
先谢过!
先谢过!
|
import java.awt.*;
import java.awt.event.*;
public class mouse
{
public static void main(String args[])
{
new test();
}
}
class test extends Frame implements MouseListener
{
Button btn_1,btn_2;
TextArea textarea;
public test()
{
btn_1=new Button("Button1");
btn_2=new Button("Button2");
textarea=new TextArea(5,20);
textarea.setEditable(false);
setLayout(new FlowLayout());
add(btn_1);
add(btn_2);
add(textarea);
btn_1.addMouseListener(this);
btn_2.addMouseListener(this);
addMouseListener(this);
setSize(220,400);
show();
}
public void mouseEntered(MouseEvent e)
{
if(e.getSource()==btn_1)
{
textarea.append("button1");
}
if(e.getSource()==btn_2)
{
textarea.append("button2");
}
}
public void mouseClicked(MouseEvent e)
{
}
public void mouseExited(MouseEvent e)
{
}
public void mousePressed(MouseEvent e)
{
}
public void mouseReleased(MouseEvent e)
{
}
}
import java.awt.event.*;
public class mouse
{
public static void main(String args[])
{
new test();
}
}
class test extends Frame implements MouseListener
{
Button btn_1,btn_2;
TextArea textarea;
public test()
{
btn_1=new Button("Button1");
btn_2=new Button("Button2");
textarea=new TextArea(5,20);
textarea.setEditable(false);
setLayout(new FlowLayout());
add(btn_1);
add(btn_2);
add(textarea);
btn_1.addMouseListener(this);
btn_2.addMouseListener(this);
addMouseListener(this);
setSize(220,400);
show();
}
public void mouseEntered(MouseEvent e)
{
if(e.getSource()==btn_1)
{
textarea.append("button1");
}
if(e.getSource()==btn_2)
{
textarea.append("button2");
}
}
public void mouseClicked(MouseEvent e)
{
}
public void mouseExited(MouseEvent e)
{
}
public void mousePressed(MouseEvent e)
{
}
public void mouseReleased(MouseEvent e)
{
}
}
|
jBMusicDlgButtion.addMouseListener(new java.awt.event.MouseAdapter()
{
public void mouseEntered(MouseEvent e)
{
//jBMusicDlgButtion_mouseEntered(e);
System.out.println("进入")
}
public void mouseMoved(MouseEvent e)
{
//jBMusicDlg_mouseMoved(e);
}
});
{
public void mouseEntered(MouseEvent e)
{
//jBMusicDlgButtion_mouseEntered(e);
System.out.println("进入")
}
public void mouseMoved(MouseEvent e)
{
//jBMusicDlg_mouseMoved(e);
}
});
|
类似mouseOver的东西,action方法应该可以,查查文档先
|
参数是object 和event
|
用MouseEvent里面的mouseEntered方法