简体   繁体   中英

How to use processing sketch in a web app

Good day, i have a Processing sketch that i want to use in a web application i am using jsp and servlets in my web app with tomcat as a server. I am using netbeans and i tried using < applet > tag but i can't get it to work, please help.

CODE:

import processing.core.*;

public class MyProcessingSketch extends PApplet {
  public static void main(String args[]) {
    PApplet.main(new String[] {  "MyProcessingSketch" });
  }

  public void setup() {


  }
@Override 
  public void draw() {
   background (200,0,0);
  }

  public void settings(){
       size(600,240);
  }


  public void mousePressed(){
            exit(); 
        }

}

Applets are not really supported anymore... But you might try p5js . Your HTML page would look like this:

<html>
<script src="http://cdnjs.cloudflare.com/ajax/libs/p5.js/0.4.6/p5.js"></script>
<script>

  function setup() {
    createCanvas(600, 240);
    background(200,0,0);
  }

  function draw() {
   // ...
  }

</script>

Like the other answer says, applets are pretty much dead. They currently require you to have a paid signed certificate or for your users to change their security settings. And even then they show a bunch of scary warning dialogs, and it's just a pain in the neck for everybody. Chrome has dropped support for applets , and they'll be deprecated in the next version of Java .

If you're using eclipse, you've got three options:

  • Deploy as a runnable jar.
  • Deploy as a packaged executable.
  • Deploy using webstart.

None of these are embedding an applet in a webpage.

However, if you're using the Processing editor, you can use Processing.js to write the same Processing code but have it deployed as JavaScript, which you can embed in a webpage. Processing.js does the translation for you, so you don't have to change your code into JavaScript code.

You can also use p5.js , but that will require you to completely rewrite your syntax into JavaScript syntax.

In either case, you'll no longer be able to use Java libraries in your code. You'll have to find a JavaScript library that does the same things and use that instead. If you really need to use the Java libraries, then you have to go with deploying using one of the first three options.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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