We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
PApplet.frame (Read 1501 times)
PApplet.frame
Oct 12th, 2007, 6:06am
 
Why the follow code when run in Eclipse, frame object will be null (null pointer exception)

But when I run in Processing IDE, the frame object is not null?

public class MyClass extends PApplet {
   public void init() {
       frame.setUndecorated(true);
       super.init();
   }
}
Re: PApplet.frame
Reply #1 - Oct 12th, 2007, 12:36pm
 
http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Integrate;action=display;num=1185469429
Re: PApplet.frame
Reply #2 - Oct 12th, 2007, 2:06pm
 
in eclipse I normaly pass the frame object to the PApplet when creating it. so you can access it from there as in the P5 IDE.

public class MainClass extends Frame {

 (...)

 public MainClass() {
   (...)
    Applet p5sketch = new P5Sketch(this);
   (...)
 }

 public static void main(String[] s) {
   new Main().setVisible(true);
 }

}

public class P5Sketch extends PApplet {

 Frame frame;
 public P5Sketch(Frame frame) {
   this.frame = frame; // here you go
 }
}
Re: PApplet.frame
Reply #3 - Oct 15th, 2007, 12:45am
 
MyMainClass.java
==================================
public class MyMainClass extends Frame {
 public MyMainClass() {
    Applet p5sketch = new MyAmbientNewsViewer(this);
  }

 public static void main(String[] s) {
   new MyMainClass().setVisible(true);
 }
}

MyApplet.java
==================================
public class MyApplet extends PApplet {

      public MyApplet(Frame frame) {
            this.frame = frame; // here you go
      }
      public void init() {
            frame.setUndecorated(true);
            super.init();
      }
}
Re: PApplet.frame
Reply #4 - Oct 15th, 2007, 12:50am
 
But when I add another Class - MyMainClass.java and run it as java application. I get nothing show up in my application, anything wrong with the following code?

MyMainClass.java
==================================
public class MyMainClass extends Frame {
   public MyMainClass() {
      Applet p5sketch = new MyApplet(this);
   }
         
   public static void main(String[] s) {
      new MyMainClass().setVisible(true);
 }
}

MyApplet.java
==================================
public class MyApplet extends PApplet {
      Frame frame;
      public MyApplet(Frame frame) {
            this.frame = frame; // here you go
      }
      public void init() {
            frame.setUndecorated(true);
            super.init();
      }
      public void setup() {
            // do some setup
      }
}
Re: PApplet.frame
Reply #5 - Oct 15th, 2007, 1:13am
 
yeah, my code above is not complete. it just shows how i handle the frame thing.
For how to set up and embedd the PApplet correctly, check out the links in the thread that fry posted. mainly http://dev.processing.org/reference/core/javadoc/processing/core/PApplet.html
Page Index Toggle Pages: 1