Problems with Object Oriented Programming with Processing in Eclipse

(Question copied from Stack Overflow)

So I'm desperately trying to cut my little program I made in Processing into different classes. However I fail on the basic level...

The Project:
We need to program a little game in Processing as the final test of our semester. Problem is, we mostly learn how to do stuff in Processing's editor. However in my opinion it's pretty bugged and the fact it has a pre-compiler from Processing to Java bothers me as well.

The Problem:
So I try using Eclipse instead. With the provided tutorial by on Processing's website I came pretty well along writing the pure Java code instead of the simplified Processing Syntax. However when it comes to making a second class, I'm completely lost. We also learn in university how to code in Java and we just finished object oriented programming as a topic. However we do not learn how to connect it with Processing.

The Problem-Code:
Below you can find my code I got problems with. I cut out most of the unneccessary stuff. However I've uploaded the full code to Pastebin, if you want to see it (warning: very messy).


import processing.core.*;

public class animation extends PApplet{

    public static void main(String[] args) {

    controls keyboard;

    //some variable initializations

    public void setup() {



    public void settings() {

        //some settings stuff


    //some more variables

    boolean moving = false,
            //triggered = false;

    boolean goUp, goDown, goLeft, goRight;

    //more vars

    public void draw() {

        //unneccesary code for drawing all the stuff

        moving = false;


        if(keyboard.goUp) {
            if(ypos > 0) {
                moving = true;
                ypos = ypos - speed * 100 * elapTime;

        if(keyboard.goDown) {
            if(ypos < height - images[0].height) {
                moving = true;
                ypos = ypos + speed * 100 * elapTime;

        if(keyboard.goLeft) {
            if(xpos > 0) {
                dir = 1;
                moving = true;
                xpos = xpos - speed * 100 * elapTime;

        if(keyboard.goRight) {
            if(xpos < width - images[0].width) {
                dir = -1;
                moving = true;
                xpos = xpos + speed * 100 * elapTime;

        if(keyPressed && key == 't' && !triggered) {
            triggered = true;



full code on pastebin


public class controls extends animation {

    boolean goUp, goDown, goLeft, goRight;

    public void check() {



    public void keyPressed() {
        setMove(keyCode, true);

    public void keyReleased() {
        setMove(keyCode, false);

    boolean setMove(int key, boolean b) {

        switch (key) {

        case UP:

            return goUp = b;

        case DOWN:

            return goDown = b;

        case LEFT:

            return goLeft = b;

        case RIGHT:

            return goRight = b;


            return b;




full code on pastebin

The error log:

#// loaded 'data/harambe/frame0.png'
#// loaded 'data/harambe/frame1.png'
#// loaded 'data/harambe/frame2.png'
#// loaded 'data/harambe/frame3.png'
#// loaded 'data/harambe/frame4.png'
#// loaded 'data/harambe/frame5.png'
#// loaded 'data/harambe/frame6.png'
#// loaded 'data/harambe/frame7.png'
#// loaded 'data/harambe/frame8.png'
#// loaded 'data/harambe/frame9.png'
#// loaded 'data/harambe/frame10.png'
#// loaded 'data/harambe/frame11.png'
#// loaded 'data/harambe/frame12.png'
#// loaded 'data/harambe/frame13.png'

    at animation.draw(
    at processing.core.PApplet.handleDraw(
    at processing.opengl.PSurfaceJOGL$DrawListener.display(
    at jogamp.opengl.GLDrawableHelper.displayImpl(
    at jogamp.opengl.GLDrawableHelper.display(
    at jogamp.opengl.GLAutoDrawableBase$
    at jogamp.opengl.GLDrawableHelper.invokeGLImpl(
    at jogamp.opengl.GLDrawableHelper.invokeGL(
    at com.jogamp.newt.opengl.GLWindow.display(
    at com.jogamp.opengl.util.AWTAnimatorImpl.display(
    at com.jogamp.opengl.util.AnimatorBase.display(
    at com.jogamp.opengl.util.FPSAnimator$
    at java.util.TimerThread.mainLoop(Unknown Source)
    at Source)

Thanks in advance to everyone who is willing to try solving this problem. I'm really lost at this point and tried a lot of things...

EDIT: When I change controls keyboard to controls keyboard = new controls(); i get the following error log (java.lang.StackOverflowError):

    at controls.<init>(
    at animation.<init>(
    at controls.<init>(
    at animation.<init>(
    at controls.<init>(
   at animation.<init>(

Above errors repeat VERY often



Sign In or Register to comment.