Hi, I’m using the fantastic G4P library, and I’ve made some secondary windows with buttons on them.
I’m using the technique of creating them null, and then showing/hiding them with other buttons.
I’m finding that sometimes you have to click the buttons 2-3 times in the secondary window before they register a click. I’m wondering if there’s something I can do to make them work 100% reliably?
Here’s code from one of the sample windows that exhibits this behavior:
public void optionsDraw(PApplet app, GWinData data){
app.background(127);
//app.image(optionsIcon, 123, 10);
app.stroke(100);
app.strokeWeight(2);
app.fill(127);
app.rect(15, 70, 270, 70, 5);
}
void createOptionsWindow() {
int windowWidth = 300;
int windowHeight = 200;
options = GWindow.getWindow(this, "Options", width/2 + 120, height/2 + 70, windowWidth, windowHeight, JAVA2D);
options.setActionOnClose(G4P.HIDE_WINDOW);
options.addDrawHandler(this, "optionsDraw");
options.addMouseHandler(this, "optionsMouse");
options.addKeyHandler(this, "optionsKey");
//options.addData(new MyData());
cbShowToolTips = new GCheckbox(options, 22, 80, 120, 20, "Show Tooltips");
cbShowToolTips.setLocalColorScheme(GCScheme.SCHEME_15);
cbShowToolTips.setSelected(blnShowToolTip);
cbShowToolTips.addEventHandler(this, "cbShowToolTips_clicked");
btnCancelOptions = new GButton (options, windowWidth/2 - buttonWidth - 15, windowHeight - buttonYOffset, buttonWidth, buttonHeight, "Cancel");
btnCancelOptions.addEventHandler(this, "btnCancelOptions_clicked");
btnCancelOptions.setLocalColorScheme(GCScheme.SCHEME_9);
btnOKOptions = new GButton (options, windowWidth/2 + 15, windowHeight - buttonYOffset, buttonWidth, buttonHeight, "OK");
btnOKOptions.addEventHandler(this, "btnOKOptions_clicked");
btnOKOptions.setLocalColorScheme(GCScheme.SCHEME_9);
}
public void optionsMouse(PApplet app, GWinData data, MouseEvent event) {
// Saves doing it for every variable in MyData class
//MyData myData = (MyData) data;
//if(event.getAction() == MouseEvent.CLICK){
// myData.lastClickX = mouseX;
// myData.lastClickY = mouseY;
//}
}
public void optionsKey(PApplet app, GWinData data, KeyEvent event) {
if (event.getKey() == RETURN || event.getKey() == ENTER) options.setVisible(false);
}
public class MyData extends GWinData {
// The variables can be anything you like.
public int lastClickX,lastClickY;
}
public void cbShowToolTips_clicked(GCheckbox source, GEvent event) {
if (cbShowToolTips.isSelected()) blnShowToolTip = true;
else blnShowToolTip = false;
showHideToolTips();
}
void showHideToolTips() {
if (blnShowToolTip) toolTipGap = 0;
else toolTipGap = 1000;
setTooltips();
}
public void btnCancelOptions_clicked(GButton source, GEvent event) {
println("CANCEL CLICKED!");
if (options != null) options.setVisible(false);
}
public void btnOKOptions_clicked(GButton source, GEvent event) {
println("OK CLICKED!");
try{
optString[1] = str(blnShowToolTip);
saveStrings("options.txt", optString);
}
catch(Exception e) {
e.printStackTrace();
}
if (options != null) options.setVisible(false);
}
It works most of the time fine, but every once in awhile, you have to click either OK or Cancel 2-3 times before it registers the click.
It’s puzzling…
Thanks for any insights anyone may have,
Mike