I would like to implement a game board in swing (needs to be a table, though about either jtable
or gridlayout
etc ...) where I will be able to drag and drop a picture on to this game board and all the cells that the picture fell on will get a notification that they were chosen.
Can anyone help with that? how do I get a couple of cells in a table know that an object was dropped on them?
Java Swing Tutorial - Java Swing Drag and Drop. Drag and drop (DnD) is a way to transfer data in an application. DnD allows us to transfer data by dragging a component and dropping it onto another component. The component dragged is called the drag source; it supplies the data to be transferred.
A DropTarget is an object responsible for accepting drops in an drag and drop operation. A Transferable encapsulates data being transferred. The transferred data can be of various type. A DataFlavor object provides information about the data being transferred. Several Swing components have already a built-in support for drag and drop operations.
Drag and drop DnD is a way to transfer data in an application by dragging a component and dropping it onto another component. The component that is dragged is called the drag source; it supplies the data to be transferred. The component being dropped is called the drop target; it is the receiver of the data.
Drag and drop (DnD) is a way to transfer data in an application. DnD allows us to transfer data by dragging a component and dropping it onto another component.
Have a look at this tutorial.
I think you have to spent some time with Google. I found the following with a little time with Google.
Hope this helps :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With