Using G4P with Eclipse IDE

For convenience, I am trying to use G4P Library as my GUI. This is my first code,

package A_FirstTest;

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

public class MainGUI extends PApplet{

    public void textfield1_change1(GTextField source, GEvent event) { //_CODE_:FirstGUI:466842:
          System.out.println("clicked!");
    }

    public void button1_click1(GButton source, GEvent event) { //_CODE_:buttonLeft:371424:
        System.out.println("clicked!");
        FirstGUI.setText("YEAH");
    } 

    public void createGUI(){
        G4P.messagesEnabled(false);
        G4P.setGlobalColorScheme(GCScheme.BLUE_SCHEME);
        G4P.setCursor(ARROW);
        surface.setTitle("Sketch Window");     //ERROR HERE!
        FirstGUI = new GTextField(this, 60, 30, 230, 20, G4P.SCROLLBARS_NONE);
        FirstGUI.setText("FirstGUI");
        FirstGUI.setLocalColorScheme(GCScheme.PURPLE_SCHEME);
        FirstGUI.setOpaque(true);
        FirstGUI.addEventHandler(this, "textfield1_change1");
        buttonLeft = new GButton(this, 60, 70, 80, 30);
        buttonLeft.setText("Left_Button");
        buttonLeft.addEventHandler(this, "button1_click1");
        }

        // Variable declarations 
        GTextField FirstGUI; 
        GButton buttonLeft; 
}

I've got an error in surface.setTitle("Sketch Window"); Any solutions?

Answers

  • What does the error say?

  • You are trying to transfer a sketch created in Processing with G4P and the GUI Builder tool to Eclipse. The GUI Builder tool creates a separate tab called gui for the code it generates.

    Processing will combine all the PDE tabs into one class when the sketch is executed so you have to do the same in Eclipse.

    Obviously I don't have your main sketch code but I have modified what you have posted to work in Eclipse.

    package A_FirstTest;
    
    import processing.core.*;
    import g4p_controls.*;
    
    public class MySketch extends PApplet {
    
        // Required so that Eclipse can run this as a Java application
        public static void main(String args[]) {
            PApplet.main(new String[] { MySketch.class.getName() });
        }
    
        // This function is required by Processing V3 in Eclipse
        // If using PS 2 then move the size() statement to the first line in setup()
        public void settings(){
            size(400,400, P2D);
        }
    
        public void setup(){
            createGUI();
        }
    
        // ==================================
        // Start of the code from the 'gui' tab
        public void textfield1_change1(GTextField source, GEvent event) { //_CODE_:FirstGUI:466842:
            System.out.println("clicked!");
        }
    
        public void button1_click1(GButton source, GEvent event) { //_CODE_:buttonLeft:371424:
            System.out.println("clicked!");
            FirstGUI.setText("YEAH");
        } 
    
        public void createGUI(){
            G4P.messagesEnabled(false);
            G4P.setGlobalColorScheme(GCScheme.BLUE_SCHEME);
            G4P.setCursor(ARROW);
            surface.setTitle("Sketch Window");     //ERROR HERE!
            FirstGUI = new GTextField(this, 60, 30, 230, 20, G4P.SCROLLBARS_NONE);
            FirstGUI.setText("FirstGUI");
            FirstGUI.setLocalColorScheme(GCScheme.PURPLE_SCHEME);
            FirstGUI.setOpaque(true);
            FirstGUI.addEventHandler(this, "textfield1_change1");
            buttonLeft = new GButton(this, 60, 70, 80, 30);
            buttonLeft.setText("Left_Button");
            buttonLeft.addEventHandler(this, "button1_click1");
        }
    
        // Variable declarations 
        GTextField FirstGUI; 
        GButton buttonLeft; 
    
        // End of the code from the 'gui' tab
        // ==================================
    
    }
    
Sign In or Register to comment.