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 4 of 8 FirstFirst ... 23456 ... LastLast
Results 76 to 100 of 192

Thread: drag and drop word to match image

  1. #76
    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

    Yes it doesn't. That is what you are supposed to add for this test:

    Change the code so it accepts one of the dropped Strings and rejects the other dropped String.
    If you don't understand my answer, don't ignore it, ask a question.

  2. #77
    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 tried several times but i keep ending up with the same code. :'(

    is there anything u can suggest to help me with this bit of the code?

  3. #78
    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'll repeat what has been said before:
    What variable is the Dropped String in when it is received? You need the name of the variable.
    Write an if statement that compares that dropped String against one of the two possible Strings that can be dropped: "test" or "testing". I'll Pick "test"
    If the dropped String is "test" print a message saying "reject the drop"
    otherwise print a message saying " accept the drop"
    If you don't understand my answer, don't ignore it, ask a question.

  4. #79
    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 what you are sayin, i am just a tad confused about how to code it all.

  5. #80
    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

    Can you write these 5 lines:
    if (match test) {
    print accept
    }else{
    print reject
    }

    Use the variable that has the Dropped String in it. Place those 5 lines after the dropped String is assigned a value.
    If you don't understand my answer, don't ignore it, ask a question.

  6. #81
    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 Norm View Post
    Can you write these 5 lines:
    if (match test) {
    print accept
    }else{
    print reject
    }

    Use the variable that has the Dropped String in it. Place those 5 lines after the dropped String is assigned a value.
    is the Dropped String?
    Last edited by stresstedout; March 4th, 2014 at 01:38 AM.

  7. #82
    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

    That's a strange question to ask about your code. Did you write that code or was it copied from someone else's work? I was assuming that you had written it and knew how it worked.

    Wasn't this discussed earlier? Your post#59 answered this question. Have you forgotten all the the previous things that were discussed in this thread? That is going to make it much harder if we have to continually go over things that were previously covered.
    If you don't understand my answer, don't ignore it, ask a question.

  8. #83
    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

    no i have written the code myself, but im just getn confused with the different terms being used. i went to get some rest gna try and do it now
    --- Update ---

    String is assigned a value
    This is what im all puzzed about. is it somthing like this?
    Last edited by stresstedout; March 4th, 2014 at 01:38 AM.

  9. #84
    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

    This statement assigns a value to a String variable:
    String aStr = "a value here";  //  assign a value to a String variable
    To the left of the = is the variable
    to the right of the = is the value being assigned to the variable
    If you don't understand my answer, don't ignore it, ask a question.

  10. #85
    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

    please can you see post#83

    is this correct?

  11. #86
    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

    No. Use the equals() method to compare Strings.

    The code only needs to compare the dropped String against the String to be accepted. Any other dropped String is to be rejected.

    The logic is close, but the coding is wrong.
    If you don't understand my answer, don't ignore it, ask a question.

  12. #87
    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

    is this correct?
    Last edited by stresstedout; March 4th, 2014 at 01:38 AM.

  13. #88
    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

    Not yet. What if there are hundreds of dropped String possibilities? The code should only test for the String(s) it is going to accept.
    If you don't understand my answer, don't ignore it, ask a question.

  14. #89
    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

    so there should be no code for the line else if? this code is still not makin a difference so im guessing it not correct?
    Last edited by stresstedout; March 4th, 2014 at 01:38 AM.

  15. #90
    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 else block is executed when the if condition is false. That will be the case for all of the Strings that do not match the accepted String(s).

    See posts #64 and #80
    If you don't understand my answer, don't ignore it, ask a question.

  16. #91
    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

    so now i need to add this to my database code which i have done, it still allows the text to go in every label.
    so now i need to set each labelicon to match the word, so it knows which ones to accept right??

  17. #92
    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

    You need to work with the testing program some more before trying to copy the logic to the larger program.
    Have you made the changes that rejects the String instead of printing a message?
    If you don't understand my answer, don't ignore it, ask a question.

  18. #93
    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

    no atm it doesnt actually reject anything.. this is the full code of the testing program..
    Last edited by stresstedout; March 4th, 2014 at 01:39 AM.

  19. #94
    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

    atm it doesnt actually reject anything
    Look at posts #64 and #80 for how to code the else
    If you don't understand my answer, don't ignore it, ask a question.

  20. #95
    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 looked at them but still unsure of how to do this.

  21. #96
    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

    Compare the else in post #64 and #80 with the else code in post#93
    If you don't understand my answer, don't ignore it, ask a question.

  22. #97
    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

    is it somthing like above??
    Last edited by stresstedout; March 4th, 2014 at 01:39 AM.

  23. #98
    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

    Sorry, that very short piece of code doesn't show what the code is doing.

    It does NOT look like the code in posts #64 and #80
    If you don't understand my answer, don't ignore it, ask a question.

  24. #99
    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 getting this error


    Exception in thread "AWT-EventQueue-0" java.awt.dnd.InvalidDnDOperationException: invalid rejectDrop()
    at sun.awt.dnd.SunDropTargetContextPeer.rejectDrop(Su nDropTargetContextPeer.java:645)
    Drag action End
    at java.awt.dnd.DropTargetContext.rejectDrop(DropTarg etContext.java:208)
    at java.awt.dnd.DropTargetDropEvent.rejectDrop(DropTa rgetDropEvent.java:242)
    at javaapplication24.DragAndDropExample$DropTargetTex tArea.drop(DragAndDropExample.java:177)
    at java.awt.dnd.DropTarget.drop(DropTarget.java:450)
    at sun.awt.dnd.SunDropTargetContextPeer.processDropMe ssage(SunDropTargetContextPeer.java:537)
    at sun.awt.dnd.SunDropTargetContextPeer$EventDispatch er.dispatchDropEvent(SunDropTargetContextPeer.java :851)
    at sun.awt.dnd.SunDropTargetContextPeer$EventDispatch er.dispatchEvent(SunDropTargetContextPeer.java:775 )
    at sun.awt.dnd.SunDropTargetEvent.dispatch(SunDropTar getEvent.java:48)
    at java.awt.Component.dispatchEventImpl(Component.jav a:4716)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2287)
    at java.awt.Component.dispatchEvent(Component.java:46 87)
    at java.awt.LightweightDispatcher.retargetMouseEvent( Container.java:4832)
    at java.awt.LightweightDispatcher.processDropTargetEv ent(Container.java:4566)
    at java.awt.LightweightDispatcher.dispatchEvent(Conta iner.java:4417)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2273)
    at java.awt.Window.dispatchEventImpl(Window.java:2719 )
    at java.awt.Component.dispatchEvent(Component.java:46 87)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.j ava:723)
    at java.awt.EventQueue.access$200(EventQueue.java:103 )
    at java.awt.EventQueue$3.run(EventQueue.java:682)
    at java.awt.EventQueue$3.run(EventQueue.java:680)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPri vilege(ProtectionDomain.java:76)
    at java.security.ProtectionDomain$1.doIntersectionPri vilege(ProtectionDomain.java:87)
    at java.awt.EventQueue$4.run(EventQueue.java:696)
    at java.awt.EventQueue$4.run(EventQueue.java:694)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPri vilege(ProtectionDomain.java:76)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java: 693)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(EventDispatchThread.java:242)
    at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:161)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:150)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:146)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:138)
    at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:91)
    Last edited by stresstedout; March 4th, 2014 at 01:39 AM.

  25. #100
    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

    It looks like the code will call the reject method more than one time. Once in the else and once after that.

    Where is the if statement that tests if the dropped String is to be accepted?
    If you don't understand my answer, don't ignore it, ask a question.

Page 4 of 8 FirstFirst ... 23456 ... 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