Results 1 to 7 of 7
  1. #1
    lucqui is offline Banned
    Join Date
    Jan 2014
    Posts
    6
    Rep Power
    0

    Default PApplet not displaying (processing.core.PApplet)

    In a class I've created I would like to display something. I'm trying to use the package processing.core and use it's class PApplet. I extend the class PApplet within my class (called QState):

    public class GraphFrame extends PApplet{
    @Override
    public void setup() {
    super.setup();
    //noLoop();
    }

    @Override
    public void draw() {
    size(1000,1000);
    rect(100,100,100,100);
    }
    }
    public void graph(){
    GraphFrame frm = new GraphFrame();
    Graph2D gr = new Graph2D(frm, 10, 10, true);
    }

    And then within main() I make the calls QState x; x.graph();, but I get no display to the screen. What's wrong? I'm probably just not up-to-speed on how PApplet works, but I have tried looking. Any help is appreciated. :)

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,038
    Rep Power
    10

    Default Re: PApplet not displaying (processing.core.PApplet)

    You say you extend PApplet and call it QState, but the code you posted extends PApplet and is called GraphFrame. Which is it? And why does your graph() function in your Processing code create a new instance of itself? I'm not really sure what's going on here...

    For better help sooner, post an SSCCE that demonstrates exactly what you're doing (in as few lines as possible, so don't post your whole project).
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    lucqui is offline Banned
    Join Date
    Jan 2014
    Posts
    6
    Rep Power
    0

    Default Re: PApplet not displaying (processing.core.PApplet)

    I'm sorry for the confusion. This code (for GraphFrame) is inside another class call QState. So the way to call graph is using a QState object. Let me make you a SSCCE.

    import processing.core.PApplet;
    import org.apache.commons.math3.complex.*;
    import org.apache.commons.math3.complex.Complex;
    import org.gwoptics.mathutils.*;
    import org.gwoptics.graphics.graph2D.*;
    import org.apache.commons.math3.analysis.polynomials.*;

    public class QState{
    protected Complex[] v;

    public void graph(){
    GraphFrame frm = new GraphFrame();
    Graph2D gr = new Graph2D(frm, 10, 10, true);
    }

    public class GraphFrame extends PApplet{
    @Override
    public void setup() {
    super.setup();
    //noLoop();
    }

    @Override
    public void draw() {
    size(1000,1000);
    rect(100,100,100,100);
    }
    }
    }


    And then driver:

    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    import java.io.IOException;

    import org.apache.commons.math3.complex.*;

    public class Main{
    public static void main(String[] args){
    me.graph();
    }
    }


    If I'm not mistaken this is compilable, and will show the bug.

  4. #4
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,038
    Rep Power
    10

    Default Re: PApplet not displaying (processing.core.PApplet)

    What is your me variable in your main() method?

    And this is just a guess, but don't you have to call the initialize method on a PApplet for it to work in Java?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    lucqui is offline Banned
    Join Date
    Jan 2014
    Posts
    6
    Rep Power
    0

    Default Re: PApplet not displaying (processing.core.PApplet)

    sorry, there's a line in there: QState me = new QState();

    I added to graph():

    public void graph(){
    GraphFrame frm = new GraphFrame();
    frm.init(); //Initialization
    }

    still no go. I have the PApplet summary (PApplet) in front of me, I'm just not familiar enough with GUI's in Java to see what's missing.

  6. #6
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,038
    Rep Power
    10

    Default Re: PApplet not displaying (processing.core.PApplet)

    You have to add your PApplet to a window such as a JFrame. You called your class GraphFrame, but it's not actually a Frame, it's a PApplet. PApplets need to be inside windows. Something like this:

    Java Code:
    JFrame frame = new JFrame("I'm a JFrame");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    PApplet papplet = new Papplet();
    frame.add(papplet);
    papplet.init();
    frame.setVisible(true);
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  7. #7
    lucqui is offline Banned
    Join Date
    Jan 2014
    Posts
    6
    Rep Power
    0

    Default Re: PApplet not displaying (processing.core.PApplet)

    Thank you! Now it is working (except a stupid incompatibility between 32-bit SWT and 64-bit jvm, but that I can deal with). :)

Similar Threads

  1. Not getting a display using PApplet
    By lucqui in forum New To Java
    Replies: 0
    Last Post: 01-16-2014, 06:53 AM
  2. Replies: 0
    Last Post: 09-19-2013, 02:04 PM
  3. Core Java
    By murali23krishna in forum New To Java
    Replies: 7
    Last Post: 02-25-2011, 06:56 AM
  4. ckkl-core 0.3.1
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 11-12-2007, 07:05 PM
  5. ckkl-core 0.3.0
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 11-10-2007, 07:44 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •