当前位置: 技术问答>java相关
请问该如何修改?(给高分)
来源: 互联网 发布时间:2015-05-30
本文导语: 我用的是J++,我想实现---当鼠标进入小应用程序的窗口范围时屏幕显示"鼠标已进入..",当鼠标退出小应用程序的窗口范围时屏幕显示"鼠标已退出..",但是没反应 import java.awt.Graphics; import java.awt.Point; import java.awt.Event; pu...
我用的是J++,我想实现---当鼠标进入小应用程序的窗口范围时屏幕显示"鼠标已进入..",当鼠标退出小应用程序的窗口范围时屏幕显示"鼠标已退出..",但是没反应
import java.awt.Graphics;
import java.awt.Point;
import java.awt.Event;
public class Demo28 extends java.applet.Applet
{
String CurrentMessage="";
public boolean mouseEnter(Event evt,int x,int y)
{
CurrentMessage="鼠标已进入......";
repaint();
return true;
}
public boolean mouseExit(Event evt,int x,int y)
{
CurrentMessage="鼠标已退出......";
repaint();
return true;
}
public void paint(Graphics g)
{
g.drawString(CurrentMessage,5,15);
}
}
import java.awt.Graphics;
import java.awt.Point;
import java.awt.Event;
public class Demo28 extends java.applet.Applet
{
String CurrentMessage="";
public boolean mouseEnter(Event evt,int x,int y)
{
CurrentMessage="鼠标已进入......";
repaint();
return true;
}
public boolean mouseExit(Event evt,int x,int y)
{
CurrentMessage="鼠标已退出......";
repaint();
return true;
}
public void paint(Graphics g)
{
g.drawString(CurrentMessage,5,15);
}
}
|
import java.awt.event.*;
...
addMouseListener(new MouseAdapter(){
public boolean mouseEnter(MouseEvent evt)
{
CurrentMessage="鼠标已进入......";
repaint();
return true;
}
public boolean mouseExit(MouseEvent)
{
CurrentMessage="鼠标已退出......";
repaint();
return true;
}
});
...
addMouseListener(new MouseAdapter(){
public boolean mouseEnter(MouseEvent evt)
{
CurrentMessage="鼠标已进入......";
repaint();
return true;
}
public boolean mouseExit(MouseEvent)
{
CurrentMessage="鼠标已退出......";
repaint();
return true;
}
});
|
import java.awt.Graphics;
import java.awt.Point;
import java.awt.Event;
public class Demo28 extends java.applet.Applet
{
String CurrentMessage="";
public boolean mouseMove(Event evt,int x,int y)
{
CurrentMessage="鼠标已进入......";
repaint();
return true;
}
public boolean mouseExit(Event evt,int x,int y)
{
CurrentMessage="鼠标已退出......";
repaint();
return true;
}
public void paint(Graphics g)
{
g.drawString(CurrentMessage,5,15);
}
}
import java.awt.Point;
import java.awt.Event;
public class Demo28 extends java.applet.Applet
{
String CurrentMessage="";
public boolean mouseMove(Event evt,int x,int y)
{
CurrentMessage="鼠标已进入......";
repaint();
return true;
}
public boolean mouseExit(Event evt,int x,int y)
{
CurrentMessage="鼠标已退出......";
repaint();
return true;
}
public void paint(Graphics g)
{
g.drawString(CurrentMessage,5,15);
}
}
|
init()
{
//击活鼠标事件
enableEvents(MouseEvent.MOUSE_MOVED);
}
/**处理鼠标移动事件,源于:enableEvent(MouseEvent.MOUSE_RELEASED)**/
protected void processMouseEvent(MouseEvent me){
}
/**处理鼠标移动事件,源于:enableEvent(MouseEvent.MOUSE_MOVED)**/
protected void processMouseMotionEvent(MouseEvent me){
}
{
//击活鼠标事件
enableEvents(MouseEvent.MOUSE_MOVED);
}
/**处理鼠标移动事件,源于:enableEvent(MouseEvent.MOUSE_RELEASED)**/
protected void processMouseEvent(MouseEvent me){
}
/**处理鼠标移动事件,源于:enableEvent(MouseEvent.MOUSE_MOVED)**/
protected void processMouseMotionEvent(MouseEvent me){
}
|
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.Robot.*;
public class TestMouse extends Applet implements MouseListener,MouseMotionListener
{
public void init()
{
this.addMouseListener(this);
this.addMouseMotionListener(this);
}
public void mouseClicked(MouseEvent e)
{
if(e.getClickCount()==1)
showStatus("You single hit at X--"+e.getX()+"--Y--"+e.getY());
else
if(e.getClickCount()==2)
showStatus("You double hit at X--"+e.getX()+"--Y--"+e.getY());
try{Robot m_Robot=new Robot();
m_Robot.mouseMove(500,500);
}
catch(Exception ee){}
}
public void mouseEntered(MouseEvent e)
{
showStatus("mouse into applet");
Integer.valueOf("222").intValue();
// Point pp=null;
// pp.x=50;
// pp.y=50;
// e.translatePoint(50,350);
}
public void mouseExited(MouseEvent e)
{
showStatus("mouse leave applet");
}
public void mousePressed(MouseEvent e)
{
showStatus("down mouse");
}
public void mouseReleased(MouseEvent e)
{
showStatus("up mouse");
}
public void mouseMoved(MouseEvent e)
{
//showStatus("X: "+e.getX()+"Y: "+e.getY());
}
public void mouseDragged(MouseEvent e)
{
showStatus("Dragged mouse");
}
}
import java.awt.*;
import java.awt.event.*;
import java.awt.Robot.*;
public class TestMouse extends Applet implements MouseListener,MouseMotionListener
{
public void init()
{
this.addMouseListener(this);
this.addMouseMotionListener(this);
}
public void mouseClicked(MouseEvent e)
{
if(e.getClickCount()==1)
showStatus("You single hit at X--"+e.getX()+"--Y--"+e.getY());
else
if(e.getClickCount()==2)
showStatus("You double hit at X--"+e.getX()+"--Y--"+e.getY());
try{Robot m_Robot=new Robot();
m_Robot.mouseMove(500,500);
}
catch(Exception ee){}
}
public void mouseEntered(MouseEvent e)
{
showStatus("mouse into applet");
Integer.valueOf("222").intValue();
// Point pp=null;
// pp.x=50;
// pp.y=50;
// e.translatePoint(50,350);
}
public void mouseExited(MouseEvent e)
{
showStatus("mouse leave applet");
}
public void mousePressed(MouseEvent e)
{
showStatus("down mouse");
}
public void mouseReleased(MouseEvent e)
{
showStatus("up mouse");
}
public void mouseMoved(MouseEvent e)
{
//showStatus("X: "+e.getX()+"Y: "+e.getY());
}
public void mouseDragged(MouseEvent e)
{
showStatus("Dragged mouse");
}
}
|
import java.awt.event.*;
...
addMouseListener(new MouseAdapter(){
public boolean mouseEntered(MouseEvent evt)
{
CurrentMessage="鼠标已进入......";
repaint();
return true;
}
public boolean mouseExited(MouseEvent)
{
CurrentMessage="鼠标已退出......";
repaint();
return true;
}
...
addMouseListener(new MouseAdapter(){
public boolean mouseEntered(MouseEvent evt)
{
CurrentMessage="鼠标已进入......";
repaint();
return true;
}
public boolean mouseExited(MouseEvent)
{
CurrentMessage="鼠标已退出......";
repaint();
return true;
}
|
在java中处理事件要注册监听器。