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 › Using Processing Libraries in Java
Page Index Toggle Pages: 1
Using Processing Libraries in Java (Read 1049 times)
Using Processing Libraries in Java
Oct 16th, 2009, 3:40pm
 
I am trying to integrate some java code into my Processing application.  I am running into a problem when attempting to Run the code. I have imported all of my .java files into my Processing project and I get the following error when trying to run: "Cannot find anything named RGB". I am pretty sure it's because I haven't imported the correct Processing library into my .java code. Could someone help me with this? Thank you in advance. Here is the .java class I am having trouble with:

import processing.core.*;
import processing.xml.*;

//HordeAlien is a subclass of Alien
//HordeAlien is used to create aliens of the horde type.
public class HordeAlien extends Alien
{
 protected PImage alienImage;
 
 //CONSTRUCTORS
 HordeAlien( int x, int y )
 {
   super( x, y );
   setBoundary();
   createAlienImage();
 }
 
 protected void createAlienImage()
 {
   alienImage = createImage( 20, 20, RGB );
   
   alienImage.loadPixels();
   for( int i = 0; i < pixels.length; i++ )
   {
     alienImage.pixels[i] = color( 255, 0, 0 );
   }
   alienImage.upDatePixels();
 }
 
 public void display()
 {
   image( alienImage, getX(), getY() );
 }
 
 protected void setBoundary()
 {
   boundary = new CollisionBoundary(
                   getX() - 20,
                   getY() - 20,
                   getX() + 20,
                   getY() + 20 );
 }
 
 public CollisionBoundary getBoundary()
 {
   return boundary;
 }
}

Re: Using Processing Libraries in Java
Reply #1 - Oct 17th, 2009, 8:09am
 
I see lot of other problems:
- createImage might fail, unless Alien defines it. You might want to do pa.createIamge() where pa is a variable holding a reference to the PApplet instance. Same for image() call.
- upDatePixels doesn't exist, you want updatePixels
And lastly, you must do pa.RGB, or better, PConstants.RGB
Page Index Toggle Pages: 1