• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Drag and Drop

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi my name is Casey, I'm currently taking AP Computer Science at my high school and I am working on a project that is worth quite a bit of my grade. My group leader decided that we would create a virtual closet. We've got most of the work done except for 1 part. I can't figure out how to use drag and drop. I don't understand it. Every site I look at gives me examples but never tells me how to use it, and when they do tell me how to use it, it only talks about dragging and dropping text. I need to drag and drop images so that the user and just move the image(the clothes) onto the manican in order to dress it up. That way they can position the clothing better on the manican. Any help would be greatly appreciated. Thanks.
 
Casey Buresh
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No Answers??? Come on people please help me out here.
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
http://faq.javaranch.com/view?PatienceIsAVirtue

You are also more likely to get a good answer to this in the Swing forum. I'll move it for you...
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There a number of ways you can approach this.
If you are using separate components for the source images and drop target then you can take
advantage of the Swing built–in drag and drop system. This is explained with examples in the
tutorial page Introduction to Drag and Drop and Data Transfer. See the section
Data Transfer with a Custom Component. This is a general–purpose system and takes a
while to put together.
If you are doing all the dragging and dropping in a single component then things can be
greatly simplified. You have the option to use components or a graphics approach.
With components you mount the images in JLabels with ImageIcons, set the parent containers
layout to null, add the labels and call setBounds for each one. Use the setBounds
method to reposition the labels with your mouse code.
For the graphics approach you can use some Rectangles to both locate the images for drawing
and for detecting mouse selections (hit–testing) for dragging. I made up a small example of
this last option.

Image files are from the Examples Index, down low.
 
Casey Buresh
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks that helps alot. Also today one of my friends in class (The Genius) gave me another idea. He talked about using MouseListener to simplify it by saying "If mouse clicks on picture then get mouse position" then a 'Triangle' would be drawn in coordination where the top left corner of the Image was located, and it would be locked to the mouse as long as it is held clicked. That way if the user wanted to save the "outfit" they had created then saving would be as easy as filling and empty two-dimensional array with the ImageIcon's name and where it was located (What coordinates) on the screen.
 
reply
    Bookmark Topic Watch Topic
  • New Topic