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.
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.
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.
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.
like so??
Last edited by stresstedout; March 4th, 2014 at 01:40 AM.
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.
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?
Use an OR condition in the if statement for all the Strings to be accepted.how do i string more than one label 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.
Did you test it? Does it work?Is this correct for the OR Condition?
If you don't understand my answer, don't ignore it, ask a question.
yes it does work..
i know u said not to but i put the coding we have done into the database data and it works well.Have you changed the test program to show two images, each with a label area and with different Strings that they accept?
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.
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.
i am in a hurry that is thing otherwise i wouldnt.
so any tips on what i do next?
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.
i have added the images to the panel.
--- Update ---
i did change it but then i got errors, please see error below.Have the drop target extend JPanel and pass its constructor the image and the accept String.
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.
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?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)
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.
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.
Please explain what your current problem is.
If you don't understand my answer, don't ignore it, ask a question.
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
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:That code passes 3 values in the constructor. The 3 values are saved into class variables.public Bicycle(int startCadence, int startSpeed, int startGear) { gear = startGear; cadence = startCadence; speed = startSpeed; }
If you don't understand my answer, don't ignore it, ask a question.
where do i put the code?