# Processing 3.5.3 - G4P library - print variable to 2nd window

**URL:** https://discourse.processing.org/t/processing-3-5-3-g4p-library-print-variable-to-2nd-window/17968
**Category:** Libraries
**Created:** [February 21, 2020, 8:05am UTC](https://discourse.processing.org/t/processing-3-5-3-g4p-library-print-variable-to-2nd-window/17968 "2020-02-21T08:05:07Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Theo68](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/theo68/32/8138_2.png) [@Theo68](https://discourse.processing.org/u/Theo68)
#### Post date: [February 21, 2020, 8:05am UTC](https://discourse.processing.org/t/processing-3-5-3-g4p-library-print-variable-to-2nd-window/17968/1 "2020-02-21T08:05:07Z")

</div>

I’m using the g4p\_controls library. Pressing a button opens a second window. In the 2nd window I have placed some labels that correspond to the values of a sensor. I’m trying to display the sensor value next to the label. How can I display the value of a variable in this 2nd window ?? is there any example of displaying the variable at any point on the 2nd window surface ???

```auto
public void button1_click1(GButton source, GEvent event) { //_CODE_:button1:896367:
  window1 = GWindow.getWindow(this, "Window title", 0, 0, 240, 120, JAVA2D);
  window1.noLoop();
  window1.setActionOnClose(G4P.CLOSE);
  window1.addDrawHandler(this, "win_draw1");

**// In this point i want to print to the 2nd window the float variable from the sensor**

  label1 = new GLabel(window1, 9, 14, 80, 20);
  label1.setTextAlign(GAlign.CENTER, GAlign.MIDDLE);
  label1.setText("Humidity");
  label1.setOpaque(false);
  window1.loop();
} //_CODE_:button1:896367:

synchronized public void win_draw1(PApplet appc, GWinData data) { //_CODE_:window1:810925:
  appc.background(230);
} //_CODE_:window1:810925:

public void createGUI(){
  G4P.messagesEnabled(false);
  G4P.setGlobalColorScheme(GCScheme.BLUE_SCHEME);
  G4P.setMouseOverEnabled(false);
  surface.setTitle("Sketch Window");
  button1 = new GButton(this, 14, 16, 120, 30);
  button1.setText("open window");
  button1.addEventHandler(this, "button1_click1");
 
}

GButton button1; 
GWindow window1;
GLabel label1;

```

---

<div class="post-metadata">

### Author: ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)
#### Post date: [February 21, 2020, 8:42am UTC](https://discourse.processing.org/t/processing-3-5-3-g4p-library-print-variable-to-2nd-window/17968/2 "2020-02-21T08:42:24Z")

</div>

Use a label on the second window for the value e.g. `labal.setText("" + value)`

---

<div class="post-metadata">

### Author: ![Theo68](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/theo68/32/8138_2.png) [@Theo68](https://discourse.processing.org/u/Theo68)
#### Post date: [February 21, 2020, 11:24am UTC](https://discourse.processing.org/t/processing-3-5-3-g4p-library-print-variable-to-2nd-window/17968/4 "2020-02-21T11:24:16Z")

</div>

I managed to do what you suggested and it was a success.  
Plus I managed to change the fonts and size. What I failed to do is change the color.  
But the main problem is that I must find a way to keep the Labeltext up to date like the variable do . It seems difficult for the level of knowledge I have. Maybe I need to change the whole design and logic.  
Thank you for your help

---

<div class="post-metadata">

### Author: ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)
#### Post date: [February 21, 2020, 2:45pm UTC](https://discourse.processing.org/t/processing-3-5-3-g4p-library-print-variable-to-2nd-window/17968/5 "2020-02-21T14:45:33Z")

</div>

> [@Theo68](#):
>
> keep the Labeltext up to date like the variable do

try this sketch out, the label text is constantly update as the mouse moves

```auto
import g4p_controls.*;

GLabel lbl0;
float dist; // distance from the centre of window

void setup(){
  size(500,300);
  lbl0 = new GLabel(this, 50,20,100,20,"?");
  lbl0.setOpaque(true);

}

void draw(){
  background(200,200,255);
  lbl0.setText("" + dist);
  // DRaw lines showing window centre
  stroke(20,20,128);
  line(0, height/2, width, height/2);
  line(width/2, 0, width/2, height);
}

// This Processing method is executed everytime
// the mouse moves.
void mouseMoved(){
  // Calculate the distance of the mouse from the centre of the window
  float dx = mouseX - width/2;
  float dy = mouseY - height/2;
  dist = sqrt(dx*dx+dy*dy);
}

```

> [@Theo68](#):
>
> What I failed to do is change the color.

Look at the G4P [guides](http://www.lagers.org.uk/g4p/guides/g01-introduction.html) on my website. See the guides under colour schemes. 😄

---

<div class="post-metadata">

### Author: ![Theo68](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/theo68/32/8138_2.png) [@Theo68](https://discourse.processing.org/u/Theo68)
#### Post date: [February 21, 2020, 5:47pm UTC](https://discourse.processing.org/t/processing-3-5-3-g4p-library-print-variable-to-2nd-window/17968/6 "2020-02-21T17:47:24Z")

</div>

First of all thank you very much for your help. I have managed to solve the main problem of constantly updating the variable within the form by studying many examples and using my intuition.

I used this routine and it works great for all texts in labels that appear in the 2nd window.

```auto
synchronized public void windowDraw1 (PApplet appc, GWinData data) {
  appc.background (230);
  AirTemp_sensor1_Data.setText ("" + millis () / 1000);
  AirHum_sensor1_Data.setText ("" + millis () / 500);
  SoilTemp_sensor1_Data.setText ("" + millis () / 250);
  SoilHum_sensor1_Data.setText ("" + millis () / 125);
  Sun_sensor1_Data.setText ("" + millis () / 10);
  UVA_sensor1_Data.setText ("" + millis () / 5);
  UVB_sensor1_Data.setText ("" + millis ());
}

```

I started with the GUI gap builder but have made some modifications to the original code given by the gap builder. So from this point on, and then I try to embed code without opening the gap builder so that always generate the original code. Thanks again. 🙂

Στις Παρ, 21 Φεβ 2020 στις 4:55 μ.μ., ο/η Peter Lager via Processing Foundation [processingfoundation1@discoursemail.com](mailto:processingfoundation1@discoursemail.com) έγραψε:
