We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I have this problem, of which my ButtonOpenClose.java cannot get reference to CENTER and GROUP. I have tried to implements PConstants but it does not make my sketch working.
What should I do?
Answers
Use
import static
for the class processing.core.PConstants: :ar!import static processing.core.PConstants.*;
Also using
implements processing.core.PConstants
works as well!Does not working. I am using Processing 2.2.1 by the way.
Try
import processing.core.PConstants;
Hei quark, your solution was in my first screenshot. It says that The function shapeMode(int) does not exist.
You have
PContants
it should bePConstants
, you are missing an 's' and you don't need the static keyword so again it should beimport processing.core.PConstants;
Now that I've taken more time to pay attention, your problem got nothing to do w/ PConstants! =P~
You're trying to access sketch's "canvas" w/o its PApplet's reference! X_X
Any classes accessing the "canvas" needs to request its owner's reference somehow.
Usually right at their constructors and storing it in some field afterwards:
"ForeignJavaClassNeedsCanvas.java" tab file:
Testing "some.pde" tab file:
If it still doesn't work then replace ALL 3 imports with
import processing.core.*;
which will make all classes and interfaces in
processing.core
available to you.It is working! Thanks quark and GoToLoop for helping ^:)^ .
I have been using Processing for a year and never experience this. Am I missing something? And why suddenly I need to put suffix f (example. 0.01f) in every float value in ForeignJavaClassNeedsCanvas.java but not int the .pde file?
.
or ane
in them w/ anf
..5
becomes.5f
,3.
becomes3.f
,1e3
becomes1e3f
, etc.public
.#
becomes0xff
.color
becomesint
.Thanks man really helpful.
One last question, why P2D is slower than the default renderer? When I run the P2D sketch, it goes to grey blank screen before showing the sktech. Is there anyway I can make my P2D sketch run faster?
Java has 2 floating point number types
float
anddouble
In Java the value 5.0 is treated as a
double
to make it afloat
we need to add the suffix i.e. 5.0fIn .pde tabs the Processing pre-processor adds the 'f' suffix for you.
So the statement
float x = 5.0;
is OK in a ,pde tab but not OK in a .java tab
Unfortunately the error message is not related to PConstants but everything else you write is about PConstants no wonder GoToLoop and I started down the wrong track.
Worth reading, somewhat related to your issue too, but on Eclipse IDE: O:-)
http://forum.Processing.org/two/discussion/12993/nullpointerexception-when-calling-textwidth-in-another-class
There is another thing why I think I never have this problem before.
The class here is a .java file. If I want to make a Processing pre - compiled object, I can just make my class in .pde. Hence, I do not need to worry about importing Processing internal libraries, adding suffix f in float, and refering PApplet as class argument.
https://www.Reddit.com/r/processing/comments/3ouavi/how_can_you_get_reference_to_pconstants_in/