We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello guys,
Can anyone help as I could control click the button of each button, a second window with G4P?
Below is the sample code ...
import g4p_controls.*;
GWindow window;
GButton btnTest, btnTest2;
public void setup() {
size(160, 160);
background(255);
window = new GWindow(this, "Second Window", 130, 100, 400, 320, false, JAVA2D);
window.addDrawHandler(this, "windowDraw");
window.addMouseHandler(this, "windowMouse");
window.addKeyHandler(this, "keyEvent");
window.setActionOnClose(G4P.CLOSE_WINDOW);
window.setLocation(250, 20);
btnTest = new GButton(window.papplet, 10, 50, 120, 30, "Test");
btnTest2 = new GButton(window.papplet, 10, 90, 120, 30, "Test 2");
}
public void draw() {
background(240);
}
public void windowDraw(GWinApplet appc, GWinData windata) {
appc.background(255);
}
public void windowMouse(GWinApplet appc, GWinData windata, MouseEvent event) {
if (event.getAction() == MouseEvent.CLICK) //??
println("Mouse event in extra window " + frameRate);
}
public void keyEvent(GWinApplet appc, GWinData data, KeyEvent event) {
if ((event.getAction() == KeyEvent.PRESS) && (appc.keyCode == ESC)) {
//appc.key = 0;
appc.keyCode = 0; //??
println("CTRL Pressed!");
}
}
More one detail can "cancel" the ESC key, not to close the window?
Thank you
Answers
To keep the window open use
window.setActionOnClose(G4P.KEEP_OPEN);
I don't understand the question.
Hello Peter, thanks for the feedback ...
Sorry the English, but thankfully we have the google translate, but could not say almost nothing ... (laughs) ...
I need to control the Click of each separate button when not in a second window, it works like regular ...
But when I use a second window, I can not do the same validation as would the code, it would be possible to do the same control?
This second code does not work, I would like to know how to be able to work ...
Thank you for attention
In the case of the second window, I only wanted to close the current window (not the entire application), or simply "cancel" the ESC, to not close any application.
However, this code does not seem to work in the second window.
Thank you again
You are using Processing 2.1.1 why not Processing 3?
I have created an example where the ESC key is ignored in the second window
Hello Peter, thanks for the help ...
OK, so I can use the controls of buttons on different screens, just a detail I have to solve in the first screen I use GImageButton, and the second use GButton ...
Just to complicate matters a bit does not it? ( laughs )...
It is the first screen is a menu where the user will choose the options that open certain settings screen, registers, etc ... below is the print through a better idea.
We are developing an application, where we put several options for animations, simple games and other activities ... This is another application to make the settings, entries, as I mentioned ...
How could I control the events GImageButton and GButton separately?
Code Snippet
Thank you very much!
What about using the Processing 3, had some problem with some libraries, including G4P changed a few things, I can compile some programs ...
For example, this copies a clipboard image in Processing 2, 3 is not recognizing.
I need to see how to resolve this, Processing 3 really is with many improvements ...
I know it has nothing to do with the subject we are seeing, but just to get a better idea of the error, the print is below ...
Thank you
It is possible for every control to have its own event handler.
For instance if we have 2 buttons
then after they are created you can add event handlers like this
and the event handlers would look like this
I see you are using Processing 3.5.4 which is the last version compatible for Processing 2. There will be no more updates or bug fixes for this version of G4P.
Hi Peter,
OK, it worked perfectly!
I'll see if I can update to the Application for Processing 3.
Thank you very much! :)
Beware that if you go to Processing V3 you will also have to use G4P 4.0.5 which will some changes in the code.
OK, I've adjusted it, G4P worked usual ... now need to update SQLite, I use to load data ...
I'll open another post, it seems that SQLite is not updated to Processing 3.
Meanwhile'll Processing using 2 ...
Thank you very much.