开发者

Can I use ProcessingJS compiler for converting Java code to JavaScript for non-ProcessingJS purposes?

Basically, the question is how to use ProcessinJS compiler to use it in the same way that CoffeeScript allows writing client side code, except that it would be in Java language. I'm thinking of live coding in Java in the browser similar开发者_JAVA技巧 to the "Try CoffeeScript" option in the CoffeeScript website.


This is a very confusing question. Let's go through this step by step:

  • The Processing language is designed to be syntactically similar to Java, and it is normally compiled to Java (quoth the Wikipedia article on Processing: "the code is translated into pure Java before compiling").
  • ProcessingJS is a project with two parts: 1) a JS library for using Canvas, and 2) a compiler (written in JS) that compiles Processing code to JS code that uses the aforementioned library.
  • It would certainly be possible to use ProcessingJS to compile Processing code to JS code that runs in real-time directly in the browser. Indeed, this has already been done. (Update: The interactive ProcessingJS editor that link used to go to has been replaced by http://sketchpad.cc/.)

But, when you talk about using ProcessingJS to do "live coding in Java in the browser"... well, ProcessingJS doesn't generate Java. Only the Processing compiler written in Java generates Java. If you want to work with Processing code in the browser and get Java output, you should either:

  1. Sidestep ProcessingJS altogether and use a Java applet, or
  2. Use ProcessingJS to compile and run your Processing code in real time, and use Ajax to send the Processing code to the server for compilation to Java.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