calling my PApplet object from a Java object?
in
Programming Questions
•
1 year ago
I'm sure this is rather fundamental, but I don't see how to call back into my PApplet object from a Java object. E.g.:
- // file MyApp.pde
- Pet dog;
- String name;
- void setup() {
- dog = new Pet(this);
- }
- void setName(String n) {
- name = n;
- }
- // file Pet.java
- class Pet {
- PApplet _parent;
- public Pet(PApplet parent) {
- _parent = parent;
- }
- public void doStuff() {
- _parent.setName("fido");
- }
- }
My intent is to have my PApplet contain some global state, e.g. name, and to be able to modify that state from a Java class instantiated by my PApplet. But the call to
_parent.setName('fido') results in
processing.app.Exception: the function setName(String) does not exist.
I'm sure this is a pretty simple problem, but as I said, I don't see what the real fix is. Thanks in advance.
1