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 & HelpPrograms › Processing - Java integration
Page Index Toggle Pages: 1
Processing - Java integration (Read 3993 times)
Processing - Java integration
Jun 1st, 2010, 12:18pm
 
I managed to integrate a small sketch in the Java Netbeans IDE, but i have a little problem. I am trying to export to pdf from my java application but it cannot recognize the processing.pdf.* import library. Where do i find it? I found the core....but what about pdf?  Thank you.
Re: Processing - Java integration
Reply #1 - Jun 1st, 2010, 1:22pm
 
this is the code - don't mind the commentaries

Code:

import processing.core.*;
import processing.pdf.*;
//import prosvg.*;
import java.util.Random;

public class Main extends PApplet{

@Override
public void setup() {
size(400, 400);
background(255);
noStroke();
smooth();
beginRecord(PDF, "pdf_export_test.pdf");
frameRate(25);
noLoop();

}



@Override
public void draw()
{
// if(savePDF == true)
// {
// beginRecord(PDF, "PDF_test_" + frameCount + ".pdf");
// }
noStroke();
Random r = new Random();
int col1 = r.nextInt(255);
int col2 = r.nextInt(255);
int col3 = r.nextInt(255);
int x = r.nextInt(width);
int y = r.nextInt(height);
int radius1 = r.nextInt(250);
int radius2 = r.nextInt(250);
fill(col1, col2, col3, 50);
ellipse(x, y, radius1, radius2);
//if(savePDF == true)
//{
// endRecord();
// }
//endRecord();
}


/**
* @param args the command line arguments
*/
public static void main(String args[]) {
PApplet.main(new String[] { "--present", "Main" });
}
@Override
public void mousePressed() {
loop();
}

@Override
public void mouseReleased() {
noLoop();
}
@Override
public void keyPressed() {
if(key == ' ') {endRecord();
//saveFrame("svg_export_test.svg");
exit();}
}

}


Re: Processing - Java integration
Reply #2 - Jun 2nd, 2010, 1:32am
 
This Topic was moved here from Software Bugs by PhiLho .
Re: Processing - Java integration
Reply #3 - Jun 2nd, 2010, 1:35am
 
Beware where you post your messages, thanks.

Look at the installation directory where you have installed Processing.
You found core.jar in the 'lib' folder, you will find the pdf.jar (and its companion itext.jar) in the 'libraries' folder just next to the 'lib' one.
Re: Processing - Java integration
Reply #4 - Jun 2nd, 2010, 5:11am
 
sry for the wrong topic. I did put the core from lib, and the .pdf from libraries, but it says "unused import" and it's quite strange - in processing works .... but when i go java ....and try it  i get this

Code:

debug:
Exception in thread "Animation Thread" java.lang.NoClassDefFoundError: com/lowagie/text/pdf/FontMapper
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2389)
at java.lang.Class.getConstructor0(Class.java:2699)
at java.lang.Class.getConstructor(Class.java:1657)
at processing.core.PApplet.makeGraphics(PApplet.java:1159)
at processing.core.PApplet.createGraphics(PApplet.java:1086)
at processing.core.PApplet.beginRecord(PApplet.java:6713)
at Main.setup(Main.java:25)
at processing.core.PApplet.handleDraw(PApplet.java:1400)
at processing.core.PApplet.run(PApplet.java:1328)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.ClassNotFoundException: com.lowagie.text.pdf.FontMapper
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
... 11 more



Without trying to export to pdf ( begin/endrecord) the applet does work so something is trully wrong. Any thoughts?
Re: Processing - Java integration
Reply #5 - Jun 2nd, 2010, 5:48am
 
There is no .pdf (and it wouldn't be useful) in the 'libraries' folder.
Did you included itext.jar as well, as suggested above? (in a perhaps too elliptic way)
Re: Processing - Java integration
Reply #6 - Jun 2nd, 2010, 6:10am
 
many jolly thanks
Re: Processing - Java integration
Reply #7 - Jun 2nd, 2010, 10:55am
 
I am still having some integration problems. yes i managed to make it run independently , but when i want it to run from an event i receive an exception.
The modification from the previous code i posted, despite having a main in the class i created the cunstructor to activate the PApplet
Code:

public Vizual() {
PApplet.main(new String[] { "--present", "Vizual" });
}
   @Override
   public void mousePressed() {
 loop();
 }

In my main application class i'm trying to get it start from an menu event:
Code:

if (command.equals(" Generate visualization ")) myviz = new Vizual();


Running the project, i recieve this when i try to "generate the visualization" from my menu .... and it crashes.

Code:

java.lang.ClassNotFoundException: Vizual
       at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
       at java.security.AccessController.doPrivileged(Native Method)
       at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
       at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
       at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
       at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
       at processing.core.PApplet.main(PApplet.java:6522)
       at sphynxer.Vizual.<init>(Vizual.java:65)


And it's strange because i have the class "Vizual" defined
Code:

public class Vizual extends PApplet{

@Override
public void setup() {
size(400, 400, "prosvg.SVGKdl");
background(255);
noStroke();
smooth();
beginRecord(PDF, "pdf_export_test.pdf");

Any suggestions?  Sad
Re: Processing - Java integration
Reply #8 - Jun 2nd, 2010, 12:08pm
 
i've solved the problem. I had to add the package name to the class name....and from the event i had to call PApplet.main
Page Index Toggle Pages: 1