I have used
I have used
I don't understand what you are trying to do.Quote:
need help to assign a specific label to 1 drop point that matches its statement.
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?
Is this it:Quote:
i would like the draggable label "moon" to only accept the drop when it is dragged to the statement cat jumped over the moon
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"
yes u got it, my explaining skills are rubbish.
Look at the String class for a method to find a substring in another String.
This is my whole code for this task.. have i done it wrong?
Does it work? What happens when the code is executed?Quote:
have i done it wrong?
yes it works, the drop
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
there is a
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.
Is this it:
there is a JLabel es the statement
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?
there is no string saved in the program.
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.
sorry i thought u meant like saved in database or somthing
Time to do some design work. What Strings should be define where for what you want the code to do.
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 there is only one drop target what is the second s1 for?
Why are 4 Strings passed to the DropTargetTextArea constructor?
it was just an example.. ill just sort out the layout and add the sentence to stop the confusion
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.
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