We are about to switch to a new forum software. Until then we have removed the registration on this forum.
hello #Quark
I have noticed several time instability problems when using the G4P library to generate multiwindows. I'm using G4P builder tool in Processing 3.7. I stripped the code to the bare minimum to narrow down what could generate the error. The code (see below) loads a .obj file, set a .JPG picture as background to main window and rotate the .obj in the main window. It also create an empty window using G4P with P3D randerer.
If the createGUI() line is commented the code runs for hours with no problem. If I uncomment the createGUI() line, the code crash with the error reported below. The behaviour is different depending upon the platform used:
Same behavior if I export the code as .exe. I'm running on both PC Java8.
I really need to get this stable (not many time left to the end of my project...)... Are you aware about that kind of trouble on Windows10 ? any hint to get it stable ?
Appreciate very much your help,
///////////////////// code////////////////////////////////////////////////////////////
import g4p_controls.*;
PShape Arr,Tip, Gr, Rd, Pt;
PShape s;
float Rx, Ry=80, Rz ,mix=0.0001;
PImage bg;
public void setup(){
bg = loadImage("Back.JPG");
bg.resize(500,650);
size(500, 650, P3D);
background(bg);
s = loadShape("wingXstrmUs.obj");
createGUI(); //<<====== this is the problematic line
}
public void draw() {
background(bg);
// generate random angles
Rx=(1-mix)*Rx+mix*radians(random(180));
Ry=(1-mix)*Ry+mix*radians(random(180));
Rz=(1-mix)*Rx+mix*radians(random(180));
// draw the object rotation in the main window
translate(width/2, height/2);
rotateX (Rx);
rotateY(Ry);
rotateZ(Rz);
scale(4, 4, 4);
shape(s, 0, 0);
}
////// Below code generated by G4P builder in the GUI tab to generate the empty window
synchronized public void win_draw1(PApplet appc, GWinData data) { //_CODE_:window1:517716:
appc.background(230);
} //_CODE_:window1:517716:
// Create all the GUI controls.
// autogenerated do not edit
public void createGUI(){
G4P.messagesEnabled(false);
G4P.setGlobalColorScheme(GCScheme.BLUE_SCHEME);
G4P.setCursor(ARROW);
surface.setTitle("Sketch Window");
window1 = GWindow.getWindow(this, "Window title", 0, 0, 500, 650, P3D);
window1.noLoop();
window1.addDrawHandler(this, "win_draw1");
window1.loop();
}
// Variable declarations
// autogenerated do not edit
GWindow window1;
////////////////////////////// Error generated by Processing
JRE version: Java(TM) SE Runtime Environment (8.0_162-b12) (build 1.8.0_162-b12)
#
Could not run the sketch (Target VM failed to initialize). For more information, read revisions.txt and Help ? Troubleshooting
Processing has several modes Android, Java, Python, Javascript etc, G4P only works in Java mode.
What do you mean by 'mode'?
Please note that we have moved to a new forum
Hi everyone, I am new to Processing and G4P. I am making a project that could present different GUI for different mode. For example, when I click on a button in my main function, the mode is changed and I need the code to switch to another GUI displayed. However, I am using G4P GUI Builder Tool and I found no way to do that. Is there anyone has a good solution?
I have modified the DefaultPlot example that comes with Graphica to show the plot in a GWindow.
Things to note -
1) The GWindow must be created before the GPlot
2) The parameter used to create the plot must be the GWindow instance (line 27)
3) In the GWindow draw handler we must make sure the plot
has been created to avoid a NPE (line 43)
import g4p_controls.*;
import grafica.*;
GWindow window;
GPlot plot;
void setup() {
size(300, 200);
createGUI();
createPlot();
}
void draw() {
background(255, 255, 200);
}
void createPlot() {
// Prepare the points for the plot
int nPoints = 100;
GPointsArray points = new GPointsArray(nPoints);
for (int i = 0; i < nPoints; i++) {
points.add(i, 10*noise(0.1*i));
}
// Create a new plot and set its position on the screen
plot = new GPlot(window);
plot.setPos(25, 25);
// or all in one go
// GPlot plot = new GPlot(this, 25, 25);
// Set the plot title and the axis labels
plot.setTitleText("A very simple example");
plot.getXAxis().setAxisLabelText("x axis");
plot.getYAxis().setAxisLabelText("y axis");
// Add the points
plot.setPoints(points);
}
synchronized public void win_draw(PApplet appc, GWinData data) {
appc.background(230);
if (plot != null) {
plot.defaultDraw();
}
}
public void createGUI() {
G4P.messagesEnabled(false);
G4P.setGlobalColorScheme(GCScheme.BLUE_SCHEME);
G4P.setCursor(ARROW);
surface.setTitle("Sketch window");
window = GWindow.getWindow(this, "GWindow with Graphica plot", 0, 0, 500, 350, JAVA2D);
window.noLoop();
window.addDrawHandler(this, "win_draw");
window.loop();
}
as i have this set up as a tree and i want it to look better and work more effiecently than it already does So if you could help with my tree that would be greatly appricated
`import processing.sound.*;
import g4p_controls.*;
import java.util.ArrayList;
import java.util.List;
PImage menu;
SoundFile Harrible;
SoundFile cremeyboy;
SoundFile bianca;
SoundFile C;
SoundFile Excuse;
PImage[] scenes = new PImage[10];
boolean startscreen = true;
boolean startmusic = true;
Node root;
Node currentScene;
void setup() {
size(1280, 720);
menu = loadImage("menu.jpg");
Excuse = new SoundFile(this,"noExcuse.wav");
C = new SoundFile(this, "Condragulation.wav");
Harrible = new SoundFile(this, "Harrible.mp3");
cremeyboy = new SoundFile(this, "cremey boy.wav");
bianca = new SoundFile(this, "bianca.wav");
root = new Node("scene1.png", 1,"choose your queen you have the choice from bianca and dela");
currentScene = root;
root.left = new Node("scene2.png", 2,"You chose bianca now go to the work room");
root.right = new Node("scene3.png", 3, "you chose bendelacreme now go to the work room to see to choose you couture (you can go either left or right) ");
Node iterator;
iterator = root.left;
iterator.left = new Node("elganzabianca.png", 69,"Choose Left or Right for which couture you want dependent on what couture you choose will determine the reception you get");
iterator.right = new Node("elganzabianca.png", 69,"Choose Left or Right for which couture you want dependent on what couture you choose will determine the reception you get");
iterator = root.right;
iterator.left = new Node("scene7.png", 1111,"yeet");
iterator.right = new Node("scene7.png", 9999,"yeet");
iterator = root.left.left;
iterator.left = new Node("EndScene1.png", 10,"You have to sashay away");
iterator.right = new Node("EndScene1.png", 8,"You won the judges over with your couture");
iterator = root.left.right;
iterator.left = new Node("EndScene1.png", 8,"Not all the judges agree but you do live another week but you won the challenge");
iterator.right = new Node("EndScene1.png", 6,"Thats terrible nobody liked your couture and for that you sashay away");
iterator = root.right.right;
iterator.left = new Node("EndScene1.png", 5,"You argued with ru now you sashay away");
iterator.right = new Node("EndScene1.png", 8,"Great Job you live to see another");
iterator = root.right.left;
iterator.left = new Node("EndScene1.png", 6,"Thats Horrible ");
iterator.right = new Node("EndScene1.png", 8,"You Won the Challenge you can now leave the stage a get ready for another week");
iterator = root.left.left.right;
iterator.left = new Node("Finscreen.png", 8,"yeet");
iterator.right = new Node("Finscreen.png", 9,"yeet");
iterator = root.left.right.left;
iterator.left = new Node("Finscene.png", 10,"Sorry Dela No one liked your couture so you haved to sashay away");
iterator.right = new Node("Finscene.png", 11,"Do the stanky leg b xoxoxo :^) you won now you can sleep ");
iterator = root.right.right.left;
createGUI();
}
void draw() {
if (startscreen) {
background(menu);
} else {
background(255);
startmusic = false;
image(currentScene.scene, 0, 0);
}
text(currentScene.Dialog, 500, 100);
//these if statements play the audio and stop it after it has has played
if (currentScene.index == 1) {
currentScene.index =-1;
}
if (currentScene.index ==-1){
}
if (currentScene.index == 3) {
cremeyboy.play();
currentScene.index =-3;
}
if (currentScene.index ==-3){
}
if (currentScene.index == 2) {
bianca.play();
currentScene.index =-2;
}
if (currentScene.index ==-2){
}
if (currentScene.index == 6) {
Harrible.play();
currentScene.index =-6;
}
if (currentScene.index ==-6){
}
if (currentScene.index == 7) {
Harrible.play();
currentScene.index =-7;
}
if (currentScene.index ==-7){
}
if (currentScene.index == 5) {
Harrible.play();
currentScene.index =-5;
}
if (currentScene.index ==-5){
}
if (currentScene.index == 8) {
C.play();
currentScene.index =-8;
}
if (currentScene.index ==-8){
}
if (currentScene.index == 10) {
Excuse.play();
currentScene.index =-10;
}
if (currentScene.index ==-10){
}
println(255, currentScene.index);
}
void keyPressed() {
if (keyCode == RIGHT) {
currentScene = currentScene.right;
}
if (keyCode == LEFT){
currentScene = currentScene.left;
}
}
DISPLAY
interface Display{
void display();
}
NODE
public class Node implements Display{
void display(){
}
PImage scene;
int index;
Node left;
Node right;
String Dialog;
Node (String filename,int i, String DialogInput){
scene = loadImage(filename);
index = i;
Dialog = DialogInput;
}
}
Gui
/* =========================================================
* ==== WARNING ===
* =========================================================
* The code in this tab has been generated from the GUI form
* designer and care should be taken when editing this file.
* Only add/edit code inside the event handlers i.e. only
* use lines between the matching comment tags. e.g.
void myBtnEvents(GButton button) { //_CODE_:button1:12356:
// It is safe to enter your event code here
} //_CODE_:button1:12356:
* Do not rename this tab!
* =========================================================
*/
public void button1_click1(GButton source, GEvent event) { //_CODE_:button1:446807:
println("button1 - GButton >> GEvent." + event + " @ " + millis());
startscreen = false;
button1.dispose();
button2.dispose();
} //_CODE_:button1:446807:
public void button2_click1(GButton source, GEvent event) { //_CODE_:button2:341443:
println("button2 - GButton >> GEvent." + event + " @ " + millis());
exit();
} //_CODE_:button2:341443:
// Create all the GUI controls.
// autogenerated do not edit
public void createGUI(){
G4P.messagesEnabled(false);
G4P.setGlobalColorScheme(GCScheme.BLUE_SCHEME);
G4P.setCursor(ARROW);
surface.setTitle("Sketch Window");
button1 = new GButton(this, 116, 511, 127, 43);
button1.setText("Start");
button1.setLocalColorScheme(GCScheme.GOLD_SCHEME);
button1.addEventHandler(this, "button1_click1");
button2 = new GButton(this, 116, 558, 128, 52);
button2.setText("Exit");
button2.setLocalColorScheme(GCScheme.ORANGE_SCHEME);
button2.addEventHandler(this, "button2_click1");
}
// Variable declarations
// autogenerated do not edit
GButton button1;
GButton button2; `
If you do not want to create your own GUI you could also create a slider / scrollbar element using one of the Processing GUI libraries -- e.g. G4P or ControlP5.
Update a variable with the slider, then use that variable as an argument to translate() at the top of your draw. Now moving the bar translates the screen contents.
Hi, I am in need of some help, again. -sigh- I am working with the G4P Image Toggle Button, and I would like to change the behavior so that when you click on the button, it will automatically switch states. Right now the way that it is it will only change states when you click and then release the mouse. I tried using the event handler function that was provided in the example but that did not make sense to me because that was for one single button, but I have a class (called keys) that is an extension of the GImage Toggle Button class.
Thank you for the code. I actually ended up finding a much easier way to do what I wanted to do though by using the image toggle button from the G4P library.
A button (or any G4P control) does not return values rather they generate events which you must catch to execute some code.
In this example there 2 buttons which make an ellipse either bigger or smaller depending on which one you click.
import g4p_controls.*;
GButton btnSmaller, btnBigger;
float dx, dy;
void setup() {
size(480, 320);
dx = width/4;
dy = height/4;
// Create 2 buttons on the main sketch window
// x y w h face text
btnSmaller = new GButton(this, 160, 10, 60, 30, "Smaller");
btnBigger = new GButton(this, 260, 10, 60, 30, "Bigger");
}
void draw() {
background(200, 180, 255);
// Draw elipse in centre of the screen
stroke(128, 0, 0);
strokeWeight(3);
fill(192, 64, 64);
ellipse(width/2, height/2, dx, dy);
}
void handleButtonEvents(GButton button, GEvent event) {
// Clicked on 'bigger'
if (button == btnBigger && event == GEvent.CLICKED) {
dx += 10; // make ellispe bigger
dy += 10;
}
// Clicked on 'smaller'
if (button == btnSmaller && event == GEvent.CLICKED) {
dx -= 10; // make ellispe smaller
dy -= 10;
}
}
What value does a button return? What are the commands to use this value?
It is not clear what the OP wants but G4P supports copy and paste into the running sketch.
In this example sketch below click on the text area and press Ctrl + V to paste any text on the clipboard into the area. (You need to copy some text from elsewhere first obviously :D )
You will need to install G4P using the Contributions Manager for this sketch to run.
import g4p_controls.*;
GTextArea txaArea;
public void setup(){
size(320, 200, P2D);
surface.setTitle("Paste from clipboard example");
txaArea = new GTextArea(this, 10, 10, 300, 180, G4P.SCROLLBARS_BOTH | G4P.SCROLLBARS_AUTOHIDE);
txaArea.setPromptText("Use Ctrl + V to paste some text here");
txaArea.setOpaque(true);
}
public void draw(){
background(230);
}
The answer was given and it was "Install the G4P library" ;)
You can do this from the menus
Sketch > Import Library > Add Library
and selecting G4P in the contributions manager.
Hi, i'm trying to learn programing using Java processing, I want to run G4P examples, but the tool is not working right I reinstall it . I found this , but it never got answered. I am using Ubuntu, (cool for me :) I went here https://forum.processing.org/two/discussion/comment/58072/#Comment_58072 but the answer was never givin. How do you fix this ?
Thank you,
Dear all, I'm a beginer with Processing so my question might not be posed in the correct manner.
Still, I tried to use the Gplot objects and the related methods provided in the library Grafica. It works fine when the GPlot are manipulated in the MAIN window (i.e. main Draw function). I'm now trying to get the same graphs in an independent window generated with G4P builder. For that, I tried to place the Gplot related code (Gplot objects and manipulation) in the draw handler (win_draw) generated by G4P GUI builder. However, when I'm trying to use the same Gplot objects/methods there, I get consitently the following error :
_An error occured during execution of the eventhandler: CLASS: DataLogger1_1_PDE METHOD: win_draw Caused by java.lang.NullPointerException)
This makes sometime the computer (OSx10.8 / processing3) crashing.
Can anybody share experience/examples on how to pass a Gplot object to the draw handler / independent window + getting the plot drawn there and not in the main.
Thank you in advance for your hep !!!
Again, thank you both for all of the help that you have given me on this topic. The example was a good one of putting the switch method in a procedure, rather than the draw(0) method, which, with your help, worked for me also.
I am not the first one who had problems with this particular issue, and I am sure that i won't be the last one. quark, would you consider putting this example in G4P the next time you revise it? I think that it would be very helpful.
Hello,
Just to register here, I decided to do a test, I removed the Libraries from Leap Motion, which was what error was presented when creating the Executable.
I left in the Project the Libraries of Processing, ControlP5, G4P and Minim, and I was able to create both .jar and .exe, using launch4j, it worked normal.
So the problem is with the LeapMotion Library, it uses beyond .jar, 2 dlls, it looks like it is not finding their way.
I generated the .jar exporting as it is selected in the image below:
But this is already a great progress, thank you very much for the help here.
Thanks anyway, thank you!
Here is an example of using G4P with states. For clarity I have used G4P with GUI Builder but combined the 2 tabs into one removing some of the comments. Simply copy and paste the who;e code into the main tab.
import g4p_controls.*;
int state = 0;
int selectedState = 0;
public void setup() {
size(400, 240, JAVA2D);
createGUI();
customGUI();
// Place your setup code here
textSize(40);
gotoState(0);
}
void gotoState(int s) {
changeGUI(state, false);
state = s;
changeGUI(state, true);
}
void changeGUI(int s, boolean v) {
switch(s) {
case 0:
option1.setVisible(v);
option2.setVisible(v);
btnGo.setVisible(v);
break;
case 1:
btnBack1.setVisible(v);
break;
case 2:
btnBack2.setVisible(v);
break;
}
}
public void draw() {
background(60, 60, 220);
fill(0);
text(state, width/2 - 10, height/2 + 10);
}
// Use this method to add additional statements
// to customise the GUI controls
public void customGUI() {
// Make all controls invisible here because
// it is not an option in GUI Builder
option1.setVisible(false);
option2.setVisible(false);
btnGo.setVisible(false);
btnBack1.setVisible(false);
btnBack2.setVisible(false);
}
// From the gui tab
public void opt1_click(GOption source, GEvent event) { //_CODE_:option1:965250:
selectedState = 1;
} //_CODE_:option1:965250:
public void opt2_click(GOption source, GEvent event) { //_CODE_:option2:491595:
selectedState = 2;
} //_CODE_:option2:491595:
public void btnGo_click(GButton source, GEvent event) { //_CODE_:btnGo:741736:
gotoState(selectedState);
} //_CODE_:btnGo:741736:
public void btnBack1_click(GButton source, GEvent event) { //_CODE_:btnBack1:362009:
gotoState(0);
} //_CODE_:btnBack1:362009:
public void btnBack2_click(GButton source, GEvent event) { //_CODE_:btnBack2:431048:
gotoState(0);
} //_CODE_:btnBack2:431048:
// Create all the GUI controls.
// autogenerated do not edit
public void createGUI(){
G4P.messagesEnabled(false);
G4P.setGlobalColorScheme(GCScheme.BLUE_SCHEME);
G4P.setCursor(ARROW);
surface.setTitle("Sketch Window");
optGroupState = new GToggleGroup();
option1 = new GOption(this, 10, 10, 120, 20);
option1.setIconAlign(GAlign.LEFT, GAlign.MIDDLE);
option1.setText("Select State 1");
option1.setOpaque(true);
option1.addEventHandler(this, "opt1_click");
option2 = new GOption(this, 10, 40, 120, 20);
option2.setIconAlign(GAlign.LEFT, GAlign.MIDDLE);
option2.setText("Select State 2");
option2.setOpaque(true);
option2.addEventHandler(this, "opt2_click");
optGroupState.addControl(option1);
option1.setSelected(true);
optGroupState.addControl(option2);
btnGo = new GButton(this, 10, 70, 120, 20);
btnGo.setText("Goto State");
btnGo.addEventHandler(this, "btnGo_click");
btnBack1 = new GButton(this, 10, 210, 120, 20);
btnBack1.setText("Back to Menu");
btnBack1.addEventHandler(this, "btnBack1_click");
btnBack2 = new GButton(this, 270, 210, 120, 20);
btnBack2.setText("Back to Menu");
btnBack2.addEventHandler(this, "btnBack2_click");
}
// Variable declarations
// autogenerated do not edit
GToggleGroup optGroupState;
GOption option1;
GOption option2;
GButton btnGo;
GButton btnBack1;
GButton btnBack2;
Thank you Chrisir and quark. Chrisir, your comment about nothing being in draw() except the switch(0 statements was very critical. And quark, for the explanation of using the reference was very helpful.
I did get my very simple code working, and have posted it here.
I don't fully understand why the part of no other code in draw(0 except the switch statements is critical. I initially tried to make the switchbox1 control invisible with a statement that tested for the state set up by the switchbox1 control clicking. It did not work!
`import g4p_controls.*;
GCheckbox checkbox1;
int state; void setup(){ size(400,400); state=0; fill(0); background(200);
createGUI();
}
void draw(){
switch(state){
case 0:
background(200);
checkbox1.setVisible(true);
text("Settings state", 50,50);
break;
case 1:
background(200);
checkbox1.setVisible(false);
text("Play state",50,50);
}
}
public void checkbox1_clicked1(GCheckbox source, GEvent event) {
println("checkbox1 - GCheckbox >> GEvent." + event + " @ " + millis());
{ state=1; }
}
public void createGUI()
{ G4P.messagesEnabled(false); G4P.setGlobalColorScheme(GCScheme.BLUE_SCHEME); G4P.setCursor(ARROW); surface.setTitle("Sketch Window"); checkbox1 = new GCheckbox(this, 166, 150, 120, 20); checkbox1.setIconAlign(GAlign.LEFT, GAlign.MIDDLE); checkbox1.setTextAlign(GAlign.CENTER, GAlign.MIDDLE); checkbox1.setText("BEND"); checkbox1.setOpaque(false); checkbox1.addEventHandler(this, "checkbox1_clicked1"); }
`
As @Chrisir points out the first place to look is the online-reference.
If you look at the reference for GCheckbox you will see this
If you scroll down you will see the methods available to this control. Also the diagram at the top shows the inheritance tree for this control. So
GCheckbox
inherits from GToggleControl
GToggleControl
inherits from GTextIconBase
GTextIconBase
inherits from GTextBase
GTextBase
inherits from GAbstractControl
The public methods from these classes also work for GCheckbox
so if you click on GAbstractControl
and scroll down you will find a method called setVisible(boolean)
which is used for all G4P controls. I suggest you explore the reference pages to get an idea of what is available.