Search code examples
javaintellij-ideaprocessing

java - Processing does not have size()


I was following an online tutorial and I think I successfully added all the processing jars. However, java says it cannot find size and many other functions My Code:

import processing.core.PApplet;
public class Main {
    // This function is called whenever we
// start the app.
    void setup()
    {
        // This function is a built in function
        // in processing which takes two
        // arguments: width and height
        // 400, 400 means a window of
        // length 400 pixels and width
        // 400 pixels
        size(400, 400);
    }

    // This function is called once per
// frame. That is, if the frame rate
// is 60, then this will be called
// 60 times in one second
    void draw()
    {

        // This is also an inbuilt function
        // which can take 4, 3 or 1 argument
        // where each argument represents the
        // intensity of each colour like:
        // 4 = (red, green, blue alpha)
        // 3 = (red, green, blue)
        // 1 = (gray_scale_value)
        background(0);

        // This command draws the circle
        // on our canvas at x=width/2,
        // y=height/2, diameter=200
        circle(width / 2, height / 2, 200);
    }

}

My dependency menu:

My Dependency List

I tried re-adding it, and it still did not work. I have no idea how to fix this as I am a total java noob.


Solution

  • The following source code runs without error in the Processing 4 IDE (editor) which may be downloaded here: https://processing.org . There is no need to use Intellij for this simple demo.

     void setup() {
      size(400, 400);
    }
    
    void draw() {
      background(0);
      circle(width / 2, height / 2, 200);
    }
    

    If you already know how to use the Processing editor and want to learn how to use Intellij to run Processing source code, then the following template runs on my system (macOS) after importing the core library from the Processing app:

    import processing.core.PApplet;
    
    public class Main extends PApplet {
        public static void main(String[] args) {
            PApplet.main(new String[] {Main.class.getName()});
        }
    
        public void settings(){
          size(400,400);
        }
    
        public void setup(){
    
        }
    
        public void draw(){
          fill(0);
          circle(200,200,200);
        }
    }