GButton doesn't fire events in eclipse (G4P)

edited October 2016 in Library Questions

Hi, i'm new to this forum as well as to processing.

When i try to run the G4P example "G4P_Sketchpad" in eclipse the "btnClear"-Button won't fire an event when clicked. The same code in the processing-IDE is working but when run from eclipse the button is not firing events to handleButtonEvents(GButton button, GEvent event).

any help is appreciated. here comes the code copied from eclipse:

regards

package myPackageName;

import processing.core.*;
import g4p_controls.*;

public class View extends PApplet {

    GPanel pnl;
    GSketchPad spad;
    GButton btnClear;
    PGraphics pg;

    public static void main(String[] args) {
        PApplet.main(View.class.getName());
    }

    public void settings() {
        size(1024, 768);
    }

    public void setup() {
        // Now create and clear graphic to be used (JAVA parameter
        // parameter is only needed for Processing 1.5.1)
        pg = createGraphics(640, 480);
        clearGraphic();
        // Create the G4P control to position and display the graphic
        spad = new GSketchPad(this, 0, 0, 350, 200);
        // Set the graphic for this control.
        // The graphic will be scaled to fit the control.
        spad.setGraphic(pg);
        // Create the button to clear the graphic
        btnClear = new GButton(this, 0, 0, 80, 20, "Clear");
        // Create the panel and add the controls
        pnl = new GPanel(this, 0, 0, 400, 300, "Sketch Test");
        pnl.addControl(btnClear, 10, 24);
        pnl.addControl(spad, 10, 50);
        // Expand the panel
        pnl.setCollapsed(false);
    }

    public void draw() {
        background(240);
        // Every 20th frame update the sketchpad graphic
        if (frameCount % 20 == 0)
            updateGraphic();
    }

    void handleButtonEvents(GButton button, GEvent event) {
        if(button == btnClear && event == GEvent.CLICKED) {
            clearGraphic();
        }
        // debug
        println(button);
        println(event);
    }

    // Clear the sketchpad graphic
    void clearGraphic() {
        pg.beginDraw();
        pg.background(255, 255, 200);
        pg.noFill();
        pg.ellipseMode(CORNERS);
        pg.endDraw();
    }

    // Add a line or ellipse to the sketchpad graphic
    void updateGraphic() {
        float x0 = random(10, pg.width - 10);
        float x1 = random(10, pg.width - 10);
        float y0 = random(10, pg.height - 10);
        float y1 = random(10, pg.height - 10);
        int col = color(random(64, 255), random(64, 255), random(64, 255));
        pg.beginDraw();
        pg.stroke(col);
        pg.strokeWeight(random(2, 5));
        if (random(0, 1) < 0.5f)
            pg.line(x0, y0, x1, y1);
        else
            pg.ellipse(x0, y0, x1, y1);
        pg.endDraw();
    }
}

Answers

  • Answer ✓

    Change line 48 to

    public void handleButtonEvents(GButton button, GEvent event) {

    In Eclipse you must specify the access specifier public for all G4P event handlers. In the PDE this is done for you by Processing's pre-processor.

  • Thank you very much!

    I've searched for information about that pre-processor but haven't found something useful. Do you know a online or offline source to get solid information about what processings pre-processor is doing exactly?

  • by now i have an understanding of some things the pre-processor is doing. like converting special processing-syntax to proper java and merging all pde-tabs into one class.

    the thing is that i'm writing my bachelor's thesis about processing and so i need "solid" information which i'm able to quote.

  • Answer ✓

    Well, you can hit CTRL+SHIFT + E to export a sketch, and check the generated ".java" file there. I'm sure you're gonna spot some interesting conversions, so the code is valid for Java compilation.

    2 notable 1s: color becomes int & any numerical literal w/ . or e in it is suffixed w/ f if it doesn't have any. :ar!

  • Answer ✓

    the thing is that i'm writing my bachelor's thesis about processing and so i need "solid" information which i'm able to quote.

    That is going to be difficult. Documentation on Processing's pre-processor is only of value to the Processing developers so will not be in the public domain for you to quote.

  • edited October 2016 Answer ✓

    the thing is that i'm writing my bachelor's thesis about processing and so i need "solid" information which i'm able to quote.

    Documentation on Processing's pre-processor is only of value to the Processing developers so will not be in the public domain for you to quote.

    If you have specific questions perhaps you could write up a question list, email-interview a developer / developers, and then quote from that interview?

  • and then quote from that email/interview?

    Yes that is a good idea, it would be referenced as a private communication and would be a valid reference for your thesis.

  • edited October 2016

    Thanks to all of you for the answers they where very helpful . :-bd

    although it seems odd to me that these informations are kept kind of secret. i think processing would benefit from a more transparent approach. not all users of processing are beginners and some may teach others and therefore need a deeper understanding.

Sign In or Register to comment.