Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Page 1 of 8 123 ... LastLast
Results 1 to 25 of 192

Thread: drag and drop word to match image

  1. #1
    Member
    Join Date
    Jan 2014
    Posts
    209
    My Mood
    Depressed
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default drag and drop word to match image

    Hi,


    Can anyone give me any tips or help me in anway?
    Last edited by stresstedout; March 4th, 2014 at 01:34 AM.


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: drag and drop word to match image


  3. #3
    Member
    Join Date
    Jan 2014
    Posts
    209
    My Mood
    Depressed
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: drag and drop word to match image

    i know how to do drag and drop, the thing im not sure how to program is if it matches the images to sit below the image, if incorrect to go back to the list.

  4. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: drag and drop word to match image

    That's just logic:

    if ( imageMatchesWords )
    {
        // accept it
    }
    else
    {
        // put it back where it came from
    }

  5. #5
    Member
    Join Date
    Jan 2014
    Posts
    209
    My Mood
    Depressed
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: drag and drop word to match image

    Quote Originally Posted by stresstedout View Post
    i know how to do drag and drop, the thing im not sure how to program is if it matches the images to sit below the image, if incorrect to go back to the list.
    I feel really stupid now, i have done drag a drop at school but i cant seem to get it to do a label on label? when it drops does it have to be in a textarea?

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: drag and drop word to match image

    Writing Drag and Drop code can be quite complicated if the components don't support it directly. Maybe you should look at selecting objects with mouse clicks instead of DnD.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Member
    Join Date
    Jan 2014
    Posts
    209
    My Mood
    Depressed
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: drag and drop word to match image

    I need to get to the grips of getting DnD done cus i need the marks for my project.
    I know its complicated but i just need to know weather or not i can drage and drop in to a label and get it sit under the image

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: drag and drop word to match image

    I think its possible but I have no idea how hard it would be for you to do it. I wrote some DnD code 8 years ago and haven't worked with it since then.
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Member
    Join Date
    Jan 2014
    Posts
    209
    My Mood
    Depressed
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: drag and drop word to match image

    i have managed to do drag the selected text into a textarea, however i will need to change to this to a label.
    I need the text which the user drag to match with the image and if it matches to go in the text area if not then to go back on the panel.
    This is where i am going to struggle now.

    someone above gave me a tip and said it was easy, but i may need some help. any tips

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: drag and drop word to match image

    What is the source of the text that is being dragged? Have you written a small test program that does a drag and drop from a source to a target?
    If you don't understand my answer, don't ignore it, ask a question.

  11. #11
    Member
    Join Date
    Jan 2014
    Posts
    209
    My Mood
    Depressed
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: drag and drop word to match image

    The code below drag and drop into a textarea, when i try to do the drop to a label i get red lines errors.
    Last edited by stresstedout; March 4th, 2014 at 01:35 AM.

  12. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: drag and drop word to match image

    The posted code is missing all the import statements.
    If you don't understand my answer, don't ignore it, ask a question.

  13. #13
    Member
    Join Date
    Jan 2014
    Posts
    209
    My Mood
    Depressed
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: drag and drop word to match image

    added them

  14. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: drag and drop word to match image

    What is your next step?

    The posted code must be very old. It uses awt classes vs swing
    If you don't understand my answer, don't ignore it, ask a question.

  15. #15
    Member
    Join Date
    Jan 2014
    Posts
    209
    My Mood
    Depressed
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: drag and drop word to match image

    I need the text which the user drag to match with the image and if it matches to go in the label if not then to go back on the panel.
    This is where i dont know where to begin.

  16. #16
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: drag and drop word to match image

    First you need to make a component that is a target for a drop gesture. The code for the drop location would look at the "text" that was being dragged and make the decision if it matches the target site or not.
    If you don't understand my answer, don't ignore it, ask a question.

  17. #17
    Member
    Join Date
    Jan 2014
    Posts
    209
    My Mood
    Depressed
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: drag and drop word to match image

    do u have any sample code or or know of any tutorials that can help?

  18. #18
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: drag and drop word to match image

    What about the code you just posted?
    If you don't understand my answer, don't ignore it, ask a question.

  19. #19
    Member
    Join Date
    Jan 2014
    Posts
    209
    My Mood
    Depressed
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: drag and drop word to match image

    i am having problems with changing the drop textarea to label and for to print the word on the label like it does in the textarea

  20. #20
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: drag and drop word to match image

    i am having problems
    Copy the full text of the error messages and paste them here.
    If you don't understand my answer, don't ignore it, ask a question.

  21. #21
    Member
    Join Date
    Jan 2014
    Posts
    209
    My Mood
    Depressed
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: drag and drop word to match image

    Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - javaapplication24.GridLayoutTest.DropTargetJLabel is abstract; cannot be instantiated
    at javaapplication24.GridLayoutTest.<init>(GridLayout Test.java:81)
    at javaapplication24.GridLayoutTest$DropTargetJLabel. main(GridLayoutTest.java:225)
    Java Result: 1

  22. #22
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: drag and drop word to match image

    What code is that error message for? The posted code has about 165 lines and is named: DragAndDropExample.
    Do your testing on the posted code BEFORE making a larger program. Work out the coding techniques with a small program first.
    If you don't understand my answer, don't ignore it, ask a question.

  23. #23
    Member
    Join Date
    Jan 2014
    Posts
    209
    My Mood
    Depressed
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: drag and drop word to match image

    run:
    Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - incompatible types: javaapplication24.DragAndDropExample.DropTargetjla bel cannot be converted to java.awt.Component
    at javaapplication24.DragAndDropExample.main(DragAndD ropExample.java:53)
    Java Result: 1
    Last edited by stresstedout; March 4th, 2014 at 01:35 AM.

  24. #24
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: drag and drop word to match image

    DropTargetjlabel cannot be converted to java.awt.Component
    You need to post all of the code.
    And all of the error messages. You mention 3 errors but only post the text of one.
    If you don't understand my answer, don't ignore it, ask a question.

  25. #25
    Member
    Join Date
    Jan 2014
    Posts
    209
    My Mood
    Depressed
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: drag and drop word to match image

    the error only says

    Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - incompatible types: javaapplication24.DragAndDropExample.DropTargetjla bel cannot be converted to java.awt.Component
    at javaapplication24.DragAndDropExample.main(DragAndD ropExample.java:53)
    Java Result: 1
    BUILD SUCCESSFUL (total time: 4 seconds)
    Last edited by stresstedout; March 4th, 2014 at 01:35 AM.

Page 1 of 8 123 ... LastLast

Similar Threads

  1. Drag and Drop in JTrees
    By helloworld922 in forum Java Swing Tutorials
    Replies: 4
    Last Post: March 21st, 2014, 11:16 AM
  2. [SOLVED] Drag and drop in MVC
    By Alice in forum Object Oriented Programming
    Replies: 9
    Last Post: December 9th, 2010, 10:16 PM
  3. Drag and Drop in JTrees
    By helloworld922 in forum Java Code Snippets and Tutorials
    Replies: 2
    Last Post: February 20th, 2010, 03:52 PM
  4. Drag and Drop in JTrees
    By helloworld922 in forum AWT / Java Swing
    Replies: 2
    Last Post: January 19th, 2010, 11:51 PM
  5. 'MouseUp' Drag and Drop Events
    By copeg in forum AWT / Java Swing
    Replies: 0
    Last Post: November 10th, 2009, 07:21 PM