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 3 123 LastLast
Results 1 to 25 of 67

Thread: accept only assigned label dnd

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

    Default accept only assigned label dnd

    I have used
    Last edited by stresstedout; March 30th, 2014 at 06:22 PM.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: accept only assigned label dnd

    need help to assign a specific label to 1 drop point that matches its statement.
    I don't understand what you are trying to do.
    I assume that "assign a specific label to 1 drop point" means setting the text of a JLabel object.
    What does "matches its statement" mean? That sounds like something is being compared. What is "its statement"?

    What is the contents of the values array?
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: accept only assigned label dnd

    1) the
    Last edited by stresstedout; March 30th, 2014 at 06:22 PM.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: accept only assigned label dnd

    i would like the draggable label "moon" to only accept the drop when it is dragged to the statement cat jumped over the moon
    Is this it:
    there is a JLabel with "moon" that is a draggable source
    there is a JLabel with "cat jumped over the moon" that is a drag target
    If the "moon" label is dragged to the "cat jumped over the moon" label, it should be accepted

    The reason it is to be accepted is because "cat jumped over the moon" contains the substring: "moon"
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: accept only assigned label dnd

    yes u got it, my explaining skills are rubbish.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: accept only assigned label dnd

    Look at the String class for a method to find a substring in another String.
    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: accept only assigned label dnd

    This is my whole code for this task.. have i done it wrong?
    Last edited by stresstedout; March 30th, 2014 at 06:22 PM.

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: accept only assigned label dnd

    have i done it wrong?
    Does it work? What happens when the code is executed?
    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: accept only assigned label dnd

    yes it works, the drop
    Last edited by stresstedout; March 30th, 2014 at 06:22 PM.

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: accept only assigned label dnd

    The code doesn't agree with what you are asking. There is NOT a String: "cat jumped over the moon" in the code.
    The code doesn't do what I suggested in post#4: accept the drop if the target String contained the dragged String
    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: accept only assigned label dnd

    there is a
    Last edited by stresstedout; March 30th, 2014 at 06:22 PM.

  12. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: accept only assigned label dnd

    Before you can write code for a program you need to decide what it is supposed to do.
    Look at post#4 and explain what is wrong with what I posted there.
    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: accept only assigned label dnd

    Is this it:
    there is a JLabel es the statement
    Last edited by stresstedout; March 30th, 2014 at 06:23 PM.

  14. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: accept only assigned label dnd

    Where is the String: "cat jumped over the moon" or just "moon" saved in the program so it can be used to determine if a drop should be accepted?
    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: accept only assigned label dnd

    there is no string saved in the program.

  16. #16
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: accept only assigned label dnd

    ???
    What are these:
    JLabel s1 = new JLabel("Cat jumped over the ");
    JLabel moonLabel = new DraggableLabel("moon");
    JLabel dogLabel = new DraggableLabel("dog");
    JLabel catLabel = new DraggableLabel("cat");
    JLabel MouseLabel = new DraggableLabel("mouse");
    Component droplabel = new DropTargetTextArea("moon", "dog","cat","mouse");

    I see lots of Strings in the program.
    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: accept only assigned label dnd

    sorry i thought u meant like saved in database or somthing

  18. #18
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: accept only assigned label dnd

    Time to do some design work. What Strings should be define where for what you want the code to do.
    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: accept only assigned label dnd

    1)
    Last edited by stresstedout; March 30th, 2014 at 06:23 PM.

  20. #20
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: accept only assigned label dnd

    How does the target know what String to accept if it is passed 4 Strings?
    What is the purpose of the components: s1(the second one) and dropLabel? Doesn't there need to be a drop target for each incomplete sentence?

    You need to spend more time on the design. Post#19 has left off the String "door" that would be dropped onto the s1(second one) label.
    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: accept only assigned label dnd

    "drop labe
    Last edited by stresstedout; March 30th, 2014 at 06:23 PM.

  22. #22
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: accept only assigned label dnd

    If there is only one drop target what is the second s1 for?

    Why are 4 Strings passed to the DropTargetTextArea constructor?
    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: accept only assigned label dnd

    it was just an example.. ill just sort out the layout and add the sentence to stop the confusion

  24. #24
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: accept only assigned label dnd

    It's better when posting code to remove the unneeded and confusing stuff to show a clean example of what you are trying to do.
    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: accept only assigned label dnd

    i am having some difficulty with the design, it currently looks like this.. but when i get it working i will fix the design. please can we carry on with the m
    Last edited by stresstedout; March 30th, 2014 at 06:23 PM.

Page 1 of 3 123 LastLast

Similar Threads

  1. How to not accept empty jfield?
    By myexternall11 in forum Java Theory & Questions
    Replies: 1
    Last Post: February 20th, 2012, 04:38 AM
  2. [SOLVED] Need help with updating label
    By Neacel in forum AWT / Java Swing
    Replies: 5
    Last Post: January 22nd, 2012, 02:38 PM
  3. JTree DnD Problem
    By hafunui in forum AWT / Java Swing
    Replies: 3
    Last Post: August 12th, 2011, 10:33 PM
  4. Label not showing up.
    By joshft91 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 1st, 2011, 03:36 PM
  5. Dropping to graphic element dragged from JList
    By tua1 in forum AWT / Java Swing
    Replies: 1
    Last Post: November 29th, 2008, 08:22 AM