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 5 of 8 FirstFirst ... 34567 ... LastLast
Results 101 to 125 of 192

Thread: drag and drop word to match image

  1. #101
    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
    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?
    The accept works... heres the code:
    Last edited by stresstedout; March 4th, 2014 at 01:39 AM.

  2. #102
    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 {}s are missing for the else block.

    What is the variable: string2 for?

    The variable: string1 should be defined as a class instance variable, not as a local variable in a method. The next step in the test program will be to pass into the class the String that it is supposed to accept.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #103
    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
    The {}s are missing for the else block.

    What is the variable: string2 for?

    The variable: string1 should be defined as a class instance variable, not as a local variable in a method. The next step in the test program will be to pass into the class the String that it is supposed to accept.

    this code i have just changed it works... is this correct now?? or do i need change what u have suggested above?
    Last edited by stresstedout; March 4th, 2014 at 01:39 AM.

  4. #104
    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 accept String needs to be defined outside of the method. Make it a parameter to the class's constructor.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #105
    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
    The accept String needs to be defined outside of the method. Make it a parameter to the class's constructor.
    like it was in post #89??

  6. #106
    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 part of post#89 are you asking about.

    Do you know what the definition of a method is? For example, what variables are defined inside a method and what variables are defined outside of a method.
    If you don't understand my answer, don't ignore it, ask a question.

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

    like so??
    Last edited by stresstedout; March 4th, 2014 at 01:40 AM.

  8. #108
    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 looks like the definition of a method.

    Did you have a question about the contents of that method?

    One poor coding technique is putting more than one } on the same line like at the end of the method. Each } should be on its own line.
    If you don't understand my answer, don't ignore it, ask a question.

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

    ermm sorry i will fix }}

    so now that i have with this working with your patience and help

    1) how do i string more than one label to be accepted??

    2) can i now add this to my code with the sql??

    3) how will i set the location for where the code will be accepted?

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

    how do i string more than one label to be accepted??
    Use an OR condition in the if statement for all the Strings to be accepted.

    Have you changed the test program to show two images, each with a label area and with different Strings that they accept?

    To show an image with its own label, create a panel, use the Gridlayout, add the image and label to the panel and then add the panel to the frame.
    For the panel, Have the drop target extend JPanel and pass its constructor the image and the accept String.

    When that test version works, you can think about copying the logic to the big program.
    If you don't understand my answer, don't ignore it, ask a question.

  11. #111
    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
    Use an OR condition in the if statement for all the Strings to be accepted.

    Is this correct for the OR Condition?
    s
    Last edited by stresstedout; March 4th, 2014 at 01:40 AM.

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

    Is this correct for the OR Condition?
    Did you test it? Does it work?
    If you don't understand my answer, don't ignore it, ask a question.

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

    yes it does work..

    Have you changed the test program to show two images, each with a label area and with different Strings that they accept?
    i know u said not to but i put the coding we have done into the database data and it works well.

    last thing left is:

    so do u think you can help me with this bit "Have the drop target extend JPanel and pass its constructor the image and the accept String".
    if i just do this in the code to the database program straight away please.

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

    Don't be in a hurry to move the testing code into the main program. It will be easier to work out the techniques in the test program.
    If you don't understand my answer, don't ignore it, ask a question.

  15. #115
    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 in a hurry that is thing otherwise i wouldnt.

    so any tips on what i do next?

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

    Change the test program to show two images, each with a label area and with different Strings that they accept.

    To show an image with its own label, create a panel, use the Gridlayout, add the image and label to the panel and then add the panel to the frame.
    For the panel, Have the drop target extend JPanel and pass its constructor the image and the accept String.
    If you don't understand my answer, don't ignore it, ask a question.

  17. #117
    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 added the images to the panel.

    --- Update ---

    Have the drop target extend JPanel and pass its constructor the image and the accept String.
    i did change it but then i got errors, please see error below.
    Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: Uncompilable source code - Erroneous sym type: javaapplication24.DragAndDropExample.DropTargetTex tArea.setText
    at javaapplication24.DragAndDropExample$DropTargetTex tArea.drop(DragAndDropExample.java:178)
    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:40 AM.

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

    Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: Uncompilable source code - Erroneous sym type: javaapplication24.DragAndDropExample.DropTargetTex tArea.setText
    at javaapplication24.DragAndDropExample$DropTargetTex tArea.drop(DragAndDropExample.java:178)
    The error message points to the setText() used at line 178. I'm not familiar with what the IDE is saying. Can you use the javac command to get a better compiler error message?

    Other problems:
    What are the variables: string1, string2 and string3 for? They should not be there. The accept String(s) should be passed to the class in the constructor

    The images should be passed to the drop class.
    If you don't understand my answer, don't ignore it, ask a question.

  19. #119
    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
    The error message points to the setText() used at line 178. I'm not familiar with what the IDE is saying. Can you use the javac command to get a better compiler error message?

    Other problems:
    What are the variables: string1, string2 and string3 for? They should not be there. The accept String(s) should be passed to the class in the constructor

    The images should be passed to the drop class.
    i dont understand i thought i need the string1, string2
    Last edited by stresstedout; March 4th, 2014 at 01:41 AM.

  20. #120
    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 String variables: string1, string2 and string3 should NOT be defined and given values inside of the method.
    The accept String(s) should be passed to the class's constructor and saved in a class variable for use in the if test to determine if the dropped String is to be accepted or not.

    Do you know how to create and use class constructors? See the tutorial:
    Providing Constructors for Your Classes (The Java™ Tutorials > Learning the Java Language > Classes and Objects)
    If you don't understand my answer, don't ignore it, ask a question.

  21. #121
    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
    The String variables: string1, string2 and string3 should NOT be defined and given values inside of the method.
    The accept String(s) should be passed to the class's constructor and saved in a class variable for use in the if test to determine if the dropped String is to be accepted or not.

    Do you know how to create and use class constructors? See the tutorial:
    Providing Constructors for Your Classes (The Java™ Tutorials > Learning the Java Language > Classes and Objects)

    i am back, and im still struggling with this, i have read the article but not getting anywere. any help please?

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

    Please explain what your current problem is.
    If you don't understand my answer, don't ignore it, ask a question.

  23. #123
    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
    Please explain what your current problem is.

    The String variables: string1, string2 and string3 should NOT be defined and given values inside of the method.
    The accept String(s) should be passed to the class's constructor and saved in a class variable for use in the if test to determine if the dropped String is to be accepted or not.

    how do i do this?

    i have the article you suggested but im still stuck

  24. #124
    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

    There are two parts. The first part: remove the definitions from the class
    What problem do you have with that? Select the lines in the editor and press the Delete button.

    Passing a value to a class using a constructor:
    This is really VERY BASIC java.
    What don't you understand about how to code a constructor that takes an argument?
    From the tutorial:
    public Bicycle(int startCadence, int startSpeed, int startGear) {
        gear = startGear;
        cadence = startCadence;
        speed = startSpeed;
    }
    That code passes 3 values in the constructor. The 3 values are saved into class variables.
    If you don't understand my answer, don't ignore it, ask a question.

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

    where do i put the code?

Page 5 of 8 FirstFirst ... 34567 ... 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