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.
IndexProgramming Questions & HelpIntegration › Java & Processing - drawing in a Java class
Page Index Toggle Pages: 1
Java & Processing - drawing in a Java class (Read 871 times)
Java & Processing - drawing in a Java class
Aug 4th, 2006, 4:50pm
 
I am having trouble drawing from within a Java class that is linked to Processing.
All my java instances and variables, I have no problems with. But what I'm trying to do is have several classes of objects with different behaviors and images, and I'd love to store all this info and class like a class's draw method from the Processing file and have the code for drawing each class within the class.

When I call a translate or ellipse or anything from within my java class, I am getting a null pointer exception.

Anyone know a work around?
Re: Java & Processing - drawing in a Java clas
Reply #1 - Aug 4th, 2006, 7:23pm
 
Can you show us some code? The "translate", "ellipse" or anything are PApplet methods, so your classes should be linked to the applet and call its methods.
Re: Java & Processing - drawing in a Java clas
Reply #2 - Aug 8th, 2006, 1:57pm
 
What do you mean by linking them to the PApplet?

Heres a simplified example of what I'm trying to do.
In my main .pde Processing file, I have:
import processing.core.*;


public class testing_java extends PApplet{

Atom a;

void setup(){
 size(screen.width, screen.height, P3D);
 a = new Atom();
}

void draw(){
 background(0);
 a.atomDraw();
}

}


And my .java file consists of:

import processing.core.*;


public class Atom extends PApplet {
 
 public Atom(){  
 }
 
 public void atomDraw(){
  ellipse(56, 46, 55, 55);  
 }
 
}



And I'm getting the null pointer exception on the ellipse call from within the atom class.....

Any suggestions?





Re: Java & Processing - drawing in a Java clas
Reply #3 - Aug 9th, 2006, 11:25am
 
Actually, i figured it out myself... just thought I'd throw up the reply in case someone else has the problem.

The java class file cannot be saved as .java.  It has to be .pde and it works just fine!
Page Index Toggle Pages: 1