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 & HelpSyntax Questions › Importing java classes/libraries
Page Index Toggle Pages: 1
Importing java classes/libraries (Read 611 times)
Importing java classes/libraries
Nov 21st, 2008, 6:47pm
 
Is it possible to import Java classes such as java.util.regex.Matcher or java.util.zip.ZipFile from within a Processing file?
Re: Importing java classes/libraries
Reply #1 - Nov 21st, 2008, 7:11pm
 
yes
Re: Importing java classes/libraries
Reply #2 - Nov 21st, 2008, 7:17pm
 
Any hints or example code to guide me on how to do that?
Re: Importing java classes/libraries
Reply #3 - Nov 21st, 2008, 7:23pm
 
8) i was going to explain but thought a boolean answer would be funnier.

if you 'export as application' and then look at the produced java source you'll see something like

Code:

import processing.core.*;
import java.applet.*;
import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
import java.text.*;
import java.util.*;
import java.util.zip.*;

public class sketch_081121c extends PApplet {

public void setup() {
//...
}

public void draw() {
// ...
}

static public void main(String args[]) {
PApplet.main(new String[] { "sketch_081121c" });
}
}


so you get all of those things for free (which is how you can use println() without the System.out for instance).

i think it's just a case of
import classname;
as usual. did you try that?
Re: Importing java classes/libraries
Reply #4 - Nov 21st, 2008, 7:31pm
 
Code:

import java.util.regex.*;

void setup() {
Pattern p = Pattern.compile("o w");
Matcher m = p.matcher("hello world");
boolean b = m.find();
println("Found: " + b);
}


seems fine.
Re: Importing java classes/libraries
Reply #5 - Nov 21st, 2008, 7:43pm
 
koogy wrote on Nov 21st, 2008, 7:31pm:
seems fine.

And using match() is even finer:
http://processing.org/reference/match_.html
Wink

And I think there are examples of using ZIP archives elsewhere on the board.
Re: Importing java classes/libraries
Reply #6 - Nov 21st, 2008, 10:43pm
 
koogy wrote on Nov 21st, 2008, 7:23pm:
so you get all of those things for free (which is how you can use println() without the System.out for instance).

For the record, actually you can use println because it is defined in PApplet class...

Good demonstration, otherwise. :-)
Page Index Toggle Pages: 1