Note: I have the correct processing.core library imported on my project already with build paths created.
import processing.core.*;
public class MyPApplet extends PApplet{
private String URL = "https://www.bali.com/media/image/663/best-resorts-bali.jpg";
private PImage backgroundImage;
public void setup() {
size(400, 400);
backgroundImage = loadImage(URL, "jpg");
}
public void draw() {
image(backgroundImage, 0, 0);
}
}
The other answer is half correct, but I think I understand why you were confused.
You can run Java code without a main()
function, as long as that code is an applet. The problem is that your code is not an applet, so it requires a main()
function.
This is a little bit confusing, because before Processing 3, PApplet
did extend the Applet
class, so a Processing sketch was an applet. But after Processing 3, that's no longer the case, so you can't run a Processing sketch as an applet. If you're following an outdated tutorial, that's the source of your confusion.
Also note that if you're using Processing from Java, you should use the settings()
function instead of the setup()
function.
Shameless self-promotion: I've written a tutorial on using Processing as a Java library available here.