Java error: cannot pass to java.applet.Applet in Eclipse

So, here is a really simple code that will not compile in Eclipse:

import processing.core.*;

public class MyPApplet extends PApplet {
}

I try to run it as a Java applet, but I get an error:

java.lang.ClassCastException: MyPApplet cannot be cast to java.applet.Applet

The task PAppletis the class from the package processing, and it extends java.applet.Applet, and MyPAppletextends PApplet, but I still get this error. It makes no sense. Why can not be MyPAppletdistinguished java.applet.Applet?

Can anybody help?

+4
source share
3 answers

As George said, PAppletno longer expands Appletcompared to treatment 3.

, , runSketch() :

public class MyPapplet extends PApplet {

  public static void main(String... args){
    String[] pArgs = {"MyPapplet "};
    MyPapplet mp = new MyPapplet ();
    PApplet.runSketch(pArgs, mp);
  }

  public void settings() {
    size(200, 100);
  }
  public void draw() {
    background(255);
    fill(0);
    ellipse(100, 50, 10, 10);
  }
}

, , , . :

PSurfaceAWT awtSurface = (PSurfaceAWT)mp.surface;
PSurfaceAWT.SmoothCanvas smoothCanvas = (PSurfaceAWT.SmoothCanvas)awtSurface.getNative();

, .

+2

3.x PApplet :

Applet - Java java.awt.Applet , PApplet, , Applet ( , PApplet Java AWT Component), .

- github repo 3.0

, (2.2.1 ).

+1

Below is the template for 3.x programs in Eclipse. However, you should use them as a "Java application" and not a "Java applet":

import processing.core.PApplet;

public class P5Template extends PApplet {

    public void settings() {

        size(512, 200);
    }

    public void setup() {

    }

    public void draw() {

        background(0, 30, 0);
    }

    public static void main(String[] args) {

        PApplet.main(new String[] { P5Template.class.getName() });
    }
}
0
source

Source: https://habr.com/ru/post/1623712/


All Articles