Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Drag and Drop: what should my sources and targets be?  RSS feed

Matt Senecal
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
D-n-d gurus, I need your help. I'm creating a backgammon game, and need help in figuring out what components should be sources, and what should be targets.
The way the board works is that each point on the board is a separate object. The checkers (also separate objects) are contained within the point in a vector. Checkers are added/subtracted to/from the point by adding/removing them to/from the vector, then calling a custom method which redraws the checkers on the point. The board is just a large JPanel, and the points are positioned within the board using explicit positioning.
I would like to add drag-and-drop capabilities to the board, so that the user can click and drag a checker to another point. After reading the drag-and-drop tutorial, I'm more confused than ever.
My question to you: what should my drag sources be, and what should the targets be? I'm assuming that the points should be drop targets, since they will be receiving the dropped checkers. Should the checkers or points be drag sources?
Also, since a checker is just a glorified JPanel, what do I need to do to make it draggable?
Any help would be appreciated!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!