java怎么设置图片跟随鼠标
1、//给个实例import java.awt.Color;import java.awt.event.MouseAdapter;import java.awt.event.MouseEvent;import java.awt.event.MouseMotionListener;import java.net.URL;import javax.swing.BorderFactory;import javax.swing.Icon;import javax.swing.ImageIcon;import javax.swing.JFrame;import javax.swing.JLabel;

3、//图标Iconicon = new ImageIcon(newURL("https://gss0.bdstatic.com/70cFsjip0QIZ8tyhnq/img/logo-zhidao.gif"));

5、l.addMouseMotionListener(new MouseMotionListener(){public void mouseDragged(MouseEvent e) {JLabel l = (JLabel)e.getSource();l.setLocation(l.getX()+e.getX()-x,l.getY()+e.getY()-y);}public void mouseMoved(MouseEvent e) {}});}}

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
阅读量:80
阅读量:52
阅读量:75
阅读量:52
阅读量:64