iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🎓

Running Processing on IntelliJ IDEA for Mac

に公開

Introduction

I am currently attending the evening program (commonly known as the K-course) at the University of Electro-Communications, and in my second year programming class, we started using Processing, a language specialized in graphic drawing.

Processing screen

Since I usually develop using IntelliJ, it was quite painful to develop with something like a plain notepad (my productivity drastically drops without Vim keybindings). So, I decided to install Processing into IntelliJ to develop with an IDE, and I'm documenting the steps here.

By the way, when I searched, I found an article titled Writing Processing in IntelliJ IDEA #Java - Qiita, but with this setup, Macs encounter the following error message and fail to launch properly. I hope this information is helpful to others facing the same issue.

java.lang.NoClassDefFoundError: com/apple/eawt/QuitHandler
 at java.base/java.lang.Class.getDeclaredMethods0(Native Method)
 at java.base/java.lang.Class.privateGetDeclaredMethods(Class.java:3402)
 at java.base/java.lang.Class.getMethodsRecursive(Class.java:3543)
 at java.base/java.lang.Class.getMethod0(Class.java:3529)
 at java.base/java.lang.Class.getMethod(Class.java:2225)
 at processing.core.PApplet.runSketch(PApplet.java:10707)
 at processing.core.PApplet.main(PApplet.java:10504)
 at processing.core.PApplet.main(PApplet.java:10486)
 at lesson2.polygon.main(polygon.java:8)
Caused by: java.lang.ClassNotFoundException: com.apple.eawt.QuitHandler
 at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
 at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
 at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:525)

Prerequisites

The instructions are written assuming a Mac environment. For Windows users, the folder structure will be different, so please interpret accordingly. It should work by slightly changing the folder paths (or the Qiita link above might resolve your issue).

Similar settings should apply to VS Code, but since students can use IntelliJ for free, it's a good opportunity to experience the convenience of a paid IDE (spreading the word).

Steps

Creating a New Project

First, create a new project.

Select Java for the project and specify JDK 17 or later.

Project creation

If you haven't installed Java individually, it's probably JDK 16. If you keep the default 16, you'll get an error like the following, indicating that Java is too old (you can change it later from File → Project Structure). If you don't have any other options besides 16, you should install OpenJDK or similar.

Error: A LinkageError occurred while loading the main class lesson2.polygon
 java.lang.UnsupportedClassVersionError: processing/core/PApplet has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 60.0

Adding a Module

Now, let's add the Processing module so that Processing can run in the project.

Project Structure Screen

First, go to FileProject Structure.

Select Project Structure

Add JAR

From here, select JARs or directories as shown in the next image.

Project Structure Screen

Select JAR or project

Then, a Finder window will appear. Navigate to “Application” → “Processing” → “Contents” → “Java” and select the “core.jar” file displayed there.

Select core.jar

If successful, core.jar should be displayed as shown below. With this, you are ready to proceed.

Add core.jar

Writing Source Code

Now let's write the Processing source code. As shown in the next image, add a Java program named “test” under the src folder.

Add test code

Once added, paste the following code:

import processing.core.PApplet;

// The name "test" should match the filename
public class test extends PApplet {

  public static void main(String args[]) {
    // This name should also match the filename
    PApplet.main("test");
  }

  public void settings(){
    // Only the size method should be specified here
    size(640,480);
  }
  public void setup(){
  }
  public void draw(){
    // Actual Processing code goes here
    background(255);
    quad(400,100,300,200,600,200,550,50);
    triangle(250,250,200,450,600,450);
  }
}

Running the Program

Select "Run" → "Run", and choose "test" from the options that appear.

Run

If the setup is correct, an image like the following should be displayed. Good!

Result

Conclusion

With this, you can now use IDE features like auto-completion, which makes development much more comfortable. For the class, you'll submit your code, so copy the size(640,480) part from the settings and the content of the draw method, then verify its operation on the actual Processing screen.

    size(640,480);
    background(255);
    quad(400,100,300,200,600,200,550,50);
    triangle(250,250,200,450,600,450);

IDEs (Integrated Development Environments) like VS Code and IntelliJ are essential in professional work. In particular, the development experience with GitHub Copilot is so comfortable that you can't go back once you've tried it. For evening students who have limited time, mastering such tools to work efficiently is crucial, I believe.

Happy coding!

GitHubで編集を提案

Discussion