Hi there!
I want to fix the GUI error for the Magnifying Glass burning simulation program to run smoothly.
When changing anything in the GUI from the G4P GUI Builder tool, the program always crashes with a NullPointerException in 2 - 5 minutes and does not highlight the problematic line of code.
I tried:
- searching for the problem online and following solutions
- defining all variables used in the program
- using try-catch statements
- recreating the GUI
but they were unhelpful.
Code for GUI Event Handlers:
public void pauseButtonClicked(GButton source, GEvent event) { //_CODE_:pauseButton:875606:
// If the program is running, stop
if(running) {
running = !running;
noLoop();
pauseButton.setText("Resume");
}
// If the program is paused, run
else {
running = !running;
loop();
pauseButton.setText("Pause");
}
} //_CODE_:pauseButton:875606:
public void massSliderChanged(GCustomSlider source, GEvent event) { //_CODE_:massSlider:958855:
println("massSlider - GCustomSlider >> GEvent." + event + " @ " + millis());
} //_CODE_:massSlider:958855:
public void focalDistanceSliderChanged(GCustomSlider source, GEvent event) { //_CODE_:focalDistanceSlider:299666:
} //_CODE_:focalDistanceSlider:299666:
public void xPositionSliderChanged(GCustomSlider source, GEvent event) { //_CODE_:xPositionSlider:537864:
println("xPositionSlider - GCustomSlider >> GEvent." + event + " @ " + millis());
} //_CODE_:xPositionSlider:537864:
public void yPositionSliderChanged(GCustomSlider source, GEvent event) { //_CODE_:yPositionSlider:494398:
println("yPositionSlider - GCustomSlider >> GEvent." + event + " @ " + millis());
} //_CODE_:yPositionSlider:494398:
public void beamIntensitySliderChanged(GCustomSlider source, GEvent event) { //_CODE_:beamIntensitySlider:967979:
float num = beamIntensitySlider.getValueF();
if(num > 0.1 && num < 2 ) {
material.beamIntensity = num;
}
} //_CODE_:beamIntensitySlider:967979:
public void materialChoiceClicked(GDropList source, GEvent event) { //_CODE_:materialChoice:221684:
if (materialChoice.getSelectedText().equals("Ant")) {
currentMaterial = "ant";
}
else if (materialChoice.getSelectedText().equals("Paper")) {
currentMaterial = "paper";
}
else if (materialChoice.getSelectedText().equals("Grass")) {
currentMaterial = "grass";
}
else {
currentMaterial = "wood";
}
reset();
} //_CODE_:materialChoice:221684:
public void glassQualityChanged(GDropList source, GEvent event) { //_CODE_:glassQuality:419836:
if (glassQuality.getSelectedText().equals("Clear")) {
magnifyingGlass.lensQuality = "Clear";
magnifyingGlass.transparency = 1;
}
else if (glassQuality.getSelectedText().equals("Impurities")) {
magnifyingGlass.lensQuality = "Impurities";
magnifyingGlass.transparency = 0.75;
}
else if (glassQuality.getSelectedText().equals("Dirty")) {
magnifyingGlass.lensQuality = "Dirty";
magnifyingGlass.transparency = 0.5;
}
} //_CODE_:glassQuality:419836:
public void temperatureSliderChanged(GSlider source, GEvent event) { //_CODE_:temperatureSlider:230192:
surroundingTemperature = temperatureSlider.getValueI();
currentTemperature.setText(str(surroundingTemperature));
reset();
println("slider1 - GSlider >> GEvent." + event + " @ " + millis());
} //_CODE_:temperatureSlider:230192:
What is the most efficient fix if we must stick to the G4P GUI builder?