0

So I am trying to run the following code as a Java Applet in Eclipse:

import processing.core.*;

public class MyPApplet extends PApplet {

    private String URL = "https://upload.wikimedia.org/wikipedia/commons/1/16/Appearance_of_sky_for_weather_forecast,_Dhaka,_Bangladesh.JPG";
    private PImage backgroundImg;

    public void setup() {
        size(1200, 1200);
        backgroundImg = loadImage(URL, "jpg");

    }

    public void draw() {

        backgroundImg.resize(0,  height);
        image(backgroundImg, 0, 0);

    }
}

However, when I select Run -> Run As it displays "(none applicable)". I literally copied and pasted the code straight from the instructor's notes, and then the instructions say select Run -> Run As -> Java Applet. That option is not there.

I tried going into Run Configurations and add a new Java Applet, however, it asks for an Applet name, which I tried putting java.applet.Applet to no avail. My friend has his running just fine with the exact same code.

EDIT: Restarted Eclipse, Now there is an error saying MyPApplet cannot be cast to java.applet.Applet; however, MyPApplet extends PApplet which extends java.applet.Applet....

Help is greatly appreciated...

Syd
  • 65
  • 8
  • 1
    Possible duplicate of [How to run applet in eclipse using web project](http://stackoverflow.com/questions/16792642/how-to-run-applet-in-eclipse-using-web-project) – Zia Jan 11 '16 at 05:23
  • @Syd try switching perspective or workspace or even restart eclipse – sguan Jan 11 '16 at 05:33
  • @TheProgrammerG, I restarted. Now when I try to run it, it says that MyPApplet cannot be cast to java.applet.Applet... But MyPApplet extends PApplet, which extends java.applet.Applet.... – Syd Jan 11 '16 at 05:47
  • @Syd what step is it stuck on? (post your code) – sguan Jan 12 '16 at 01:29

2 Answers2

0

Figured it out guys. It couldn't run as an applet because I was using a newer version of the processing library (ie processing 3.0.1) and the instructor's code was made using processing 2.2.1. Turns out that they changed it so that PApplet no longer extends java.applet.Applet, so it couldn't be run. I had to either use the older library or use a new function from the new library.

Syd
  • 65
  • 8
0

You can still use Processing 3 with Eclipse. Add PApplet.main with "package.ClassName" as an argument in your main function and run as java application.

package ptest;
import processing.core.PApplet;
import processing.core.PVector;
public class MyApp extends PApplet {

public static void main(String[] args) {
    PApplet.main("ptest.MyApp");
}
private Segment a;
public void setup() {

}
public void settings() {
    size(800, 800);
}
public void draw() {
    background(0);
    line(0,0,100,100);
}
}
vignesh karnika
  • 111
  • 1
  • 5