传递参数物件ID值
修改部分代码:jmetest.awt.swingui.dnd.TestDnd
protected void buildUI() {
new JMEDragAndDrop(this.getDesktop());
JInternalFrame frame = new JInternalFrame("dnd test", true, true);
frame.setLayout(new GridLayout(4, 4));
JInternalFrame frame1 = new JInternalFrame("dnd test1", true, true);
frame1.setLayout(new GridLayout(4, 4));
frame1.setIconifiable(true);
Icon icon1 = getResizedIcon("kofei.png");
frame.add(new DndIcon(this, icon1,201));
Icon icon2 = getResizedIcon("Monkey.png");
frame.add(new DndIcon(this, icon2,205));
// few empty icons to let you play
for (int i = 0; i < 13; i++) {
frame.add(new DndIcon(this, null));
}
Icon icon3 = getResizedIcon("logo.jpg");
frame.add(new DndIcon(this, icon3,209));
DndIcon icons[]=new DndIcon[16];
for (int i = 0; i < 16; i++) {
icons[i]=new DndIcon(this, null,i+1){
@Override
public void receive(int partId) {
System.out.println("received:"+partId);
}
};
frame1.add(icons[i]);
}
frame.setSize(64 * 4, 64 * 4);
frame.setLocation(100, 100);
frame.setVisible(true);
frame1.setSize(64 * 4, 64 * 4);
frame1.setLocation(320, 100);
frame1.setVisible(true);
this.getDesktop().getJDesktop().add(frame);
this.getDesktop().getJDesktop().add(frame1);
MouseInput.get().setCursorVisible(true);
}
private Icon getResizedIcon(String fileName) {
ImageIcon icon = new ImageIcon(this.getClass().getResource("/jmetest/data/images/" + fileName));
icon.setImage(icon.getImage().getScaledInstance(64, 64, 16));
return icon;
}
}
/**
* DndIcon is the drag source and the drop target, so you can easily drag /
* swap icons from different panels
*
* @author Nomis
*/
public class DndIcon extends JLabel implements JMEDragGestureListener, JMEDragSourceListener, JMEDropTargetListener {
private static final long serialVersionUID = 1L;
private JMEDragAndDrop dndSupport;
public int partID=0;
public DndIcon(JMEDesktopState desktopSate, Icon icon) {
this.setIcon(icon);
this.dndSupport = desktopSate.getDesktop().getDragAndDropSupport();
new JMEMouseDragGestureRecognizer(dndSupport, this, DnDConstants.ACTION_COPY_OR_MOVE, this);
this.setBorder(BorderFactory.createLineBorder(Color.black));
}
public DndIcon(JMEDesktopState desktopSate, Icon icon,int partID) {
this.setIcon(icon);
this.dndSupport = desktopSate.getDesktop().getDragAndDropSupport();
new JMEMouseDragGestureRecognizer(dndSupport, this, DnDConstants.ACTION_COPY_OR_MOVE, this);
this.setBorder(BorderFactory.createLineBorder(Color.black));
this.partID=partID;
}
/**
* 接受一个物体
*/
public void drop(JMEDropTargetEvent e) {
TransferableImage t = (TransferableImage) e.getTransferable();
Icon icon = null;
try {
icon = (Icon) t.getTransferData(null);
} catch (UnsupportedFlavorException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}
System.out.println("------"+partID);
DndIcon source = (DndIcon) e.getSource();
receive(source.partID);
if (icon != null) {
// Set current icon to the source
source.setIcon(this.getIcon());
this.setIcon(icon);
}
}
public void receive(int partId){
}
/**
* 拉出的时候
* @param dge
*/
public void dragGestureRecognized(JMEDragGestureEvent dge) {
分享到:
相关推荐
鼠标拖动物品源码 实现方法: 为了实现这种效果,又不改变原来程序的逻辑。我做了一个光标组件(CoolCursor,目前最简易版) ,用来更新光标。结构基本上是这样的:为了实现这种效果,又不改变原来程序的逻辑。我...
两边的图标分别可随便拖动,但左右不可以互换,因为设置了拖放限制,需要type一样才能相互拖动。 我也没写过大型的MMORPG游戏,不知道正真需要怎么样的组件,玩玩,随便先做个简单的。 该组件属于轻量级组件,基本...
游戏中道具栏拖动物品效果。。。。、。。。。。。。。。
实现类似游戏武侠风云中背包物品的拖动,基于as的库进行编写,没有使用DragManager,DragManager的特效太多,没有研究怎样去除。 本例中做到了两个面板中各自物品的拖动及互相拖动,比较实用。 以前总是基于...
jquery和easyui实现购物车添加功能,可以直接拖拽加入
AS3惯性拖拽算法以及源文件。 拖拽一个物体,抛出后,根据抛出速度计算出滑行时间。
这是一个JQ拖放插件. 功能: 限制拖动范围 ...类似物品栏里的物品可相互拖拽,而且可以有限制拖放.如:下面格子里的东西可以拖到上面 但是不能拖到下面的其他格子里; 上面格子里的东西可以在上下格子里任意拖放
助力快速用 UGUI 完成图标互换,数据互换 为初学者节省宝贵的时间,避免采坑! 文档地址:https://blog.csdn.net/ChinarCSDN/article/details/89932238
实现了通过读取Json数据自动生成菜单物品,在空槽中的物品摆放等。
unity3d物品拖拽功能,包括分页功能,有效果图,不明白的可以电me,大家一起学习,一起up,up,up.....................
这是一个用Flash AS3.0制作出来的一个拖动小动画
在开发中可能会遇到将道具拖动到某个位置的需求,这里提供了一种简单方便的实现方式,欢迎品鉴~
鼠标选中物体并拖动物体的方法 Posted on 2013年04月05日 by U3d / Unity3D脚本/插件/被围观 265 次 鼠标选中物品并拖动物品
UE4开发的背包蓝图,能够点击和移动物品,当鼠标点击其中一个物品时,物品边框高亮,其他物品的取消高亮,选择的物品记录到某个蓝图中,进行物品的拖拽,物品的信息有:物品名称、物品的图标、物品的Mesh、物品的...
基于PHP的Ajax物品拖动的购物车 PHP+MySQL版.zip
Ajax物品拖动的购物车,PHP+MySQL版,jquery插件的运用让效果变得灵动起来,全动感操作,数据无刷新取自MySQL,本程序可无缝嵌入到商城购物网站中,实用方便,学习jQuery的朋友,也可认真参考一下。
基于PHP的Ajax物品拖动的购物车PHP+MySQL版源码.zip
PHP实例开发源码—Ajax物品拖动的购物车 PHP+MySQL版.zip
PHP 无刷新物品拖动的购物车 MySQL 版,jquery插件的运用让效果变得灵动起来,全动感操作,数据无刷新取自MySQL,本程序可无缝嵌入到商城购物网站中,实用方便,学习jQuery的朋友,也可认真参考一下。