G4P library with GUI builder - Can I make Sliders in an Child applet?

please format code with </> button * homework policy * asking questions

First of all , I love the GUI builder. Saved me lots of trouble… Thank you authors.

I am using the Demos/Tests/MultipleWindows sketch and I got a a second applet and I’d like to make features in the applet. Possible?


1 Like

I never did this, but maybe check out this: G4P - Checkbox grid

quark made the library by the way

(forget the grid, it’s about handling the new Window imho)


Good to see you again here. Thanks for the previous help with the legs,

I will try that. Sounds hard.
But before that, a simpler question:
Can I start / stop the applet after the main sketch is up?

In setup there is the line that starts it
child = new ChildApplet();
But I can’t cancel that after the sketch started. Or can I ? I have a toggle button to do it,.

public void imgTogButton1_click1(GImageToggleButton source, GEvent event) { //_CODE_:imgTogButton1:800288:
  println("imgTogButton1 - GImageToggleButton >> GEvent." + event + " @ " + millis());
  //imgTogButton1 = source.isSelected();
   Toggle = !Toggle; // false is Down 
   if (Toggle)
   {rect(30, 20, 55, 55, 7);
    println (Toggle);

a child applet?

Wouldn’t child window be easier, as in the link?
I dunno…

Sorry, I can’ help you here…

What do you mean by ‘features’?

There is no class called ChildApplet in G4P - if you want a secondary window then use G4P’s GWindow class.

GUI Builder alreaddy allows you to create secondary windows and add G4P controls to them. Just make sure you add a draw handler for the new window.

1 Like

Thanks a lot, I did make a second window with your example.
But I was hoping to be able to open GUI Builder from tools and see the new window.
Then make features, like buttons and sliders.

Is that possible?

What example?

As I said there is no class called ChildApplet in G4P. Since GUI Builder works exclusively with G4P it will not work with the ChildApplet class.

If you haven’t already done so I recommend you look at the four GUI Builder videos on my website.

Someone recommended this above

Is that a good example to start with for multi windows?


Not if you are using GUI Builder.

Creating a secondary window with a slider on it

  1. Start Processing
  2. Create a new empty sketch
  3. Start GUI Builder
    Using GUI Bulder
  4. clcik on the new window button
  • add a draw handler called win_draw
  1. click on the slider button to add a slider to the new window

If you follow the above instruction you will get a sketch with 2 windows and a slider in the secndary one and the code will look like

// Need G4P library
import g4p_controls.*;
// You can remove the PeasyCam import if you are not using
// the GViewPeasyCam control or the PeasyCam library.
import peasy.*;

public void setup() {
  size(480, 320, JAVA2D);
  // Place your setup code here

public void draw() {

// Use this method to add additional statements
// to customise the GUI controls
public void customGUI() {

and in the second tab

/* =========================================================
 * ====                   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!
 * =========================================================

synchronized public void win_draw1(PApplet appc, GWinData data) { //_CODE_:window1:452479:
} //_CODE_:window1:452479:

public void slider1_change1(GSlider source, GEvent event) { //_CODE_:slider1:581575:
  println("slider1 - GSlider >> GEvent." + event + " @ " + millis());
} //_CODE_:slider1:581575:

// Create all the GUI controls. 
// autogenerated do not edit
public void createGUI(){
  surface.setTitle("Sketch Window");
  window1 = GWindow.getWindow(this, "Window title", 0, 0, 240, 120, JAVA2D);
  window1.addDrawHandler(this, "win_draw1");
  slider1 = new GSlider(window1, 70, 40, 100, 40, 10.0);
  slider1.setLimits(0.5, 0.0, 1.0);
  slider1.setNumberFormat(G4P.DECIMAL, 2);
  slider1.addEventHandler(this, "slider1_change1");

// Variable declarations 
// autogenerated do not edit
GWindow window1;
GSlider slider1; 

Thanks a lot, That works for me. I was not aware I can do that.

Also for the first time I made a decimal output slider.

The depiction of the slider shows fine, 2 digit decimals but the output is an integer and a zero.
I am using the GUI builder and here is the code it generated:

  IMU_Slider = new GSlider(this, 1230, 300, 210, 60, 10.0);
  IMU_Slider.setLimits(0.0, -6.0, 6.0);
  IMU_Slider.setNumberFormat(G4P.DECIMAL, 2);
  IMU_Slider.addEventHandler(this, "slider4_change1");

To get the value out I use

public void slider4_change1(GSlider source, GEvent event) { //_CODE_:IMU_Slider:603197:
 // println("IMU_Slider - GSlider >> GEvent." + event + " @ " + millis());
    float IMU_Bias = source.getValueI();
    println (IMU_Bias);

What am I doing wrong,
Thanks again for this library , better than any thing.


Internally all sliders store their value as a float and you have used this
float IMU_Bias = source.getValueI();
to retrieve the value which is the problem. You are asking the slider to return the value as an integer and then store in in a float so it will always have a zero after the decimal point.

Instead use this
float IMU_Bias = source.getValueF();
which will return the slider value as a float.

Thanks that worked, but I get too many decimals, such as 1.4081631

In the GUI builder I asked in "Numeric precision " for 1.
Any ideas?

This simply controls how decimal numbers appear on the slider e.g. limits and current value it has no effect on the value stored internally which happens to be a float with 7-8 significant figures

This retrieves the value stored internally as a float so it can be used in calculations or whaever.

If you want to display the number as a string with the specified decimal places then use
String IMU_BiasS = source.getValueS();

1 Like

Thanks , I made a little process and trimmed to 2 decimals.
IMU_Bias = source.getValueF()*100;
int R = round (IMU_Bias);
IMU_Bias = R/100.00;
println (IMU_Bias);