简体   繁体   English

如何在 IntelliJ IDEA 上使用处理 3?

[英]How to use Processing 3 on IntelliJ IDEA?

I'd like to use the IntelliJ IDEA IDE to develop some app using Processing 3 .我想使用IntelliJ IDEA IDE开发一些使用Processing 3的应用程序。 How can I do that ?我怎样才能做到这一点 ?

There are only tutorials on how to use Processing 2, but I think things have changed enough so that those tutorials do not work anymore.只有关于如何使用 Processing 2 的教程,但我认为情况已经发生了很大变化,以至于这些教程不再适用。

Thank you谢谢

It's hard to answer general "how do I do this" type questions.很难回答一般的“我该怎么做”类型的问题。 Stack Overflow is designed more for "I tried X, expected Y, but got Z instead" type questions. Stack Overflow 更多地是为“我尝试过 X,预期 Y,但得到 Z”类型的问题而设计的。 You'll have much better luck if you try something out and post an MCVE along with a specific question if you get stuck.如果您尝试一些事情并在遇到困难时发布一个MCVE以及一个特定问题,您将会有更好的运气。 You say you think things have changed enough so that those tutorials don't work anymore- could you test that assumption by trying it out?你说你认为事情已经发生了足够的变化,以至于那些教程不再适用——你能通过尝试来验证这个假设吗?

Because those tutorials will still work.因为这些教程仍然有效。 A few things have changed, such as the removal of the ability to embed a PApplet directly into a Swing application.一些事情发生了变化,例如删除了将PApplet直接嵌入到Swing应用程序中的能力。 But 90% of the rest of the tutorials should work fine.但是其余教程的 90% 应该可以正常工作。

Step 1: Add the Processing library to your classpath.第 1 步:将处理库添加到您的类路径。 This includes the core and any JOGL dependencies you need.这包括您需要的核心和任何 JOGL 依赖项。

Step 2: Create a class that extends PApplet and add your code there.第 2 步:创建一个扩展PApplet的类并在其中添加您的代码。

Step 3: Call PApplet.main("YourSketchNameHere");第 3 步:调用PApplet.main("YourSketchNameHere"); to launch your sketch.启动你的草图。

Here is a little example that shows those steps:这是一个显示这些步骤的小示例:

import processing.core.PApplet;

public class ProcessingTest extends PApplet{

    public void settings(){
        size(200, 200);
    }

    public void draw(){
        background(0);
        ellipse(mouseX, mouseY, 20, 20);
    }

    public static void main(String... args){
        PApplet.main("ProcessingTest");
    }
}

Please try something out and post a specific question if you get stuck.如果您遇到困难,请尝试一下并发布一个特定的问题。 Good luck.祝你好运。

Shameless self-promotion: I wrote a tutorial on using Processing as a Java library, available here .无耻的自我推销:我写了一篇关于将 Processing 用作 Java 库的教程,可在此处获得。

I up voted Kevin's answer but also went ahead and created a gradle project that you can use with or without an IDE or processing.我对 Kevin 的回答投了赞成票,但也继续创建了一个 gradle 项目,您可以在有或没有 IDE 或处理的情况下使用该项目。 Git Commit to processing project Git 提交处理项目

Edit doesn't work for video libraries.编辑不适用于视频库。 i tried to get the libraries needed but that is not my best area and have resorted to use P3 for those projects.我试图获得所需的库,但这不是我最好的领域,并且已经为这些项目使用了 P3。

The easiest way for me is to create a new maven project and add proessing through maven.对我来说最简单的方法是创建一个新的 maven 项目并通过 maven 添加处理。

After that you create your class that extends PApplet (I named it Main).之后,您创建了扩展 PApplet 的类(我将其命名为 Main)。

In Run > Edit Configuratins add the main class name and the same name for program arguments.Run > Edit Configuratins中添加主类名称和程序参数的相同名称。

