Why can't I access public methods from another class outside of the PApplet? (I'm using netbeans)

I've written some code in netbeans to be a JFrame that has a PApplet inside it running a simple sketch. My issue is that even when I create a public method in my PApplet class, I cannot access it from my JFrame class.

Using code from this example: http://www.sebastianoliva.com/en/en/2010/05/using-a-processing-sketch-as-a-java-component/trackback/

I have 3 classes, my main (BTW the markdown on this forum is mangling the code, I can't stop it form doing that, just note that if you move this project into netbeans using 3 different class files, import core.jar it will work if you comment out the line that's causing me problems.:

public class myMainClass {
    public static void main(String[] args) {
        new displayCreator().setVisible(true);
    }
}

Then I have my JFrame:

public class displayCreator extends javax.swing.JFrame {
     public displayCreator(){
        this.setSize(600, 600); //The window Dimensions
        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        javax.swing.JPanel panel = new javax.swing.JPanel();
        panel.setBounds(20, 20, 600, 600);
        processing.core.PApplet sketch = new simpleSketch();
        panel.add(sketch);
        this.add(panel);
        sketch.testSetter(true);  //<--- THIS IS CAUSING ME PROBLEMS!!!  CANNOT FIND testSetter in "sketch".
        sketch.init(); 
        this.setVisible(true);
    }
}

and of course my sketch:

import processing.core.*;

public class simpleSketch extends PApplet {

    private boolean amIset = false;

    public void testSetter(boolean setting) {
         this.amIset = setting;
    }
    public void setup() {
        size(400, 400);
        background(0);
    }
    public void draw() {
        background(0);
        fill(200);
        ellipseMode(CENTER);
        ellipse(mouseX, mouseY, 40, 40);
    }
}

When I have the line in displayCreator "sketch.testSetter(true); " I'm trying to set a value that lives inside the PApplet. The problem is that I can't. When I use Netbeans and try to autocomplete (type "sketch." then hit Ctrl+space) the method "testSetter" does not exists. If I just type it in manually, the code doesn't work even though "testSetter" is very clearly alive and well inside the simpleSketch class (I can use it without any problems inside its own class).

I really have no idea why is it preventing me from doing this.

Answers

Sign In or Register to comment.