Create a maven project in Intellij.在 Intellij 中创建一个 Maven 项目。 In one folder (example "libs") you put all libs which are probably not yet available via mavencentral, but with the help of maven you can handle the installation automatically.在一个文件夹(例如“libs”)中,您可以将所有通过 mavencentral 可能尚不可用的库放入,但在 maven 的帮助下,您可以自动处理安装。

libs

Then inside the pom.xml you add a maven-install-plugin , which will install your libs for you inside your local repository.然后在 pom.xml 中添加一个maven-install-plugin ,它将为您在本地存储库中安装您的库。

        <profiles>
        <profile>
        <id>Assembly Gui</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-install-plugin</artifactId>
                    <version>${maven-install-plugin.version}</version>
                    <executions>
                        <execution>
                            <id>install-controlP5-lib</id>
                            <goals>
                                <goal>install-file</goal>
                            </goals>
                            <phase>validate</phase>
                            <configuration>
                                <groupId>sojamo.de</groupId>
                                <artifactId>controlP5</artifactId>
                                <version>${controlP5.version}</version>
                                <packaging>jar</packaging>
                                <file>${basedir}/libs/controlP5-2.3.0.jar</file>
                                <generatePom>true</generatePom>
                            </configuration>
                        </execution>
                        <execution>
                            <id>install-appleJar-lib</id>
                            <goals>
                                <goal>install-file</goal>
                            </goals>
                            <phase>validate</phase>
                            <configuration>
                                <groupId>processing.org</groupId>
                                <artifactId>appleJar</artifactId>
                                <version>${appleJar.version}</version>
                                <packaging>jar</packaging>
                                <file>${basedir}/libs/apple.jar</file>
                                <generatePom>true</generatePom>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>

Note that both libs are "installed" during the "validate" phase, so the order is请注意,这两个库都是在“验证”阶段“安装”的,所以顺序是

  1. clean干净的
  2. validate (here your processing libs are installed)验证(此处安装了您的处理库)
  3. compile (and here they can be retrieved later from your local repo)编译(在这里它们可以稍后从您的本地仓库中检索)
  4. test测试
  5. ... ...

Because the maven-install-plugin was inserted as a profile (active as default), you can switch it off inside Intellij for saving a bit of time during builds once it runned at least once.由于 maven-install-plugin 是作为配置文件插入的(默认为活动状态),因此您可以在 Intellij 中将其关闭,以便在构建期间至少运行一次后节省一点时间。

Profiles in Intellij Intellij 中的配置文件

  1. Download the .jar files from their official site从他们的官方网站下载.jar文件
  2. Create any Java (or Kotlin ) project in IntelliJIntelliJ中创建任何Java (或Kotlin )项目
    • for this tutorial I've used Maven对于本教程,我使用了Maven
  3. Inside IntelliJ , go to File > Project StructureIntelliJ中,转到File > Project Structure
    • or press CTRL + ALT + SHIFT + S at the same time或同时按CTRL + ALT + SHIFT + S
  4. Inside Project Settings > Libraries : Click Plus icon内部Project Settings > Libraries :单击Plus icon
    • navigate to the downloaded folders导航到下载的文件夹
  5. Add everything inside processing-XYZ/core/libraryprocessing-XYZ/core/library添加所有内容
    • for other dependencies, look into modes library对于其他依赖项,请查看modes
    • eg: for SVG export , add processing-XYZ/modes/java/libraries/svg/library例如:对于SVG 导出,添加processing-XYZ/modes/java/libraries/svg/library

To make it easier to use Processing within an external IDE, I implemented a rudimentary wrapper.为了更容易在外部 IDE 中使用 Processing,我实现了一个基本的包装器。 This will avoid the necessity to inject the Processing-Object to each created class that want to use Processing methods.这将避免将处理对象注入每个想要使用处理方法的已创建类的必要性。

Have a look: Using Processing within external IDE看看: 在外部 IDE 中使用处理

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM